FIX: Cannot Receive WM_HELP for a Subclassed ControlLast reviewed: September 19, 1997Article ID: Q145865 |
4.00
WINDOWS NT
kbprg kbbuglist kbfixlist
The information in this article applies to:
SYMPTOMSWM_HELP is not received by the parent window of a control that has been subclassed by MFC.
CAUSECWnd, the base class of all MFC windows, has a handler for WM_HELP. This handler intercepts the WM_HELP message in the control itself and thus the message will not be sent to the parent window as expected.
RESOLUTIONSubclass all the controls in the CDialog, CFormView, CPropertyPage, or other CWnd derived class that contains the controls which have been subclassed by MFC. The "Sample Code" below iterates through the child windows of a given parent window and checks their WindowProc. If their WindowProc is AfxWndProc (MFC's WindowProc), it subclasses the controls again so that another window procedure is called first. In this WindowProc, we check for WM_HELP and call DefWindowProc instead of passing the message to MFC's AfxWndProc.
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual C++ 4.1.
MORE INFORMATIONCWnd::OnHelpInfo (handler for WM_HELP) sends a WM_COMMAND with ID_HELP to the application's main frame window. This message can be intercepted in the main frame, but at this point, the HELPINFO structure has been lost. The main frame will not have any way of determining which help context should be used.
REFERENCES
FixHelp(this); Sample Code
/* Compile options needed: Default */ //////////////////////////////////////////////////////////////////////// // FixHelp.h - Include this file in your dialog's or form view's .CPP void FixHelp(CWnd* pWnd); // Call this from your OnInitDialog() for a // dialog or OnInitialUpdate() for a CFormView //////////////////////////////////////////////////////////////////////// // FixHelp.cpp - Insert this file into your project #include "stdafx.h"LRESULT CALLBACK ControlFixProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); void FixHelp(CWnd* pWnd){ // search all child windows. If their window proc // is AfxWndProc, then subclass with our window proc CWnd* pWndChild = pWnd->GetWindow(GW_CHILD); while(pWndChild != NULL) { if (GetWindowLong(pWndChild->GetSafeHwnd(), GWL_WNDPROC) == (LONG)AfxWndProc) { SetWindowLong(pWndChild->GetSafeHwnd(), GWL_WNDPROC, (LONG)ControlFixProc); } pWndChild = pWndChild->GetWindow(GW_HWNDNEXT); }} LRESULT CALLBACK ControlFixProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { if (uMsg == WM_HELP) { // bypass MFC's handler, message will be sent to parent return DefWindowProc(hwnd, uMsg, wParam, lParam); } return AfxWndProc(hwnd,uMsg,wParam,lParam);}
//////////////////////////////////////////////////////////////////////// |
Additional reference words: 4.00 4.10 SubclassWindow SubclassDlgItem
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |