Virtual Developer Workshop: Containerized Development with Docker

ContextHelp.gif (3646 bytes)

Environment: The code below goes for both the VC++ 5.0 and the new VC++ 6.0.

This is an supplement to the article submitted by Joep Oude Veldhuis. Please follow his description and instruction to install Microsoft HTML Help 1.21 or read the story at Microsoft.

By adding context help to your application expand the use and enhance the user experience. The context help can be recognized by the arrow cursor associated with the question mark. Dialog boxes supporting this can be recognized by the ? icon in the upper right-hand corner of the box. If the user have trouble understanding the function of some of the control, the solution is to click the icon, move the cursor into the control of question, and left-click the mouse. Alternative is for controls that have the input focus without generating a command message (like edit controls), is simply pressing the F1 key that has the same effect. A popup windows appears containing help text that you declared. Adding context help using the HTML popup can be described in four steps:

  1. Enable the context help for the dialog at the 'Dialog Properties' 'Extended Styles' page.
  2. Assign help text for the control in your 'String Table'.
  3. Trap the WM_HELPINFO message in the dialog box class.
  4. CopyPaste the code below into your desired class

It is important that the id used in your String Table is the same you named the control, try use the combo box at the 'String Properties' dialog. The message handler for the WM_HELPINFO message goes like this,

afx_msg BOOL OnHelpInfo(HELPINFO* pHelpInfo);
BOOL CDlg::OnHelpInfo(HELPINFO* pHelpInfo) 
  // This method does all the work	
  ShowContextHelp(CWnd::FromHandle((HWND)pHelpInfo->hItemHandle), pHelpInfo->MousePos, pHelpInfo->iCtrlId);

  // We will proceed the message, so skip the base class
  // return CDialog::OnHelpInfo(pHelpInfo);
  return TRUE;  

As mentioned in the comment, the ShowContextHelp(...) is the method that have our attention. The method takes two arguments: a pointer to the window, and the POINT structure where the help request occurred.

void CDlg::ShowContextHelp(CWnd* pWnd, POINT pt, int iCtrlID)
  CString s;

  // Load help text from String Table
    HH_POPUP hPop;					// HTML Help popup structure
    memset(&hPop, 0, sizeof(hPop));			// Initialize structure to NULLs	
    hPop.cbStruct         = sizeof(hPop);		// Set size of structure
    hPop.clrBackground    = RGB(255, 255, 208);	// Yellow background color
    hPop.clrForeground    = -1;			// Font color	
    hPop.rcMargins.left   = -1;			 
    hPop.rcMargins.bottom = -1;
    hPop.rcMargins.right  = -1;
    hPop.pt               = pt;	
    hPop.pszText          = s;			// Message from String Table
    hPop.pszFont          = NULL;			// Font
    HtmlHelp(pWnd->GetSafeHwnd(), NULL, HH_DISPLAY_TEXT_POPUP, (DWORD)&hPop);
  } // End if found a help string for this request
} // End ShowContextHelp(...)

The HH_POPUP structure is used to display the context help in a popup window. The structure has members for setting the foreground/background colors, for adjusting where the popup will be displayed, and for selecting the font to use. If you skip the first parameter, be typing NULL, you will experience that the popup window is acting like a modaless dialog, which was not the intention.

The second parameter for the HtmlHelp(...) method, point to a file object where the string resource also could be placed.

Hope you will find it usefull.


  • HTML Popup on wrong monitor

    Posted by Rob Fritz on 09/17/2018 02:26pm

    I'm having this problem: https://stackoverflow.com/questions/43764787/windows-htmlhelp-popup-on-wrong-monitor which is to say that when hPop.pt = pt has a negative X coordinate, which it can in a multi-monitor configuration when the app window is "left" of the system-defined main monitor, the context help appears Y-correct but left-justified (x=0) on the main monitor. Has anyone figured out a work-around?

  • Closing help context ??

    Posted by Legacy on 08/13/2003 07:00am

    Originally posted by: JS

    Does anyone have an idea of the way to close the htmlhelp popup ? I can't manage to get the CLOSE_ALL to work !
    Thanx !

  • complilation error comes due to missing "htmlhelp" file

    Posted by Legacy on 06/25/2003 07:00am

    Originally posted by: Sumita Sharma

    we have to add htmlhelp.lib and include "htmlhelp.h" else
    complilation errors like
    'HH_DISPLAY_TEXT_POPUP' : undeclared identifier
    'HtmlHelp' : undeclared identifier
    'HH_POPUP' : undeclared identifier
    will be generated

    If u have html.lib with u, this can solve ur problem

    Including HTML Help Support Files in an Application

    This topic discusses how to include the required HTML Help files in your application.

    To include the required HTML Help files in your application:

    1> Include Htmlhelp.lib in your project:

    1.1> In Visual C++, on the Project menu, click Settings... .

    1.2> In the Project Settings dialog box, click the Link tab, then select the Input category.

    1.3> Under the Additional library path, specify the directory location of the Htmlhelp.lib file on your computer.

    2> Include Htmlhelp.h in your project:

    2.1> On the Project menu, click Settings... .

    2.2> In the Project Settings dialog box, click the C/C++ tab, then select the Preprocessor category.

    2.3> Under Additional include directories, specify the directory location of the Htmlhelp.h file on your computer.

    3> In the Project Settings dialog box (Project menu), specify Htmlhelp.lib as the Object/libraries module in the Link tab, General category.

    4> In your project's Stdafx.h file, insert the following line:

    #include <htmlhelp.h>

    Note When using AppWizard to create an MFC (.exe) project, you do not need to select Context-sensitive help check box in Step 4, unless you also plan to use WinHelp in the application.

  • solution to Compilation error

    Posted by Legacy on 11/26/2002 08:00am

    Originally posted by: cc

    you need to add htmlhelp.lib
    and #include "htmlhelp.h"

    good luck.


  • Compiler Error!!!

    Posted by Legacy on 12/14/2001 08:00am

    Originally posted by: Deepak Gupta

    i have tried to implement this ode but got the compiler error as :
    'HH_POPUP' : undeclared identifier
    'HtmlHelp' : undeclared identifier
    'HH_DISPLAY_TEXT_POPUP' : undeclared identifier
    and other errors related to above.....

    i think some lib file needs to be included. i've tried going Microsoft link, but failed.

    pls help..
    Deepak Gupta.

  • HTMLHelp Question...

    Posted by Legacy on 11/24/2000 08:00am

    Originally posted by: Marc

    Just a question on using this method.

    I try and use this method as described to display some context sensitive help, however I keep getting a Debug Assertion Failure line 875 in Wincore.cpp?

    Have you seen this error before or know of anyplace I can look for more info on how I could solve this?


  • HtmlHelp(...)

    Posted by Legacy on 10/27/2000 07:00am

    Originally posted by: Aras

    Could you please tell me more about this method:
    Aras Noori

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date