Installation of the Microsoft HTML Help SDK

The HTMLHelp SDK is not provided with Visual Studio, at least not version 6. So if you have not installed it separately then you need to, as described in Installing HTML Help. Then look at my Introduction to HTMLHelp article if you need help getting started writing HTML Help files. Then set up the VC environment as described in Including HTML Help Support Files in an Application.

Program Modifications

The following is my version of how to modify a MFC application to use HTMLHelp.

Modifying the Resources

First create string resources to be used as prompts for the menus. Add the following ids with these strings or whatever other strings you choose. The resource editor will probably use the correct “Value” so you should not need to be concerned about that. I don’t know if it matters whether the exact values I show here must be used. Also it is probably not necessary to use all 6, probably only ID_HELP_CONTENTS, ID_HELP_INDEX and ID_HELP_SEARCH are necessary.
Display the Index of the Help file\nDisplay Index
List Help topics\nHelp Topics
Display instructions about how to use help\nHelp
Shows the help file
Display the Search tab of the Help file\nDisplay Search
Display the Table of Contents of the Help file\nDisplay Contents
Next add the following to a menu: ID_HELP_CONTENTS, ID_HELP_INDEX and ID_HELP_SEARCH. It is necessary to add them to a menu first since otherwise they will not be available in the ClassWizard to add handlers for them.

Modifying the Application

In your application’s InitInstance add the following so that the help file path and filename are set automatically. This assumes that your chm file is the same filename as your exe file except with a chm extension instead of the exe extension. It should also be in the same directory. That is the convention MFC uses and the following will just change the extension from hlp to chm. Next this code verifies that the chm file exists.

	CString strHelpFile = m_pszHelpFilePath;
