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

zhaozj2021-02-17  95

When we use CWnd :: CreateControl () Dynamically create an ActiveX control, Windows messages will not be sent to us to derive the control class by CWND. For example, even if we create a handle for the WM_KILLFOCUS message, this handle will not be called. (Don't believe you try :))

When this question is caused, CWnd :: CreateControl () does not make the HWnd subclass of me control.

I know the reason, it is not difficult to solve the problem. We only need to make it subcatenate after the control is created. You can achieve it by step:

1. Of course, add controls, mailed C inclusive classes for controls.

2. Retreat the creative member variable in the class of the control, which is the pointer object of the inclusive class.

3. Add: Add:

// {{AFX_MSG (CMYCLASS) / /}} AFX_MSGDECLARE_MESSAGE_MAP ()

CMYCLASS is the actual class name.

4. Add: below the #include section of the CPP file of the inclusive CPP file:

Begin_MESSAGE_MAP (CMYCLASS, CWND) // {{AFX_MSG_MAP (CMYCLASS) / /}} AFX_MSG_MAPEND_MESSAGE_MAP ()

5. Delete the .clw file under the project directory, open ClassWizard in the project, first select Yes, select Add All.

6. Now you can use ClassWizard to add message mapping and handle functions for the control tolerance class.

After completing these modifications, you must create a control and make it subcatenate, and below 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 hWnd = m_pFlexGrid -> DETACH (); m_pflexgrid-> subclasswindow (hwnd);

转载请注明原文地址:https://www.9cbs.com/read-31522.html

New Post(0)