Set Help file and HelpContextId in VB6

In VB6 the way to achieve F1 content sensitive help is by connecting the application's project Help File Name and form's ContextId properties.

Tip
The Help Generator add-ins for VB6 automatically assigns Help File Name and ContextId to each form and this way connect to a corresponding generated topic page - which saves you a lot of time.
Example: Form Properties linking F1 to topic page in help file 

 The image on the right shows the properties set in VB6 .

  • The Application's Help File Name property tells F1 to open the xlCompare.chm file
  • The Help Context Id is a numeric way to tell which page to open in the Help File

Which topic page does Help Context Id point to?

To make the connection, you have to inform the the help compiler about the existance using the .hhp file. For this, we find it convenient to use a Map file and an Alias file. You can create these  manually, but if you use the Help Generator add-in they will be created automatically.

HHP File

In the above example the HHP file contains sections for alsia and mapping:

[ALIAS]
#include Faculty_alias.txt
[MAP]
#include Faculty_map.txt

Map file

You can assign the Context ID numbers to the specific topics in a Map file. The Map file is actually a C header file that is used by the Help compiler when the Help compiler compresses all the *.htm files into one *.chm file. The Map file is a plain-text file that contains the #define statement for each topic in your Help system....

#define IDH_frmFacultyQuery 50
#define IDH_frmFacultyAddressBook 60
...

Yes, the numerics (50, 60,...) are the Help Context Ids from the property window.

Alias file

The Help topics (.html files) must be associated to the topic identifiers that are defined in the Map file. You can do this if you define aliases for the Help topics. An alias is the relationship between a window-level Help topic (.html file) and a topic identifier in a Map file.

...
IDH_frmFacultyQuery=frmFacultyQuery.htm
IDH_frmFacultyAddress_Book=frmFacultyAddressBook.htm
...

Adding new Help Context Ids

You are free to add new Help Context Ids. Make sure you add an entry both in the map and the alias files.

Activating help from your application