In VC, let the dynamically created ActiveX Control respond to Windows messages

Source: Internet
Author: User

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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.