WinHelp is called two times when you press F1 in an AppWizard-generated MFC application (139696)
The information in this article applies to:
- The Microsoft Foundation Classes (MFC), when used with:
- Microsoft Visual C++, 32-bit Editions 4.0
- Microsoft Visual C++, 32-bit Editions 4.1
- Microsoft Visual C++, 32-bit Enterprise Edition 4.2
- Microsoft Visual C++, 32-bit Enterprise Edition 5.0
- Microsoft Visual C++, 32-bit Enterprise Edition 6.0
- Microsoft Visual C++, 32-bit Professional Edition 4.2
- Microsoft Visual C++, 32-bit Professional Edition 5.0
- Microsoft Visual C++, 32-bit Professional Edition 6.0
- Microsoft Visual C++, 32-bit Learning Edition 6.0
This article was previously published under Q139696 SYMPTOMS
In an AppWizard-generated MFC application with context-sensitive help
support, pressing F1 causes WinHelp to be called twice. In most cases, the
application displays the correct help topic. In some cases, however, the
application displays the wrong help topic. This can happen when the user
clicks a toolbar button and presses F1 before releasing the mouse button.
This occurs only under the operating systems that support the WM_HELP
message, such as Windows 95 or Windows NT 4.0.
CAUSE
CWnd in MFC 4.0 has a handler for WM_HELP that sends a WM_COMMAND with an
id of ID_HELP. The AppWizard-generated application also has an accelerator
for the F1 key. Both result in WinHelp being called.
RESOLUTION
There are two possible resolutions: - Remove the accelerator table entry for F1. The problem with this is that
F1 help will no longer work in Windows NT 3.5 or Win32s because these
operating systems do not support the WM_HELP message.
-or-
- Override CWinApp::PreTranslateMessage and cancel routing of the F1 key
down message as follows:
static BOOL AFXAPI IsHelpKey(LPMSG lpMsg)
// Return TRUE only for non-repeat F1 keydowns.
{
return lpMsg->message == WM_KEYDOWN &&
#ifndef _MAC
lpMsg->wParam == VK_F1 &&
#else
lpMsg->wParam == VK_HELP &&
#endif
!(HIWORD(lpMsg->lParam) & KF_REPEAT) &&
GetKeyState(VK_SHIFT) >= 0 &&
GetKeyState(VK_CONTROL) >= 0 &&
GetKeyState(VK_MENU) >= 0;
}
BOOL CHelpStuffApp::PreTranslateMessage(MSG* pMsg)
{
// If on a system that supports WM_HELP, cancel
// routing of F1 key.
DWORD dwVersion = ::GetVersion();
UINT nWinVer = (LOBYTE(dwVersion) << 8) + HIBYTE(dwVersion);
if (nWinVer >= 0x333 && IsHelpKey(pMsg))
return TRUE;
return CWinApp::PreTranslateMessage(pMsg);
}
STATUSMicrosoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.
Modification Type: | Major | Last Reviewed: | 5/26/2005 |
---|
Keywords: | kbprb kbtshoot kbBug kbcode kbCSHelp kbNoUpdate KB139696 kbAudDeveloper |
---|
|