2011-06-08 94 views

回答

0

使用IE9和本地C++ BHO(ATL),我沒有問題得到onQuit事件 我BHO從IdispEventImpl派生,並在SINK_MAP我指定的DISPID_ONQUIT事件:

class ATL_NO_VTABLE CMyBho 
    :public CComObjectRootEx<CComSingleThreadModel> 
    ... 
    ,IObjectWithSiteImpl<CMyBho> 
    ,IDispEventImpl<1, CMyBho, &DIID_DWebBrowserEvents2, &LIBID_SHDocVw, 1, 1> 
{ 
    ... 
    BEGIN_SINK_MAP(CMyBho) 
     SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_ONQUIT, onQuit) 
    END_SINK_MAP() 
    ... 
    STDMETHODCALLTYPE onQuit(); 
    ... 
    STDMETHOD(SetSite)(IUnknown* unkSite) { 
     CComQIPtr<IServiceProvider> ifServiceProvider(unkSite); 
     CComPtr<IWebBrowser2> ifBrz2; 
     ifServiceProvider->QueryService(SID_SWebBrowserAPP, IID_IWebBrowser2, 
             (void**)&ifBrz2); 
     this->DispEventAdvise(ifBrz2); 
    } 
} 

說一切,我知道這是本地代碼(而不是C#),這是IE9--但也許它會給你一個提示,說明你的C#實現需要做什麼。如果您想要完整的源代碼或需要更多幫助,請發送備註或評論。

0

OnQuit在IE11下運行得非常好。

處理程序:

public void OnQuit() 
{ 
    logger.Debug("Entered OnQuit"); 
} 

接線:

int IObjectWithSite.SetSite(object site) 
{  
    if (site != null) 
    { 
     mainWindowBrowser = (WebBrowser)site; 
     mainWindowBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); 
     mainWindowBrowser.OnQuit += new DWebBrowserEvents2_OnQuitEventHandler(this.OnQuit); 
    } 
    else 
    { 
     mainWindowBrowser.DocumentComplete -= new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete); 
     mainWindowBrowser.OnQuit -= new DWebBrowserEvents2_OnQuitEventHandler(this.OnQuit); 
     mainWindowBrowser = null; 
    } 
    return 0; 
} 
相關問題