Adding Context Help

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
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 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
  if(s.LoadString(iCtrlID))
  {
    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.



Comments

  • Closing help context ??

    Posted by Legacy on 08/13/2003 12: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 !

    Reply
  • complilation error comes due to missing "htmlhelp" file

    Posted by Legacy on 06/25/2003 12: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.


    Reply
  • solution to Compilation error

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

    Originally posted by: cc

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


    good luck.

    cc

    Reply
  • Compiler Error!!!

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

    Originally posted by: Deepak Gupta

    Hi,
    
    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.

    Reply
  • HTMLHelp Question...

    Posted by Legacy on 11/24/2000 12: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?
    thx

    Marc

    Reply
  • HtmlHelp(...)

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

    Originally posted by: Aras

    Could you please tell me more about this method:
    
    HtmlHelp(....)
    thanks,
    Aras Noori

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

Top White Papers and Webcasts

  • With 81% of employees using their phones at work, companies have stopped asking: "Is corporate data leaking from personal devices?" and started asking: "How do we effectively prevent corporate data from leaking from personal devices?" The answer has not been simple. ZixOne raises the bar on BYOD security by not allowing email data to reside on the device. In addition, Zix allows employees to maintain complete control of their personal device, therefore satisfying privacy demands of valued employees and the …

  • Managing your company's financials is the backbone of your business and is vital to the long-term health and viability of your company. To continue applying the necessary financial rigor to support rapid growth, the accounting department needs the right tools to most efficiently do their job. Read this white paper to understand the 10 essentials of a complete financial management system and how the right solution can help you keep up with the rapidly changing business world.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds