Virtual Developer Workshop: Containerized Development with Docker

Environment: Visual C++ 5 & 6

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	
  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

  // Initialize structure to NULLs	
  memset(&hPop, 0, sizeof(hPop)); 

  // Set size of structure
  hPop.cbStruct         = sizeof(hPop);		

  // Yellow background color
  hPop.clrBackground    = RGB(255, 255, 208);	

  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, 
 } // 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.


  • Dialog inside a tab control inside a form view inside a splitter window inside a dialog

    Posted by Matthijs.Wessels on 03/22/2006 03:26pm

    If we do it your way, the whole program hangs. if we replace the first parameter in the HtmlHelp() function with a pointer to the main dialog then we can see the context help, but the program still hangs. We use a static CSplitterWnd split into 4 panes. The second pane(index 1) contains a CFormView. On the CFormView we put a CTabCtrl (using the designer). This CTabCtrl contains a bunch of tabs which are CDialogs. We have a button on one of these CDialogs and when we press F1 when this button is selected, the context sensitive help should pop up.

  • How do you trap context help message on cfiledialog

    Posted by vgandhi on 04/06/2004 05:56pm

     I am using a class derived from CFileDialog. I have created a custom checkbox below the default one that comes with CFileDialog i.e. 'Open as read-only'. However when I try to associate help with that custom checkbox I get no help associated. 
    Here is the code I am using
    CRect rectCheckbox;
    GetParent()->GetDlgItem( chx1 )->GetWindowRect( rectCheckbox );
    // Make the text window a little bigger
    int nWindowWidth = rectCheckbox.Width() + 200;
    int nWindowHeight = rectCheckbox.Height();
    ScreenToClient( &rectCheckbox );
    //  Create checkbox with style and font and location from the //read-only checkbox
    CButton m_TestHelp;
    rectCheckbox, GetParent(),IDC_TEST_HELP);
    CWnd *pCtl = GetParent()->GetDlgItem( IDC_TEST_HELP );
    pCtl->SetWindowPos( NULL, rectCheckbox.left, rectCheckbox.top+20, nWindowWidth, nWindowHeight,
    pCtl->EnableWindow( TRUE );
    pCtl->ShowWindow( SW_SHOW );
    pCtl->SetWindowContextHelpId( HIDC_TEST_HELP);
    So when I click on the question mark next to 'X' at the top of the dialog and drag it on the custon checkbox created I don't get the help id associated with HIDC_TEST_HELP. I get the default help id 28441/0x6f19 which says 'no help associated with this item'.
    I have the method defined but it doesn't even hit this method
    BOOL CCustomFileDialog::OnHelpInfo(HELPINFO* pHelpInfo) 
    	// TODO: Add your message handler code here and/or    call default	
    	return CFileDialog::OnHelpInfo(pHelpInfo);
    Please help. 

  • 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