2 eagle lzt eagle_lzt 于 2013.06.29 16:55 提问

ie bho 插件:如何获得浏览器滚动条变化事件

我已经写了一个简单的bho。

目的是知道浏览器的滚动条是否滚动。

DISPID_DOCUMENTCOMPLETE事件可以获取。
DISPID_HTMLWINDOWEVENTS2_ONSCROLL 事件不能获得。

class部分:

class ATL_NO_VTABLE Chellobho :
public CComObjectRootEx,
public CComCoClass,
public IObjectWithSiteImpl,
public IDispatchImpl,
public IDispEventImpl,
public IDispEventImpl

注册部分:
BEGIN_SINK_MAP(Chellobho)
SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_DOCUMENTCOMPLETE, OnDocumentComplete)
SINK_ENTRY_EX(3, DIID_HTMLWindowEvents2, DISPID_HTMLWINDOWEVENTS2_ONSCROLL, OnScroll)
END_SINK_MAP()

SetSite函数:
STDMETHODIMP Chellobho::SetSite(IUnknown* pUnkSite)
{
MessageBox( NULL, L"SetSite", L"SetSite", MB_OK );
IDispatch *pDisp2;
CComQIPtr spHTML2;
CComPtr htmlWindow;

if (pUnkSite != NULL)
{
    // Cache the pointer to IWebBrowser2.
    HRESULT hr = pUnkSite->QueryInterface(IID_IWebBrowser2, (void **)&m_spWebBrowser);
    if (SUCCEEDED(hr))
    {
        hr = IDispEventSimpleImpl<1,Chellobho,&DIID_DWebBrowserEvents2>::DispEventAdvise(m_spWebBrowser);   
        hr = m_spWebBrowser->get_Document(&pDisp2);

        //test
        spHTML2 = pDisp2;
        if ( spHTML2 ) {
            spHTML2->get_parentWindow(&htmlWindow);
            hr = IDispEventSimpleImpl<3,Chellobho,&DIID_HTMLWindowEvents2>::DispEventAdvise(htmlWindow);
            if (SUCCEEDED(hr))
            {
                m_fAdvised = TRUE;
            }
        }
    }
}
else
{
    // Unregister event sink.
    if (m_fAdvised)
    {
        IDispEventSimpleImpl<1,Chellobho,&DIID_DWebBrowserEvents2>::DispEventUnadvise(m_spWebBrowser);
        IDispEventSimpleImpl<3,Chellobho,&DIID_HTMLWindowEvents2>::DispEventUnadvise(htmlWindow);
        m_fAdvised = FALSE;
    }

    // Release cached pointers and other resources here.
    m_spWebBrowser.Release();
}

// Call base class implementation.
return IObjectWithSiteImpl<Chellobho>::SetSite(pUnkSite);

}

1个回答

oyljerry
oyljerry   Ds   Rxr 2015.01.03 11:07

通过Javascript去获取。然后调用C++来通知

Csdn user default icon
上传中...
上传图片
插入图片