PRB: Messages Not Received by Dynamically Created ControlLast reviewed: July 10, 1997Article ID: Q156051 |
4.00 4.10 4.20
WINDOWS
kbprg kbprb
The information in this article applies to:
SYMPTOMSWhen you create ActiveX Controls dynamically via CWnd::CreateControl(), Windows messages are not sent to your CWnd-derived class. For example, if you create a handler for WM_KILLFOCUS, it is not called.
CAUSECWnd::CreateControl() doesn't subclass the HWND associated with the control.
STATUSThis problem is by design.
WORKAROUNDAs a workaround, use a CFormView or CDialog and add the control to the dialog box resource at design time via the Resource Editor. You can then add a member variable using Class Wizard. The C++ class wrapper created by Component Gallery doesn't have a message map, so you must add this manually. The following steps illustrates how to insert an ActiveX Control and create a message handler for it:
MORE INFORMATIONWhen you insert a control via Component Gallery, the C++ class wrapper has Create() functions that also call CWnd::CreateControl(). The workaround above works because adding a member variable adds a call to DDX_Control(). DDX_Control() calls SubclassWindow() for you. If you try to call SubclassWindow() after calling CreateControl(), you will get several ASSERTs, because the HWND associated with the control has already been attached to a different MFC class (CWnd member of COleControlSite).
|
KBCategory: kbprg kbprb
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |