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