Click here to Skip to main content
15,868,016 members
Articles / Desktop Programming / MFC
Article

Adding Context Help to your application

Rate me:
Please Sign up or sign in to vote.
4.77/5 (11 votes)
6 Jun 20042 min read 86.5K   47   14
This short article demonstrates the ability to add Context Help to your application.

Sample Image - ContextHelp.gif

Introduction

Adding context help to your application expands the use and enhances 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. How to install Microsoft HTML Help 1.4 SDK... read the story at Microsoft.

User Enhancements

If the users have trouble understanding the function of some of the controls, 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 input focus without generating a command message (like edit controls), is simply pressing the F1 key that has the same effect. A popup window appears containing help text that you declared.

Four steps

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. Copy-paste the code below into your desired class.
BEGIN_MESSAGE_MAP(CDlg, CDialog)
 ON_WM_HELPINFO()
END_MESSAGE_MAP()

It is important that the ID used in your String Table is the same you named the control, try using the combo box at the 'String Properties' dialog.

Ready for Message Handler

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 has our attention. The method takes three arguments: a pointer to the window, the POINT structure where the help request occurred, and the identification for the control.

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

 // Load help text from String Table
 if(s.LoadString(iCtrlID))
 {
  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, 
   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, by typing NULL, you will experience that the popup window is acting like a modeless dialog, which was not the intention.

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

Hope you will find it useful.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Denmark Denmark
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionCan you do HtmlHelp in a CFormView? Pin
Member 345539813-Nov-08 7:20
Member 345539813-Nov-08 7:20 
General[Message Removed] Pin
nompel5-Oct-08 0:09
nompel5-Oct-08 0:09 
QuestionPop-up help for menus Pin
moihere5-Oct-07 3:18
moihere5-Oct-07 3:18 
GeneralDual Monitor Pin
paulgafa18-Oct-06 20:03
paulgafa18-Oct-06 20:03 
GeneralThanks Pin
barnabe4217-May-06 21:38
barnabe4217-May-06 21:38 
Generalconfine the text in a recangle Pin
mimosa9-May-06 10:59
mimosa9-May-06 10:59 
GeneralRe: confine the text in a recangle Pin
kokholm9-May-06 21:38
kokholm9-May-06 21:38 
Questionwhy calls for .hlp file? Pin
No-Cloud-Dagon23-Feb-05 13:38
No-Cloud-Dagon23-Feb-05 13:38 
GeneralhPop.pszFont="What?" Pin
Penguen Efendi16-Dec-04 9:18
Penguen Efendi16-Dec-04 9:18 
GeneralError 2660 Pin
nevedko5-Jul-04 16:08
nevedko5-Jul-04 16:08 
GeneralRe: Error 2660 Pin
metallman5-Aug-04 0:58
metallman5-Aug-04 0:58 
GeneralRe: Error 2660 Pin
Programmer_Chris6-Nov-04 21:12
Programmer_Chris6-Nov-04 21:12 
GeneralRe: Error 2660 Pin
Penguen Efendi21-Nov-04 8:01
Penguen Efendi21-Nov-04 8:01 
GeneralNice! Pin
Ravi Bhavnani7-Jun-04 2:19
professionalRavi Bhavnani7-Jun-04 2:19 
A nice alternative to having to supply a .chm file along with your app. Thanks for your post!

/ravi

My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com

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.