HTML Help - Context Help Ids

How do I setup my HTML help to use context help ids? 

It is such a common question and one not really answered in the workshop online help.

Open your project (.hhp) file in notepad or some other text editor.

Add a [MAP] section and define the IDs your require.
Add an [ALIAS] section and define the mapping between each ID and a help topic.

Best to show you by example:

[ALIAS]
IDH_HomePage=default.htm
IDH_TestTopic1=htmlfiles\testtopic1.htm
IDH_TestTopic2=mychm::htmlfiles\testtopic2.htm

[MAP]
#define IDH_HomePage 1000
#define IDH_TestTopic1 1001
#define IDH_TestTopic2 1002

Alternatively you can do this:

[ALIAS]
#include myhelp.ali

[MAP]
#include myhelp.h

where myhelp.ali is a text file containing

   IDH_HomePage=default.htm
   IDH_TestTopic1=htmlfiles\testtopic1.htm
   IDH_TestTopic2=mychm::htmlfiles\testtopic2.htm

and myhelp.h is a text file containing

   #define IDH_HomePage 1000
   #define IDH_TestTopic1 1001
   #define IDH_TestTopic2 1002

That's it. Nothing much to it is there? Recompile your .HHP file. Now your application can call help using context help Ids instead of topic file names.

Typical context call made from the application:

HtmlHelp(0, "c:\app\help\Help.chm", HH_HELP_CONTEXT, 1001);

Typical context call with window type $global_main included:

HtmlHelp(0, "c:\app\help\Help.chm>$global_main", HH_HELP_CONTEXT, 1001);

My Context Calls Don't Work? 

I've seen a few reports of contextual help not working. According to MVP David Liske it appears to be related to using the #included statement. David's fix is to add the include file under the [FILES] section of the .hhp file. Thanks David.

Context Ids in Merged Help 

Notice that the example above contains a link to a topic in slave CHM. This works but on closer examination we find that the indexes don't merge. This seems to be a problem with latter versions of HTML Help (hhctrl.ocx).

EG. IDH_TestTopic2=mychm::htmlfiles\testtopic2.htm

See also: Context Ids in Merged Help