Article ID: 191118
Article Last Modified on 6/9/2005
189453 How To Prepare HTML Help Files for Context-Sensitive Help
186907 How To Set Up Visual C++ to Use the HTML Help API
static const DWORD aMenuHelpIDs[] =
{
ID_FILE_NEW, IDH_FILE_NEW ,
ID_FILE_OPEN, IDH_FILE_OPEN ,
ID_FILE_SAVE, IDH_FILE_SAVE ,
ID_EDIT_CUT, IDH_EDIT_CUT,
ID_EDIT_COPY, IDH_EDIT_COPY,
ID_EDIT_PASTE, IDH_EDIT_PASTE,
ID_FILE_PRINT, IDH_FILE_PRINT,
ID_APP_ABOUT, IDH_APP_ABOUT,
ID_FILE_PRINT_PREVIEW, IDH_FILE_PRINT_PREVIEW,
0, 0
};
In the previous example, each control ID is followed by its
corresponding help ID.
// Subtract 1 from the total number of ID pairs to account
// for the NULL pair at the end of the array.
DWORD numHelpIDs = (sizeof(aMenuHelpIDs)/sizeof(DWORD))/2 - 1
void CTestApp::WinHelp( DWORD dwData, UINT nCmd )
{
DWORD i;
switch (nCmd)
{
case HELP_CONTEXT:
// If it is a help context command, search for the
// control ID in the array.
for (i= 0; i < numHelpIDs*2; i+=2)
{
if (aMenuHelpIDs[i] == LOWORD (dwData) )
{
i++; // pass the help context id to HTMLHelp
HtmlHelp(m_pMainWnd->m_hWnd,"sample.chm",
HH_HELP_CONTEXT,aMenuHelpIDs[i]);
return;
}
}
// If the control ID cannot be found,
// display the default topic.
if (i == numHelpIDs*2)
HtmlHelp(m_pMainWnd->m_hWnd,"sample.chm",HH_DISPLAY_TOPIC,0);
break;
}
}Note In the previous example, Sample.chm must be in the same folder as
the MFC application project file because no path is specified.
virtual void WinHelp( DWORD dwData, UINT nCmd = HELP_CONTEXT );
#define IDH_FILE_NEW 1
#define IDH_FILE_OPEN 2
#define IDH_FILE_SAVE 3
#define IDH_EDIT_CUT 4
#define IDH_EDIT_COPY 5
#define IDH_EDIT_PASTE 6
#define IDH_FILE_PRINT 7
#define IDH_APP_ABOUT 8
#define IDH_FILE_PRINT_PREVIEW 9
LRESULT CMyView::OnHelpHitTest(WPARAM, LPARAM lParam)
{
ASSERT_VALID(this);
// Find the child window ID under mouse cursor
int nID = OnToolHitTest((DWORD)lParam, NULL);
if (nID != -1)
return HID_BASE_CONTROL+nID;
nID = GetDlgCtrlID();
return nID != 0 ? HID_BASE_CONTROL+nID : 0;
}Keywords: kbhowto kbapi kbprogramming kbcode KB191118