Click here to Skip to main content
15,867,488 members
Articles / Programming Languages / C++

Creating and Using HTML Help in MFC Applications

Rate me:
Please Sign up or sign in to vote.
3.73/5 (21 votes)
24 Apr 2013CPOL3 min read 132.4K   3.7K   64   23
Managing HTML Help from scratch
HTMLHelpByNguyenThanhPhuong/html_help_6.gif

Introduction

Last time I tried to search the Internet to get a complete guide of using HTML in an MFC application. I realized that there are many topics mentioning HTML Help but none of them has the same purpose with my desired work, so after working with HTML Help Workshop and reading documents, I finally decided to write a topic about working with HTML help from scratch.

In this presentation, I'll take you through 9 steps in 2 main stages to integrate an HTML help file with an MFC application. The 2 main stages are: 

  1. Create HTML Help files. 
  2. Link HTML file to your own MFC application. 

Stage 1: Create *.chm (Compiled Help Module) file

First of all, you need to have HTML Help Workshop installed, it can be downloaded from: Microsoft HTML Help Downloads

Edit your own *.chm file (Compiled Help Module). You can start from the beginning, but I would rather suggest you modifying an existing .chm file that has the same structure with your prospective .chm file. Do the following steps: 

Step 1. Open HTML Help Workshop. 

Step 2. Click File->Decompile. 

Step 3. Choose destination folder where you want to store files after decompiling. You should create a new folder to store files because many files are to be be generated after the decompilation. 

Select the existing .chm file.

HTMLHelpByNguyenThanhPhuong/html_help_1.gif

In this example, I use PowerDVD.chm file because it has the same help structure with my application.

Step 4. Using an HTML Editor, Microsoft Frontpage for example, to edit the content of the HTML file(s) that has/have been extracted by HTML Help Workshop to the content that you want to have. This step is like the process of editing a website.

Step 5. Import and Compile your own help

  • Click File->New->Project. One dialog appears, select Next.
  • Assign a name for the project. Click Next.
  • Check all checkboxes you see in the new dialog. Click Next.
  • In the next three dialogs, the New Project Wizards will ask you to locate the table of contents, the Help index and the HTML files. You simply choose the appropriate files that HTML Help Workshop has extracted in the folder in Step 3. Click Next each time you've answered one dialog.
  • Click File->Compile. 

That is all you need to do to create your own .chm file, now forward to the 2nd stage.

Stage 2: Aggregate Help file to your MFC Application

Step 6. Create a registry key:

  • Open command window, type regedit
  • Browse to KEY_LOCAL_MACHINE\Software\Microsoft\Windows\HTMLHelp
  • Create a new string value as follows:
    • Value name is your HTML help file name, for example: SampleHelp.chm
      • Value data is the path where the .chm file locates, for example: C:\TestHelp\MyHelp\ (remember to put one back-slash at the end).

HTMLHelpByNguyenThanhPhuong/html_help_5.gif

Step 7. Create an MFC application.

Step 8. Import htmlhelp.lib to your application.

  • Right click on the Resource Files->Add Files to Folder.
  • Select htmlhelp.lib.

HTMLHelpByNguyenThanhPhuong/html_help_3.gif

Step 9. Call Help

  • Create a button.
  • Add this line in the TestHelpDlg.cpp.
    C++
    #include "htmlhelp.h"
  • Assign an event to call the Help
    C++
    void CTestHelpDlg::OnHelp() 
    {
      HtmlHelp(this->m_hWnd, "HelpSample.chm", HH_DISPLAY_TOPIC, NULL);
    }

That's your work done!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Vietnam Vietnam
I am Vietnamese. I am a researcher in Computer Science and a freelance translator in German and Vietnamese.
Willing to share experience!

Comments and Discussions

 
QuestionCreating and Using HTML Help in MFC Applications; C++; Any source code for Context Sensitive Help (not popup help) Pin
Member 775002825-Feb-17 18:04
Member 775002825-Feb-17 18:04 
Questiondoesn't work Pin
Member 1149004831-Mar-15 19:46
Member 1149004831-Mar-15 19:46 
AnswerRe: doesn't work if we dont want to do anything / Actually it works Pin
Member 775002824-Feb-17 19:57
Member 775002824-Feb-17 19:57 
QuestionLayout RTL Pin
Minoo Khazeni30-Oct-11 0:54
Minoo Khazeni30-Oct-11 0:54 
Is there any way to put the Navigation Pane on the right?
GeneralDisplaying picture in HTML .chm Pin
sharon26-Jul-09 16:53
sharon26-Jul-09 16:53 
GeneralRe: Displaying picture in HTML .chm Pin
joso29-Apr-13 22:22
joso29-Apr-13 22:22 
GeneralCLR Pin
Nicolas29293-May-09 7:03
Nicolas29293-May-09 7:03 
QuestionAre you able to catch "What's This" htmlhelp requests in a CFormView? Pin
Member 345539813-Nov-08 8:03
Member 345539813-Nov-08 8:03 
GeneralHi,i can't down demo project Pin
somnuc13-Oct-08 7:10
somnuc13-Oct-08 7:10 
GeneralModifications Pin
asalvat9-Apr-08 7:49
asalvat9-Apr-08 7:49 
QuestionDisplaying a perticular topic in .chm file. Pin
bankey101017-Oct-07 23:44
bankey101017-Oct-07 23:44 
AnswerRe: Displaying a perticular topic in .chm file. Pin
Member 775002825-Feb-17 17:59
Member 775002825-Feb-17 17:59 
GeneralProblem with HtmlHelp Pin
dandany12-May-07 4:33
dandany12-May-07 4:33 
GeneralRe: Problem with HtmlHelp Pin
AlfonsoFuentes14-Jun-08 8:13
AlfonsoFuentes14-Jun-08 8:13 
GeneralRegistry entry Pin
Phil Sobolik12-Feb-07 9:51
Phil Sobolik12-Feb-07 9:51 
GeneralThank you Pin
Big Mouse18-Dec-06 17:58
Big Mouse18-Dec-06 17:58 
QuestionVisual C++ 2005 Upgrade? Pin
DrTom226-Nov-06 9:45
DrTom226-Nov-06 9:45 
Generalcalling html help Pin
h_rw14-Jun-06 23:06
h_rw14-Jun-06 23:06 
GeneralRe: calling html help Pin
Phuong Thanh Nguyen15-Jun-06 16:20
Phuong Thanh Nguyen15-Jun-06 16:20 
GeneralNice! Pin
thompsons2-Apr-06 10:24
thompsons2-Apr-06 10:24 
Generaldebug version Pin
toxcct13-Mar-06 23:16
toxcct13-Mar-06 23:16 
GeneralRe: debug version Pin
Phuong Thanh Nguyen14-Mar-06 16:15
Phuong Thanh Nguyen14-Mar-06 16:15 
GeneralRe: debug version Pin
toxcct14-Mar-06 21:08
toxcct14-Mar-06 21:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.