Overview
This is a very short article to show a solution for context sensitive help problem for a propertysheet embedded within the page of another propertysheet. The help command gets swallowed by the system and help is not shown.
While recently upgrading the help system for one of our applications from WinHelp to HTML help, we noticed that the context sensitive help of a propertysheet embedded in the page of another sheet was not being shown. After much tracing around through the MFC source and reading MSDN, I realized that when a propertysheet gets the WM_HELPINFO
message which is sent by ::IsDialogMessage()
, it is not processed correctly due to the sheet having the window style of WS_CHILD
.
The fix
Once I had identified the problem, the fix comes quite easily.
- Inherit your own class from
CPropertySheet
.
This class should be used to replace the existing embedded sheet object in your property page.
- Map the
WM_HELPINFO
message.
This is the message we need to map to fix the problem.
afx_msg BOOL OnHelpInfo(HELPINFO * pHelpInfo);
ON_WM_HELPINFO()
BOOL CPropertySheetEx::OnHelpInfo(HELPINFO* pHelpInfo)
{
BOOL ret = FALSE;
bool handled = false;
if (GetStyle() & WS_CHILD)
{
CWnd * pWnd = GetParent();
while (pWnd != NULL && pWnd->GetStyle() & WS_CHILD)
{
pWnd = pWnd->GetParent();
}
if (pWnd != NULL)
{
ret = GetParent()->GetParent()->SendMessage(WM_HELP,
0, (LPARAM)(pHelpInfo));
handled = true;
}
ASSERT(handled);
}
if (!handled)
{
ret = CPropertySheet::OnHelpInfo(pHelpInfo);
}
return ret;
}
And that's it, everything should now work correctly.