if (strHelpFile.Right(4) == ".hlp") {
	strHelpFile = strHelpFile.Left(strHelpFile.GetLength()-4) + ".chm";
	m_pszHelpFilePath = _tcsdup(strHelpFile);
CFileStatus FileStatus;
if (!CFile::GetStatus(m_pszHelpFilePath, FileStatus)) {
	CString Message("Help file not found:\r\n");
	return FALSE;		// Optional; this can be removed
Modifying CMainFrame

Use ClassWizard to add handlers for ID_HELP_CONTENTS, ID_HELP_INDEX and ID_HELP_SEARCH then modify them as follows. I don’t know where I got the following code for OnHelpSearch from and I am not sure what it does. I should get answers to both those questions.

void CMainFrame::OnHelpContents() {
HWND hWnd = HtmlHelp(0, AfxGetApp()->m_pszHelpFilePath, HH_DISPLAY_TOC, NULL);
void CMainFrame::OnHelpIndex() {
HWND hWnd = HtmlHelp(0, AfxGetApp()->m_pszHelpFilePath, HH_DISPLAY_INDEX, NULL);
void CMainFrame::OnHelpSearch() {
memset(&q, 0, sizeof(HH_FTS_QUERY));
q.cbStruct = sizeof(HH_FTS_QUERY);
q.fUniCodeStrings = FALSE;
q.pszSearchQuery = "";
q.fStemmedSearch = FALSE;
q.fTitleOnly = FALSE;
q.fExecute = TRUE;
q.pszWindow = NULL;
HWND hWnd = HtmlHelp(0, AfxGetApp()->m_pszHelpFilePath, HH_DISPLAY_SEARCH, (DWORD)&q);

Then use ClassWizard again to override WinHelp, which is a virtual function, and then modify it as follows.

void CMainFrame::WinHelp(DWORD dwData, UINT nCmd) {
HWND hWnd = HtmlHelp(m_hWnd, AfxGetApp()->m_pszHelpFilePath, nCmd, dwData);
Custom Build Step

It is very convenient to have a custom build step for your chm file so that if you change it then it gets copied from wherever it is put by the HTMLHelp compiler to your project’s output directory (Debug or Release or whatever) automatically. By using a custom build step, this copy is done whenever you do a build of your VC project but only if the chm file has been changed. To create a custom build step for the help file, first add the file to the project. Then create the custom build step by using the “Custom Build Step” of the project settings. Select the chm file in the tree on the left then enter the following:


Copying $(InputPath)
copy $(InputPath) $(OutDir)\$(InputName).chm

  • talking to

    Can I simply say what a relief to discover someone that in fact understands what theyre discussing online. You certainly understand just how to bring a concern to light and also make it crucial. Even more individuals need to read this as well as understand this side of the tale. I cant believe youre not extra prominent due to the fact that you most definitely have the gift.


    I blog quite often and I genuinely thank you for your information. This article
    has really peaked my interest. I am going to bookmark your site and keep checking for new details about once per week.

    I subscribed to your Feed as well.

  • read the article

    Oh my goodness! a fantastic post man. Thanks Nevertheless I am experiencing concern with ur rss. Don?t recognize why Incapable to sign up for it. Is there anybody obtaining the same rss issue? Any individual that knows kindly respond. Thnkx

  • over at this website

    Can I just state what an alleviation to discover somebody that in fact recognizes what theyre talking about on the internet. You most definitely recognize exactly how to bring an issue to light and make it vital. Even more individuals need to read this and also understand this side of the story. I cant believe youre not extra preferred because you absolutely have the present.

  • Learn More

    An impressive share, I simply provided this onto a colleague that was doing a little evaluation on this. And he actually purchased me morning meal because I found it for him. smile. So let me reword that: Thnx for the reward! However yeah Thnkx for investing the time to discuss this, I feel strongly about it and also like reading more on this topic. Ideally, as you become experience, would you mind upgrading your blog with more information? It is highly helpful for me. Large thumb up for this article!

  • online

    When I originally commented I clicked the -Inform me when brand-new remarks are added- checkbox and also now each time a remark is added I get 4 e-mails with the exact same remark. Exists any way you can remove me from that service? Thanks!

  • Eric Edey

    The following time I check out a blog site, I wish that it does not dissatisfy me as high as this set. I mean, I know it was my selection to review, but I really assumed youd have something intriguing to claim. All I listen to is a lot of whining about something that you can deal with if you werent as well hectic trying to find focus.

  • Palmira Cambridge

    I?d have to check with you right here. Which is not something I normally do! I take pleasure in reviewing an article that will certainly make individuals believe. Additionally, many thanks for enabling me to comment!

  • find out here

    The next time I review a blog site, I hope that it does not dissatisfy me as long as this set. I suggest, I recognize it was my selection to read, but I really thought youd have something fascinating to claim. All I hear is a bunch of yawping regarding something that you can take care of if you werent too hectic looking for attention.

  • Check Out Your URL

    I found your blog website on google as well as inspect a few of your early messages. Continue to maintain the great run. I simply extra up your RSS feed to my MSN Information Viewers. Looking for forward to finding out more from you in the future!?

  • cbd capsules stoked

    Can I simply state what an alleviation to discover someone who in fact recognizes what theyre speaking about on the net. You certainly understand how to bring a problem to light and make it crucial. Even more individuals need to read this and comprehend this side of the story. I angle think youre not more popular because you most definitely have the gift.

  • can cbd oil be given to dogs taking rimadyl

    I?m pleased, I have to claim. Truly rarely do I encounter a blog that?s both educative and also amusing, and let me tell you, you have actually hit the nail on the head. Your idea is impressive; the problem is something that insufficient individuals are speaking wisely around. I am very satisfied that I came across this in my search for something associating with this.

  • John Deere Technical Manuals

    One more thing. In my opinion that there are many travel insurance web sites of reputable companies than enable you to enter your holiday details and have you the quotes. You can also purchase the actual international travel insurance policy on-line by using your credit card. All that you should do will be to enter your current travel specifics and you can see the plans side-by-side. Simply find the package that suits your capacity to pay and needs after which use your bank credit card to buy the idea. Travel insurance on the web is a good way to start looking for a respectable company to get international travel cover. Thanks for expressing your ideas.

  • his response

    Oh my goodness! a fantastic article dude. Thank you Nevertheless I am experiencing problem with ur rss. Don?t know why Incapable to subscribe to it. Exists any individual getting similar rss problem? Anybody who recognizes kindly respond. Thnkx

  • John Deere Technical Manuals

    On this very topic, I try update my blogs almost like I’m speaking to somebody or talking to that reader directly as I consider it helps engage people a lot more than writing content formally especially when my own blog is based around the goings ons, daily thoughts and research about this somewhat controversial concern. I discovered that I nonetheless need to use more of the methods you have mentioned in this posting.

  • Gregory Rochlin

    I just want to mention I’m very new to blogging and site-building and actually liked this website. Likely I’m likely to bookmark your site . You definitely have exceptional article content. With thanks for sharing your web site.

댓글 남기기