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[] =
{
CONTROL ID, HELP ID GENERATED WITH MAKEHM TOOL,
0,0
};

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[] =
{
IDC_BUTTON_HELP ,HIDC_BUTTON_HELP,

//define other controls IDs here.

0,0
};

3. Include resource.hm 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\resource.hm>


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,
(DWORD)(LPVOID)m_nHelpIDs);


}

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


cs.style = WS_OVERLAPPED | WS_CAPTION |FWS_ADDTOTITLE
| WS_THICKFRAME | WS_SYSMENU;
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

More by Author

Must Read