How to Integrate a CHM File with Your Application
After you have created an HTML Help (CHM) file, you will probably want to integrate it with your application and provide context-sensitive Help. Below are code examples that demonstrate how to connect a CHM help file with a programming language or IDE.
Working with a CHM File from a .NET Application
In the .NET environment we use built-in support for the HTML Help (CHM) format.
Call a help topic by Context Id:
Help.ShowHelp(this, "c:\my_help_file.chm", HelpNavigator.TopicId, "20");
Show the Table of Contents:
Help.ShowHelp(this, "c:\my_help_file.chm", HelpNavigator.TableOfContents, "");
Show the Keyword Index:
Help.ShowHelp(this, "c:\my_help_file.chm", HelpNavigator.Index, "");
Working with a CHM File from a VBA Application
Note that in a VBA application we use HTML Help API calls directly.
Declare the Following Constants:
Public Const HH_DISPLAY_TOPIC = &H0 Public Const HH_DISPLAY_TOC = &H1 Public Const HH_DISPLAY_INDEX = &H2 Public Const HH_HELP_CONTEXT = &HF
Declare the HTMLHelp() API function:
Declare Function HTMLHelp Lib "hhctrl.ocx" Alias "HtmlHelpA" (ByVal hwndCaller As Long, ByVal pszFile As String, ByVal uCommand As Long, ByVal dwData As Long) As Long
Call a help topic by Context Id:
HTMLHelp 0, MyHelpFile, HH_HELP_CONTEXT, MyTopicContextID
Show the Table of Contents:
HTMLHelp 0, MyHelpFile, HH_DISPLAY_TOC, 0
Working with a CHM File from a Delphi Application
In a Delphi application we use built-in support for the HTML Help (CHM) format.
Define the CHM filename:
Application.HelpFile := ExtractFilePath(Application.ExeName) + 'MyHelpFile.chm';
Call a help topic by Context Id:
Application.HelpContext(IDH_TOPIC);
Show the Table of Content:
HtmlHelp(0, Application.HelpFile, HH_DISPLAY_TOC, 0);
Show the keyword Index:
HtmlHelp(0, Application.HelpFile, HH_DISPLAY_INDEX, DWORD(PWideChar('My Test Keyword')));
Download a CHM Creation Tool
After watching the video which explains how you can create a CHM file with a help authoring tool, you may want to download the application whose basic features we have demonstrated. If you need more information on creating and using HTML Help (CHM) files, you can also visit the related links in the right box.