In VC, let the dynamically created ActiveX Control respond to Windows messages.
Author: Unknown Source: moonlight software station time: moonlight software Station
-
When we dynamically create ActiveX controls through cwnd: createcontrol (), Windows messages are not sent to the control class derived from cwnd. For example, even if we create a handle for the wm_killfocus message, this handle will not be called. (Try again if you don't believe it :))
When this problem occurs, cwnd: createcontrol () does not subclass the hwnd of my control.
Knowing the cause is not difficult to solve. We only need to subclass the control after it is created. You can perform the following steps:
1. Of course, it is to add controls, which can be the C ++ class of controls.
2. Create a control class to declare a member variable. This member variable is a class pointer object.
3. Add:
// {Afx_msg (cmyclass)
//} Afx_msg
Declare_message_map ()
Cmyclass is the actual class name.
4. Add the following content under the # include section of the CPP file of the Inclusion class:
Begin_message_map (cmyclass, cwnd)
// {Afx_msg_map (cmyclass)
//} Afx_msg_map
End_message_map ()
5. Delete the. CLW file under the project directory, open classwizard in the project, select Yes first, and select Add all.
6. Now you can use classwizard to add message ing and processing functions for the control inclusion class.
After completing these modifications, you must create a control and subclass it. The following is an example:
Void csdiapp2view: oninitialupdate ()
{
Cview: oninitialupdate ();
M_pflexgrid = new cmsflexgrid;
crect rect;
getclientrect (& rect);
m_pflexgrid-> Create (null, ws_child | ws_visible, rect, this, idc_flexgrid);
hwnd = m_pflexgrid-> detach ();
m_pflexgrid-> subclasswindow (hwnd );
}< br>