问题描述
我正在VisualC ++ 10中使用ATL托管浏览器控件.我的代码类似于以下示例: http://msdn.microsoft.com/zh-CN/library/9d0714y1(v=vs.80).aspx
I am using ATL in VisualC++10 to host browser control.My code is similar to this example: http://msdn.microsoft.com/en-us/library/9d0714y1(v=vs.80).aspx
区别是我有主窗口,然后子窗口托管了浏览器控件.2分钟后,我必须关闭浏览器,完全杀死浏览器activeX,但是此子窗口应该还活着并执行其他操作.但是以某种方式,该浏览器控件仍然停留在该位置,我可以看到滚动条或其他内容.
Difference is I have main window and then child window hosts the browser control.After 2 minutes i have to close the browser completely kill the browser activeX but this child window should be alive and do something else. But somehow this browser control still stays there, i can either see scrollbars or something..
我也尝试过通过在现有子窗口中创建子窗口,然后在关闭浏览器时销毁该子窗口的子窗口,但仍然无法正常工作!
I have also tried by creating child window to an existing child window, and at the time of closing browser I then destroy this child of a child - but still it does not work!
这就是我要关闭的方式:
This is how I am closing:
CLOSE()
{
m_spIWebBrowser2->Navigate(bstrURL, &vEmpty, &vEmpty, &vEmpty, &vEmpty);
m_spIWebBrowser2->Stop();
m_spIWebBrowser2->put_Visible(VARIANT_FALSE);
m_spIWebBrowser2->Quit();
DestroyWindow(m_wndChild.m_hWnd);
}
谢谢!
推荐答案
关闭webbrowser控件时,访问冲突"有很多问题,这些是对我有用的步骤:
I had many problems with "access violation" when closing webbrowser control, these are the steps that worked for me:
- 不建议任何以前建议的事件(在我的情况下为DWebBrowserEvents2).
- 如果您已附加了单击事件,请按如下所示取消附加它们:
_variant_t v; v.vt = VT_DISPATCH; v.pdispVal = 0; IHTMLDocument2->put_onclick(v);
-
IWebBrowser2->Stop()
-
IWebBrowser2->ExecWB(OLECMDID_CLOSE, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0)
-通过window.external.CloseWindow()关闭浏览器窗口时,我有未处理的异常,OLECMDID_CLOSE已修复. -
IWebBrowser2->put_Visible(VARIANT_FALSE)
-
IWebBrowser2->Release()
-
IOleInPlaceObject->InPlaceDeactivate()
-
IOleInPlaceObject->Release()
-
IOleObject->DoVerb(OLEIVERB_HIDE, NULL, IOleClientSite, 0, windowHandle_, NULL)
-
IOleObject->Close(OLECLOSE_NOSAVE)
-
OleSetContainedObject(IOleObject, FALSE)
-
IOleObject->SetClientSite(NULL)
-
CoDisconnectObject(IOleObject, 0)
-
IOleObject->Release()
- Unadvise any previously advised events (DWebBrowserEvents2 in my case).
- If you've attached click events unattach them like this:
_variant_t v; v.vt = VT_DISPATCH; v.pdispVal = 0; IHTMLDocument2->put_onclick(v);
IWebBrowser2->Stop()
IWebBrowser2->ExecWB(OLECMDID_CLOSE, OLECMDEXECOPT_DONTPROMPTUSER, 0, 0)
- when closing browser window through window.external.CloseWindow() I had unhandled exceptions and OLECMDID_CLOSE fixed it.IWebBrowser2->put_Visible(VARIANT_FALSE)
IWebBrowser2->Release()
IOleInPlaceObject->InPlaceDeactivate()
IOleInPlaceObject->Release()
IOleObject->DoVerb(OLEIVERB_HIDE, NULL, IOleClientSite, 0, windowHandle_, NULL)
IOleObject->Close(OLECLOSE_NOSAVE)
OleSetContainedObject(IOleObject, FALSE)
IOleObject->SetClientSite(NULL)
CoDisconnectObject(IOleObject, 0)
IOleObject->Release()
IWebBrowser2->Quit()
不应为WebBrowser控件(CLSID_WebBrowser)调用,它仅应用于Internet Explorer对象(CLSID_InternetExplorer).
IWebBrowser2->Quit()
should not be called for WebBrowser control (CLSID_WebBrowser), it is intended only for Internet Explorer object (CLSID_InternetExplorer).
为什么要这么难?
这篇关于如何彻底销毁WebBrowser控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!