Example Ex19b: Help Command Processing
Ex19b is based on example Ex18d from Chapter 18. It's a two-view MDI application with view-specific help added. Each of the two view classes has an OnCommandHelp message handler to process F1 help requests and an OnHelpHitTest message handler to process Shift+F1 help requests.
Header Requirements
The compiler recognizes help-specific identifiers only if the following #include statement is present:
#include <afxpriv.h>
In Ex19b, the statement is in the

CStringView
The modified string view in

afx_msg LRESULT OnCommandHelp(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnHelpHitTest(WPARAM wParam, LPARAM lParam);
Here are the message map entries in

ON_MESSAGE(WM_COMMANDHELP, OnCommandHelp)
ON_MESSAGE(WM_HELPHITTEST, OnHelpHitTest)
The OnCommandHelp message handler member function in

LRESULT CStringView::OnCommandHelp(WPARAM wParam, LPARAM lParam)
{
if (lParam == 0) { // context not already determined
lParam = HID_BASE_RESOURCE + IDR_STRINGVIEW;
}
AfxGetApp()->WinHelp(lParam);
return TRUE;
}
Finally, the OnHelpHitTest member function handles Shift+F1 help, as shown here:
LRESULT CStringView::OnHelpHitTest(WPARAM wParam, LPARAM lParam)
{
return HID_BASE_RESOURCE + IDR_STRINGVIEW;
}
In a more complex application, you might want OnHelpHitTest to set the help context ID based on the mouse cursor position.
CHexView
The CHexView class processes help requests the same way as the CStringView class does. Following is the necessary header code in

afx_msg LRESULT OnCommandHelp(WPARAM wParam, LPARAM lParam);
afx_msg LRESULT OnHelpHitTest(WPARAM wParam, LPARAM lParam);
Here are the message map entries in

ON_MESSAGE(WM_COMMANDHELP, OnCommandHelp)
ON_MESSAGE(WM_HELPHITTEST, OnHelpHitTest)
And here is the implementation code in

LRESULT CHexView::OnCommandHelp(WPARAM wParam, LPARAM lParam)
{
if (lParam == 0) { // context not already determined
lParam = HID_BASE_RESOURCE + IDR_HEXVIEW;
}
AfxGetApp()->WinHelp(lParam);
return TRUE;
}
LRESULT CHexView::OnHelpHitTest(WPARAM wParam, LPARAM lParam)
{
return HID_BASE_RESOURCE + IDR_HEXVIEW;
}
Resource Requirements
Two new symbols were added to the project's

Symbol | Value | Help Context ID | Value |
---|---|---|---|
IDR_STRINGVIEW | 101 | HIDR_STRINGVIEW | 0x20065 |
IDR_HEXVIEW | 102 | HIDR_HEXVIEW | 0x20066 |
Help File Requirements
Two topics were added to the


The generated

// Commands (ID_* and IDM_*)
HID_WINDOW_NEWHEXWINDOW 0x10082
HID_WINDOW_NEWSTRINGWINDOW 0x10083
// Prompts (IDP_*)
HIDP_OLE_INIT_FAILED 0x30064
// Resources (IDR_*)
HIDR_MANIFEST 0x20001
HIDR_MAINFRAME 0x20080
HIDR_Ex19bTYPE 0x20081
HIDR_STRINGVIEW 0x20065
HIDR_HEXVIEW 0x20066
// Dialogs (IDD_*)
HIDD_ABOUTBOX 0x20064
// Frame Controls (IDW_*)
Testing the Ex19b Application
To test the application, open a string child window and a hexadecimal child window. Test the action of F1 help and Shift+F1 help within those windows.