This topic has not yet been rated - Rate this topic

Message-Map Support

Visual Studio .NET 2003

The MFC Application Wizard adds a new menu command titled Help Topics to the two Help menus. Support for this command and for F1 and SHIFT+F1 help is provided through the message map. Topics covered in this article include:

Help Commands in the Message Map

To support the Help Topics menu item, F1 help, and SHIFT+F1 help, the MFC Application Wizard adds four entries to the message map for your CFrameWnd-derived or CMDIFrameWnd-derived class. This message map is in the MainFrm.cpp file, and the relevant message-map entries are located below the // Global help commands comment.

After you run the MFC Application Wizard, click Context-Sensitive Help. The message map for class CMainFrame will look like the following for an MDI application:

// CMainFrame

BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
   //{{AFX_MSG_MAP(CMainFrame)

   //   DO NOT EDIT what you see in these blocks of generated code !
   ON_WM_CREATE()
   //}}AFX_MSG_MAP
   // Global help commands
   ON_COMMAND(ID_HELP_FINDER, CMDIFrameWnd::OnHelpFinder)
   ON_COMMAND(ID_HELP, CMDIFrameWnd::OnHelp)
   ON_COMMAND(ID_CONTEXT_HELP, CMDIFrameWnd::OnContextHelp)
   ON_COMMAND(ID_DEFAULT_HELP, CMDIFrameWnd::OnHelpFinder)
END_MESSAGE_MAP()

For an SDI application, references to CMDIFrameWnd in this code are replaced by references to CFrameWnd.

About the Help Commands

The four help-related message-map entries follow the // Global help commands comment. The following table explains the purpose of each command ID used in these entries.

Help-Related Command IDs

Command ID Purpose
ID_HELP_FINDER Responds to the Help Topics menu item on the Help menu by displaying the Windows Contents screen.
ID_HELP Responds to F1 by displaying a specific topic in Windows Help.
ID_CONTEXT_HELP Responds to SHIFT+F1 by putting the application into Help mode.
ID_DEFAULT_HELP Used when a specific help context cannot be found.

Notice that all of these commands are mapped to member functions of class CMDIFrameWnd (in the case of an MDI application) or CFrameWnd (in the case of an SDI application). Unlike most of the other commands you place into the message map, these have handler functions that are predefined by the class library. Making the message-map entry enables the command.

The application's accelerator table defines F1 for ID_HELP and SHIFT+F1 for ID_CONTEXT_HELP. You can change the keys used for these help functions by using Visual C++ to change the key values in the accelerator table. On Win32 systems, the operating system will generate the WM_HELP message when F1 is pressed.

When the user chooses a Help menu command, the framework calls the CWinApp::WinHelp member function. This action, in turn, starts the Windows Help program and passes context information to it.

See Also

Context-Sensitive Help in an MFC Application

Did you find this helpful?
(1500 characters remaining)