BUG: WinHelp Called Twice

Last reviewed: July 31, 1997
Article ID: Q139696
The information in this article applies to:
  • The Microsoft Foundation Classes (MFC) included with: - Microsoft Visual C++, 32-bit Edition, versions 4.0, 4.1, 4.2, 4.21 5.0

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 3.51.

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);
          }
    
    

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

Keywords          : MfcMisc vcbuglist400 vcbuglist500 kbprg kbbuglist
Technology        : kbMfc
Version           : 4.0 4.1 4.2 4.21 5.0
Platform          : NT WINDOWS


================================================================================


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 31, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.