Detect scrolling in WebPage from IE extension

早过忘川 提交于 2019-12-11 10:02:34

问题


I'm creating an IE extension (using VS2008, C++) that needs to react to scrollbar events in IE. I'm using BHO for that and I have access to IWebBrowser2 element, IHTMLDocument2 element and HWND of the parent window. I can't figure out how to access the scrollbars. I have seen codes that allows me to handle the scrollbar once I have access to them, but not how to get the scrollbar objects (or are they child window of the IE window?) themselves. Any ideas?


回答1:


MSHTML renders its own scrollbars instead of using the native system controls. That's why you can apply CSS rules to them.

What I would try is:

  1. QueryInterface() the IHTMLDocument2 object for IHTMLElement.
  2. QueryInterface() that for IConnectionPointContainer.
  3. Then call IConnectionPointContainer::FindConnectionPoint(DIID_HTMLElementEvents2).
  4. Implement IDispatch::Invoke() and you should get the OnScroll event when someone scrolls the document.
  5. Rinse and repeat for sub-frames.



回答2:


SInce I have IDispatchImpl already implemented, I'm guessing I would have to override the ATL implementation of the IDispatch::Invoke method to handle events. IS it correct? If that's the case and I have sink entries with DIID_DWebBrowserEvents2, how would that be affected? Here's how my class looks like:

class ATL_NO_VTABLE CHelloWorldBHO :
    public CComObjectRootEx<CComSingleThreadModel>,
    public CComCoClass<CHelloWorldBHO, &CLSID_HelloWorldBHO>,
    public IObjectWithSiteImpl<CHelloWorldBHO>,
    public IDispatchImpl<IHelloWorldBHO, &IID_IHelloWorldBHO, &LIBID_HelloWorldLib, /*wMajor =*/ 1, /*wMinor =*/ 0>,
    public IDispEventImpl<1, CHelloWorldBHO, &DIID_DWebBrowserEvents2, &LIBID_SHDocVw, 1, 1>
{
.
.
.
BEGIN_SINK_MAP(CHelloWorldBHO)
     SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_DOCUMENTCOMPLETE, OnDocumentComplete)
     SINK_ENTRY_EX(1, DIID_DWebBrowserEvents2, DISPID_BEFORENAVIGATE2, BeforeNavigate2)//Handle BeforeNavigate2
END_SINK_MAP()
.
.
.
}

Thanks

Edit: I discovered that when Invoke is Overwritten, OnDOcumentCOmplete is never called. How do I get around this?




回答3:


See this thread for the answer. My problem and the correct answer has been described properly here.



来源:https://stackoverflow.com/questions/1071644/detect-scrolling-in-webpage-from-ie-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!