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



Comments

  • 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.

    Reply
  • 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.

    Workaround/Corrections:
    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.

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

Top White Papers and Webcasts

  • Packaged application development teams frequently operate with limited testing environments due to time and labor constraints. By virtualizing the entire application stack, packaged application development teams can deliver business results faster, at higher quality, and with lower risk.

  • IT decision support impacts all aspects of technology management, from governance and strategy to budgets and resource planning. IT decision support effectiveness often falls prey to data-driven challenges that make it difficult to understand the data in context. These challenges: overwhelming data volumes, heterogeneous data types, and growing data complexity. This Forrester Consulting Paper reports the three key findings from their study conducted, on behalf of BDNA, to test the hypothesis that data …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds