Connecting HTML Help To Visual Basic Programs: by Don Lammers
Connecting HTML Help To Visual Basic Programs: by Don Lammers
by Don Lammers
Scope
If you are trying to call HTML Help from Visual Basic I generally recommend using David Liske's Help
subclassing module and tutorial available at http://mvps.org/htmlhelpcenter. It makes life a lot easier, lets you do
things that you could not do otherwise (like use Training Card Help) and works with both Visual Basic 5 and
Visual Basic 6. It comes with its own tutorial, so I will not attempt to explain it here.
However, it always helps to understand how the original was designed to work before trying to override its
functionality. Or you may have a project that does not need any more functionality than is provided by
Microsoft. This document is intended to show you how to hook HTML Help to Visual Basic 6 and later without
using add-ons. Earlier versions of Visual Basic will require you to make all calls directly to the HTML Help API
or to use an add-on like David Liske's subclassing module.
Acknowledgements
The following information is from my own experimentation and from people who have walked this path before
me. Thanks to all of the following:
David Liske, Dana Cline, Microsoft HTML Help WorkShop Help, Microsoft Knowledge Base, The Developer's
Guide to WINHELP.EXE (Jim Mischel), Building Windows 95 Help (Nancy Hickman), Paul O'Rear, Developing
Online Help for Windows 95 (Boggan, Farkas, and Welinske), Gordon F. MacLeod, Burt Abreu.
Tips:
• If you are calling both secondary windows and pop-ups from your application and only have a single help
file, you may want to skip the secondary window name in this property and append it to App.HelpFile
only when you call help that requires a secondary window.
• The App.HelpFile property can be changed at runtime, so you can reset it in code as needed to call
additional help files.
• If you have more than one help file or window style to call from the program you should put the code for
changing help file names and windows in a separate subroutine. This makes any changes during the
project much easier to implement.
• You can let the help author edit the help file name and window specification by putting them in a separate
text file. Setting this file up in INI file format lets you use standard INI file commands to access this "text
database."
To ensure that the program and WinHelp can always find the help file:
• Register the help file by creating a string value under
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\HTMLHelp. The name of the string value is
the help file name (without path) and the value is the path.
• Always use the full path and file name when setting App.HelpFile, even if the help file is in the same
folder as the program executable.
To connect control level help (also called What's This? Help) to a form:
1. Set the form's WhatsThisHelp property to True.
2. For each control with a What's This? Help topic, set the WhatsThisHelpID. This number must match the
topic ID in the [MAP] section of the HTML Help project (.hhp) file.
3. To turn off What's This Help for a single control, set the control's WhatsThisHelpID to 0 (zero).
Notes:
• Once you put a topic number in the WhatsThisHelpID property of a control, the KeyDown, KeyUp,
and KeyPress events of the control are no longer triggered by the F1 key. You can detect any other key
press in these events, but not F1.
• The WhatsThisHelp property for a form cannot be changed at runtime. The only way to turn What's
This? Help on or off at run time is to set and clear the WhatsThisHelpID for the control.
Activate the What's This? Help Button in a Dialog Box Title Bar
If the form is not resizeable, you can put a ? in the title bar to activate What's This? Help mode. If the form is
resizeable you must handle this function using a separate button. See Connect What's This? Help to Resizeable
Windows.
Note:
• You cannot have a What's This? Help button in the title bar of any resizeable window, or any window set
to the Fixed ToolWindow style.
Notes:
• This activates What's This? Help mode for visible child forms, but not for any other non-modal forms
that may be open (for instance, tool windows).
• Any code in the subroutine after you call the WhatsThisMode method will not be executed until
What's This? Help mode is released by Visual Basic.
• The next mouse down event will be processed by the What's This? Help logic without triggering an
event you can intercept.
• If you put this code in the Click event you can call the button Click subroutine from the What's This?
Help menu item without worrying about parameters.
5. For each control with a What's This? Help topic, set the WhatsThisHelpID. This number must match the
topic ID in the [MAP] section of the HTML Help project (.hhp) file.
6. In the Help menu, create an item called What's This? Help and assign SHIFT-F1 as the shortcut. In the Click
event for this menu item, call the What's This? button Click or Mouse Up event where you put the
WhatsThisMode command.
7. In the MouseUp or Click event of What's This? Help button, activate What's This? Help mode for any non-
child non-modal form (such as a tool) that you want included in the What's This? Help logic. These forms
must have a WhatsThisHelpID set for each control, and their WhatsThisHelp property set to True. The code
would look something like this:
'**Set What's This? Help mode for tools that are open
If mnu_ColorWheel.Checked = True then
FrmTool1.WhatsThisMode
End If
Tips:
• You can trigger What's This? Help mode programmatically from any control that offers a MouseUp or
Click event.
• In C++, a menu item and equivalent toolbar item usually have the same control ID and thus the same
context ID (though this can be overridden). In Visual Basic you can easily set the WhatsThisHelpID for
each of these separately.
Tip:
• Unless there are only a few controls that do not implement a right click menu, I recommend calling the
topic directly if the user right clicks a button that does not otherwise have a right click menu. A pop-up
menu with a single What's This? item looks a bit strange, and this saves the user one click.
Note: The filename may be followed by an angle bracket (>) and the name of a secondary window if the topic
is to be displayed in a secondary window rather than in the primary window. The name of the secondary
window must have been defined in the [WINDOWS] section of the help project (.hhp) file.
uCommand specifies the type of help requested. For a partial list of possible values and how they affect the
value to place in the dwData parameter, see Help Command Constants below. For a full list, see the Microsoft
HTML Help Workshop Help.
dwData specifies additional data. The value used depends on the value of the uCommand parameter. For a
partial list of possible values, see Help Command Constants below. For a full list, see the Microsoft HTML Help
Workshop Help.
Note:
• This structure contains standard Windows POINTAPI and RECT structures, which must be defined in the
project. You can get these structures from the API Text Viewer that came with Visual Basic.
To display the Contents tab in the navigation pane and open the default topic:
HtmlHelp(frmMain.hWnd, App.HelpFile, HH_DISPLAY_TOC, ByVal 0&)
To display the Contents tab in the navigation pane and open a specific topic:
HtmlHelp(frmMain.hWnd, App.HelpFile & \
"::/TopicFileName.htm", HH_DISPLAY_TOC, ByVal 0&)
-OR-
HtmlHelp(frmMain.hWnd, App.HelpFile, \
HH_DISPLAY_TOC, ByVal "TopicFileName.htm")
To force all HTML Help windows closed that were opened by this app:
HtmlHelp(0&, "", HH_CLOSE_ALL, ByVal 0&)
Resources
All of the following plus links to other reference sites about online user assistance are available through the
Shadow Mountain Tech Web site (www.smountain.com).
On the Help/Connecting page:
• Latest update of this document and other documents about connecting online help to your program
• Programmer's Reference to WinHelp (by Don Lammers and Paul O'Rear)
• Sample code, including API definition modules.
• David Liske's help subclassing tutorial and modules
On the Help/Bugs & FAQ page:
• WinHelp 4.0 Unofficial Bug and Anomaly List (currently maintained by Don Lammers)
• WinHelp FAQ File (by Charlie Munro)