Click here to Skip to main content
Click here to Skip to main content

Adding Context Help to your application

By , 6 Jun 2004
 

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

About the Author

kokholm
Denmark Denmark
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionCan you do HtmlHelp in a CFormView?memberMember 345539813 Nov '08 - 7:20 
Are you or have you been able to have HTMLHELP popups in a CFormView?
I can make it work in a DialogBox.
I can catch the OnHelpHitTest in a CFormView, but I can't make the help popup actually happen.
 
If you have been able to do this, could you share the information?
 
Thanks.
General[Message Removed]membernompel5 Oct '08 - 0:09 
Spam message removed
QuestionPop-up help for menusmembermoihere5 Oct '07 - 3:18 
Thanks for such a simple and clean solution(sans chm files) for showing pop-up helps in dialogs.
 
Is there a similar solution for showing help strings from string table for menu items also?Confused | :confused: The status bar text is already entered in string table against the menu-id.

GeneralDual Monitormemberpaulgafa18 Oct '06 - 20:03 
Hi I have something similar in a project but when using a dual monitor the text always pops on the primary display. Any ideas how to solve?
 
Zippo
GeneralThanksmemberbarnabe4217 May '06 - 21:38 
Thanks , I hate those chm file.
it's really easy to implement that way.
Generalconfine the text in a recanglemembermimosa9 May '06 - 10:59 
Hi,
 
this is a nice add-on. If I have a long text to display and I want to limit the size of the rectangle (so I would have a multiline displayed text), how to do?
 
thanks
 
Mat Suspicious | :suss:
GeneralRe: confine the text in a recanglememberkokholm9 May '06 - 21:38 
Hej Mat,
 
thank you - hope this small piece of code can enhance your application. To "break" your tooltip text just add a simple newline \n in the string.
 
http://www.faqs.org/docs/bashman/bashref_12.html[^]

 
Thomas Kokholm
 
-- modified at 2:36 Friday 12th May, 2006
Questionwhy calls for .hlp file?memberNo-Cloud-Dagon23 Feb '05 - 13:38 
I have my project as suggested here. But when I run it, it pops up context help tip, and calls for .hlp file immediatelly. What is wrong with my application, who know?
GeneralhPop.pszFont="What?"memberPenguen Efendi16 Dec '04 - 9:18 
What about if we want to specify a font to be used in our pop-up? I know this from msdn:
hPop.pszFont="MS Sans Serif, 10, , BOLD";
But the complete format is:
facename[, point size[, charset[ BOLD ITALIC UNDERLINE]]]
meaning that, we can specify a charset for our font too. I searched but can't found a 'list' of this charset options. There are lots of charset as GREEK, RUSSIAN, TURKISH etc... But these 'strings' don't work in hPop.pszFont. Lets say i want to pop a text in greek on an english windows. What must be the charset in hPop.pszFont? Isn't there a complete list?
 
Thanks Smile | :)
GeneralError 2660membernevedko5 Jul '04 - 16:08 
Not sure what I'm doing wrong but after I copy and pasted code as outlined in step 4 of this tutorial I got:
 
testView.cpp(120): error C2660: 'CWnd::HtmlHelpA' : function does not take 4 arguments
 
Am I missing something? Any help appreciated.
GeneralRe: Error 2660membermetallman5 Aug '04 - 0:58 
Try replacing the call to HtmlHelp() with ::HtmlHelp() and linking against htmlhelp.lib.
GeneralRe: Error 2660memberProgrammer_Chris6 Nov '04 - 21:12 
I cannot figure out how to link to the htmlhelp.lib, linking against htmlhelp.lib. I searched but I cannot find that library. Help?
 
Chris
GeneralRe: Error 2660memberPenguen Efendi21 Nov '04 - 8:01 
OK, first, you must go and download HTML Help Workshop 1.3 from microsoft's download page (htmlhelp13.exe - 3.34MB). Install it. Now go to the folder 'C:\Program Files\HTML Help Workshop\include' (or wherever you have installed) and copy the file 'htmlhelp.h' to your project directory. Likewise, from folder 'C:\Program Files\HTML Help Workshop\lib' copy the file 'htmlhelp.lib' to again your project directory. Open your Project Settings dialog in vc++ by pressing alt+F7. Go to Link tab, select Input from Category combo, type htmlhelp.lib in Object/library modules box and click OK. Open the cpp file which you make use of HtmlHelp(...) function. Add #include "htmlhelp.h" end of the other #includes. That's it..
 
By the way, here is my OnHelpInfo(...) which pops the help window always below the control that requires it. When the focus is on a control, mouse is away somewhere and user hits F1, the help popup window appears at the right&bottom corner of the focused control instead of at the mouse which is away.
 
BOOL CMyDlg::OnHelpInfo(HELPINFO* pHelpInfo)
{
CWnd *pWnd;
RECT r;
POINT p;
pWnd=CWnd::FromHandle((HWND)pHelpInfo->hItemHandle);
pWnd->GetWindowRect(&r);
p.x=r.right;
p.y=r.bottom;
ShowContextHelp(pWnd,p,pHelpInfo->iCtrlId);
return TRUE;
}

 
PS: You may add the line hPop.rcMargins.top = -1; to ShowContextHelp(...) to put a margin to the top of the popup help window too.
GeneralNice!memberRavi 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    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130523.1 | Last Updated 7 Jun 2004
Article Copyright 2004 by kokholm
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid