ActiveX control Embed a web page, close the problem of webpage time

zhaozj2021-02-16  82

http://community.9cbs.net/expert/topic/3160/3160265.xml?temp =.5274317

There is a question that you said, generally said that it is a pointer problem, it is very likely that there is no safety interpretation.

You can follow, if you arrive in FinalRelease, if you didn't come here, you need you in the IoleObject_Close Release interface (the interface cross-reference cannot be released), and finally achieve the purpose of resource security.

Corresponding to ATL

IoleObject_setClientSiteioleObject_close

When covering these 2 methods, pay attention to adjust the corresponding method of ccomcontrolbase ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -------------------------------------------------- -------

(Transfer) Problem: The WM_CREATE and WM_DESTORY processing functions of the ActiveX control in IE are not called

Overview

IE Create an ActiveX control when the control is first visible, calling the WM_CREATE processing code. There is no call code for WM_Destory when leaving or closing the page. There is also the same problem when the control size is 0 * 0. If you have access to the window or sub-window of the control before this (for example, Window.onLoad Event), it will not succeed.

the reason

Most ActiveX control frameworks, such as MFC and ATL, create controls when activating ActiveX controls locally. Based on performance considerations until the control is visible for the first time, IE activates the ActiveX control. This contains web pages containing ActiveX controls more rapidly, and less memory. This also causes the WM_CREATE processing code of the ActiveX control until the control is first visible.

If the control supports non-window activation, IE creates controls in a non-window activation, so that the control of the control WM_Destory processing code will not be called when leaving or closing the page.

solution

IE The IoleObject :: SetClientSite's implementation of the ActiveX control in the page is called when the page is initialized or exit, regardless of whether the control is activated locally. At the time of the initialization page, the passing pointer is the host's IoleClient interface pointer, when leaving or closes the page, the pointer passed is an empty pointer. The status of the control can be determined according to this pointer and execute the initialization or clear code.

MFC

The implementation of the MFC on the IoleObject :: SetClientSite () contains calls to virtual functions Colecontrol :: OnsetClientSite (). At this time, it can determine whether the control is loaded or cleared according to whether the em_pclientsite is an empty pointer.

// CMYControl is derived from the Colecontrol.void CMYControl :: OnsetClientSite () {if (m_pclientsite) // Parent window and its size is not important because the control is automatically redraw and repositioning when the control is activated locally. Verify (CreateControlWindow (), CRECT (0, 0, 0, 0)); Else DestroyWindow (); Colecontrol :: OnsetClientSite ();

ATL

ATL's implementation of IoleObject :: SetClientSite () has an IoleClientSite type parameter (MFC saves this pointer to ColeControl :: m_pclients), and it is tested directly. At the same time, ATL does not reset the parent window of the control, so the control needs to be manually activated locally. // CMyControl derived CComControl STDMETHOD (SetClientSite) (IOleClientSite * pClientSite) {if (pClientSite) {RECT rc = {0,0,0,0}; // Do not have access to the container's window so just use the / . / desktop Window will be resized correctly during in-place // activation HWND hWnd = CreateControlWindow (:: GetDesktopWindow (), rc);. _ASSERT (hWnd);} else :: DestroyWindow (m_hWnd); return IOleObjectImpl :: SetClientSite ( pClientSite;

HRESULT InPlaceActivate (LONG iVerb, const RECT * prcPosRect) {// Get the container's window _ASSERT (m_spClientSite);. LPOLEINPLACESITE pInPlaceSite = NULL; HRESULT hr = m_spClientSite-> QueryInterface (IID_IOleInPlaceSite, (void **) & pInPlaceSite); _ASSERT (SUCCEEDED (hr) && pinPLACESite; hr = pinPARESite-> getWindow (& hparent); _assert (succeeded (hr) && hparent); pinPLACESIT-> Release (); // set Container Window As Our Parent Window SetParent ( Hparent);
return ccomcontrolbase :: inplaceActivate (iverb, prcposRect);
}

Steps to reproduce problems

Use the MFC or ATL to create an ActiveX control to add these two messages to use IE as a debugger reference

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

New Post(0)