This article describes how to convert an MFC AppWizard generated context-sensitive Help enabled application to use HTML Help instead of WinHelp. It assumes that no modifications have been made to the application since the AppWizard generated it. The result is the equivalent of
the context-sensitive Help application generated by the AppWizard except that HTML Help is used instead of WinHelp. The same basic functionality will be present. It is not a complete Help system but it provides general help and context help for menu items.
The procedure is slightly different depending on whether a document/view application or a dialog-based application is generated. The differences are noted below.
Installing the HTML Help Workshop also installs the library and header files you need to in order to implement HTML Help in your application.
Run the HTML Help Workshop and select File, New, Project, then click OK.
Check the Convert WinHelp Project box and click Next. Type in the path name of your WinHelp project (.hpj file) and the path name you want to use for your HTML Help project file, (.hhp). (Hint: It will make things simpler later on if you put your HTML Help file in the same folder as the WinHelp file. The rest of this article assumes you have done this.) Click Next and Finish.
Save your HTML Help project and exit the HTML Help Workshop.
If you are creating a dialog-based application you can skip this step.
Using a text editor, open the HTML Help project file (.hhp), and add a blank line to the end of the file. Then insert the following block of code.
Change the include files in the [MAP] section to have .h file extensions instead of .hm file extensions.
When using WinHelp, context help IDs are automatically generated when the .hlp file is generated. They are kept in a file called [yourprojectname].hm. You cannot include .hm files in an HTML Help project file. The HTML Help compiler expects include files to contain #define statements. You need to manually edit the file, hlp\[yourprojectname].hm, to have #define statements following the instructions below. Then rename the file to give it a .h file extension instead of a .hm file extension.
Use a text editor to open the file and edit it so that each line containing
a context help ID is preceded by a #define statement. For example:
HIDD_ABOUTBOX 0x20064
becomes:
#define HIDD_ABOUTBOX 0x20064
Save the file as [yourprojectname].h in the \hlp folder of your project.
If you are creating a dialog-based application you can skip this step.
Also notice that the file C:\Program Files\Microsoft Visual Studio\VC98\MFC\include\afxhelp.hm is listed in the HTML Help project file. You can create this file by using a text editor to open a new file, cut and then paste the text below into it. Name the file
Afxhelp.h and copy it to the C:\Program Files\Microsoft Visual Studio\VC98\MFC\include\ folder.
Save the file and name it Table of Contents.hhc. Put it in the same folder as your .hhp file.
Open your .hhp file with the HTML Help Workshop and double-click the [OPTIONS] tag. Click on the Files tab and add Table of Contents.hhc to the contents file. Click OK.
NOTE: If you have created a dialog-based application, by default Visual C++ does not create an index file for your WinHelp project so there is not an index file available for conversion when you choose to convert your WinHelp project to HTML Help. Although there is no index file, the wizard still specifies an index on the Project Options File tab that you should remove so that your HTML Help project doesn't generate an error at compile time.
Save the .hhp file and compile it.
To test the HTML Help file, using File Explorer, double-click the .chm file. This displays your HTML Help project. Click on various topics to be sure that the conversion completed properly.
In Visual Studio, on the Files View tab, remove the .hpj, .cnt and .hlp files. This action removes the steps that build the WinHelp project.
Add the HTML Help project file, .hhp, to your Visual C++ project. In Visual Studio, from the Project menu select Add to Project to select and add the file to the project. Next, select the file under the Files View tab and drag it to the Help Files branch of the tree.
Having your HTML Help project automatically rebuilt when you rebuild your Visual C++ application is optional. To do this, right-click the .hhp file in the Files View tab, and select Settings. Add the following custom build commands in the Command field:
hhc.exe .\hlp\$(InputName).hhp
Add the following to the Outputs field:
$(InputName).chm
Make sure you add the path of hhc.exe file under the Tools menu, select Options then select Directories for Executables.
Include Htmlhelp.h in your CWinApp module using an include statement.
In Visual Studio under the Project menu choose Settings then selectLink and under Category, select General. Add Jtmlhelp.lib to the Object/library modules: selection. This causes the HTML Help library to link to your project.
In Visual Studio under the Tools menu choose Options then Directories, and add the path to both the Htmlhelp.lib and Htmlhelp.h files. The location of these files depends upon where the HTML Help Workshop was installed, however this file might be found at ..\Program Files\HTML Help Workshop\lib" and "\Program Files\HTML Help Workshop\include.
If you are creating a dialog-based application, skip to the next step.
If you are creating an SDI/MDI application, use class wizard to add a handler for WinHelp to your CWinApp class.
Comment out the call to WinHelp in CWinApp::WinHelp.
Copy the text below into the WinHelp method. Change [yourprojectname] to the name of your .chm file. Rebuild the Visual C++ application and run it.
If you are creating a dialog-based application, use the class wizard to add an OnHelp handler to your dialog class. This handler is invoked when the default Help button on the dialog is clicked.
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.