Visual Basic and WinHelp

WhatsThis Help

WhatsThis Help is a feature new to Windows 95, and it is also available on NT. In the parlance of help authors, WhatsThis Help is "control-level context sensitivity". It can also be thought of as an extended tooltip, capable of both graphics and formatted text. For Visual Basic programmers, WhatsThis Help is the easiest to use of all help functions - you don't need to call the WinHelp API. You need to do the following things:

In your main form's Load event (or main procedure if your program starts with Sub Main), add the following line:

App.HelpFile = App.Path & "\helpfile.hlp"

This builds the name of your help file to include the current path of the application - change the name of your help file to fit your needs. The App.HelpFile variable is a property of the App object, of which each Visual Basic program has exactly one.

For each control in each form in your application, create a help topic that explains what that control does. Some controls that are common to many dialogs (such as the OK or Cancel buttons) can all share a common topic - there's no need to make a bunch of topics that explain the same thing. Give each topic a different context ID number.

One kind of control, called "container controls", can contain other controls. An example of this type of control is a frame, or occasionally a picture box. While each control in the container has its own unique context ID number, the container itself can also have a context ID number.

Add each context ID number into each controls WhatsThisHelpID property - most, if not all, custom controls have this property.

Finally, you have to enable WhatsThis help for your VB project. This must be done on a form-by-form basis, and there is a caveat: Windows will not let you put the WhatsThis icon on any form that contains Minimize and/or Maximize buttons. This limits you to adding the WhatsThis icon to dialogs - if you want to attach one to a main form, then you'll have to use another approach. This appears to be a limitation of Windows itself and not of Visual Basic.

For each form, set the following properties:

WhatsThisHelp = True
WhatsThisButton = True

If you ever want to trigger WhatsThis help from code, use this API call:

lReturn = WinHelpNum(hWnd, sHelpFile, HELP_CONTEXTPOPUP, lContextID)

The context ID can be any WhatsThisHelpID value. This call can be used as a response to an F1 key, for instance.

The F1 key contains a little bug that you may want to work around. If you enable WhatsThis help for a form, the F1 key should disable itself (according to the documentation). It does not, instead it shows help for the item under the mouse pointer. If you'd like it to produce WhatsThis help for the control that currently has the focus, use the following procedure.

Enable the form's KeyPreview property. This will allow the form to trap F1. In the form's KeyDown event, look for the F1 key. If you find it, set the key preview variable to zero. Then, use the WinHelp call above, using any of the following for context ID numbers:


If you want to completely disable WhatsThis help for an individual control, set its WhatsThisHelpID property to -1.

Copyright © 2009 by Dana Cline
Last Updated  Monday, April 06, 2009
Website hosted by 1and1