Implementing ToolTip Style Context Sensitive Help in CFormView based Applications

 Download Source Code and Example

Steps Required

1. In your form view or in the dialogs you are working with, turn "Help ID" property on for every control you want to have context sensitive help.

2. #define a double word Array in your View class as

static const DWORD m_nHelpIDs[];

and in your Implementation do the following:

const DWORD COurView::m_nHelpIDs[] = 

In our case declaration of help IDs array is as

static const DWORD m_nHelpIDs[];

and these IDs are defined as

const DWORD CCSHView::m_nHelpIDs[] = 

	//define other controls IDs here.


3. Include file in your View.CPP file.

4. Open your application's HPJ (help project file) and add the following line at the end of the file

#include <D:\Development\CSH\>

The path will differ according to the location of your project.

5. Now override two functions of your CFormView based class. One is WM_CONTEXTMENU and other is WM_HELPINFO.

Fill the functions' bodies as follows.

// CCSHView message handlers

void CCSHView::OnContextMenu(CWnd* pWnd, CPoint point)
	::WinHelp(pWnd->m_hWnd, AfxGetApp()->m_pszHelpFilePath, HELP_CONTEXTMENU,

} BOOL CCSHView::OnHelpInfo(HELPINFO* pHelpInfo) { return ::WinHelp((HWND)pHelpInfo->hItemHandle, AfxGetApp()->m_pszHelpFilePath, HELP_WM_HELP, (DWORD)(LPVOID)m_nHelpIDs); }

6. Now Open Microsoft Word (or any other RTF word processor) "AfxCore.RTF" file located in your projects HLP directory. This file was generated by Application Wizard.

7. In Tools menu click Options and then highlight "View" tab. Then turn "Hidden Text" check box on which is in the group "Non Printing characters". Now Click "Show/Hide" button

8. Now navigate to the end of file and press Ctrl + Enter to enter a hard page break.

9. Type help text here for the first control. In our case it is IDC_BUTTON_HELP. We type "Displays detailed help for the application" here.

10. Now go to beginning of the line and insert a footnote with a custom mark "#" and in the footnote type HIDC_BUTTON_HELP here. Click in the view window again.

11. Now to see a question mark icon in the title bar of the application go to your application's CMainFrame class's add the following lines in your CMainFrame::PreCreateWindow(..) function = WS_OVERLAPPED | WS_CAPTION |FWS_ADDTOTITLE
	cs.dwExStyle |= WS_EX_CONTEXTHELP;

If you turn WS_MINIMIZE AND WS_MAXIMIZE on then question mark icon will not appear in the title bar.

12. Bingo. We are done. Compile the project and see the online context sensitive help in action. Press Shift + F1 key when the focus is on the "Help" button in the form view and see a little tooltip style window containing the help you wrote. Here is how it will look like

Where now?

The next article explores how to implement ToolTip style context sensitive help in a dialog.

Last updated: 24 April 1998


  • ToolTip - Context Sensitive Help - I'm impressed

    Posted by Legacy on 03/13/2000 12:00am

    Originally posted by: Vince

    I must say, this is the most impressive context sensitive help method I have seen so far. All other ones I have read in the past attempt to use HTMLHELP with H_CONTROL and so forth...after following other methods which require tyou to download various files from the net and embed a heap of code, I was deterred each time.

    This method, on the other hand, is about as easy as it gets. Contrary to the other comment to this topic, I found the code provided to work perfectly in a CFormView app. I shall recommend this to other colleagues and I suggest you don't waist yourt time attempting to learn other lengthly methods which often result in dissapointment.

  • Implementing ToolTip Style Context Sensitive Help in CFormView based Applications

    Posted by Legacy on 01/26/1999 12:00am

    Originally posted by: K. Faidt

    With Visual Studio 6.0, NT 4.0, the sample code provided with this page did not work. Setting a breakpoint in CCSHView::OnHelpInfo, the windows help window appeared displaying the contents page before entering the breakpoint.
    Stepping over the call of WinHelp, an additional popup appeared telling that the help topic wasn't found.

    The help with the "sample dialog" (as described in the next page) did work: The correct popups did appear without showing the windows help window before.

    1. Rebuild csh.hlp after inserting help topics for the controls of the view. The help topics weren't found because they were not present in the help file.
    2. To avoid displaying the WINDOWS help window, I mapped the MFC-internal message WM_COMMANDHELP to method OnCommandHelp (a method of the view class). That method only returns true. An alternative way would be to call WinHelp in that method and omit handling of WM_HELPINFO.

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

Top White Papers and Webcasts

  • Entire organizations suffer when their networks can't keep up and new opportunities are put on hold. Waiting on service providers isn't good business. In these examples, learn how to simplify network management so that your organization can better manage costs, adapt quickly to business demands, and seize market opportunities when they arise.

  • Microsoft® Office 365 is a top choice for enterprises that want a cloud–based suite of productivity collaboration applications. With Office 365, you get access to Microsoft™ Office solutions practically anytime, anywhere, on virtually any device. It's a great option for current Microsoft users who can now build on their experience with Microsoft™ solutions while enjoying the flexibility of a cloud-based delivery. But even organizations with no previous investment in Microsoft will find that …

Most Popular Programming Stories

More for Developers

RSS Feeds

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