把用delphi6开发的activex嵌在某个页面中,我能不能在activex里得知IE被关闭(Alt+F4这种方法关闭的).找了好久没找到,请各位帮忙下。

解决方案 »

  1.   

    在控件里面获得顶层窗口的IWebBrowser指针之后捕获DWebBrowserEvent2::Quit事件。
      

  2.   

    to  jiangsheng(蒋晟.MSMVP2004Jan)
    IWebBrowser指针怎么获得?又怎么捕获DWebBrowserEvent2::Quit事件?
    谢谢
      

  3.   

    http://support.microsoft.com/kb/257717
    http://support.microsoft.com/default.aspx?scid=kb;en-us;311284
      

  4.   

    to  jiangsheng(蒋晟.MSMVP2004Jan)
    能给我个简单的例子吗?看了那些,我还不是很明白。
    要不你留个MSN什么的,可以吗?
      

  5.   

    to  jiangsheng(蒋晟.MSMVP2004Jan)
    能再指点下吗?
      

  6.   

    sample code uses C++ and MFC
    class CAutomationDlg : public CDialog
    {
    ......
    CComQIPtr<IWebBrowser2> m_pWebBrowser2;
    DWORD m_dwCookie;
    BOOL m_bOwnIE;
    afx_msg void DocumentComplete(IDispatch *pDisp,VARIANT *URL);
    afx_msg void OnQuit();
    DECLARE_DISPATCH_MAP();
    };
    BEGIN_DISPATCH_MAP(CAutomationDlg, CDialog)
    DISP_FUNCTION_ID(CAutomationDlg, "OnQuit",DISPID_ONQUIT,OnQuit,VT_EMPTY, VTS_NONE)
    DISP_FUNCTION_ID(CAutomationDlg, "DocumentComplete",DISPID_DOCUMENTCOMPLETE,DocumentComplete,
     VT_EMPTY, VTS_DISPATCH VTS_PVARIANT)
    ...
    END_DISPATCH_MAP()void CAutomationDlg::AdviseSinkIE()
    {
    if(m_pWebBrowser2)
    {
    LPUNKNOWN pUnkSink = GetIDispatch(FALSE);
    AfxConnectionAdvise((LPUNKNOWN)m_pWebBrowser2, 
    DIID_DWebBrowserEvents2,pUnkSink,FALSE,&m_dwCookie); 
    }
    }
    void CAutomationDlg::UnadvisesinkIE()
    {
    if(m_dwCookie != 0&&m_pWebBrowser2!=NULL)
    {
    LPUNKNOWN pUnkSink = GetIDispatch(FALSE);
    AfxConnectionUnadvise((LPUNKNOWN)m_pWebBrowser2, DIID_DWebBrowserEvents2, pUnkSink, FALSE, m_dwCookie);
    m_dwCookie = 0;
    }
    }void CAutomationDlg::CreateNewShellWindow(BOOL bIE)
    {
    if(!UpdateData())return;
    //Detach the previous instance
    if(m_pWebBrowser2)
    {
    if(m_bOwnIE)
    {
    m_pWebBrowser2->Quit();
    m_bOwnIE=FALSE;
    }
    UnadvisesinkIE();
    m_pWebBrowser2=(LPUNKNOWN)NULL;
    }
    if(bIE)
    {
    // create a new IE instance and show it 
    m_pWebBrowser2.CoCreateInstance(CLSID_InternetExplorer);
    m_bOwnIE=TRUE;
    HRESULT hr;
    hr = m_pWebBrowser2->put_StatusBar(VARIANT_TRUE);
    hr = m_pWebBrowser2->put_ToolBar(VARIANT_TRUE);
    hr = m_pWebBrowser2->put_MenuBar(VARIANT_TRUE);
    hr = m_pWebBrowser2->put_Visible(VARIANT_TRUE);
    //sink for the Quit and DocumentComplete events
    AdviseSinkIE();
    NavigateToSamplePage(bIE);
    }...void CAutomationDlg::OnQuit()
    {
    //detach to avoid AV caused by invalid reference.
    if(m_pWebBrowser2)
    {
    UnadvisesinkIE();
    m_pWebBrowser2=(LPUNKNOWN)NULL;
    }
    }