views:

267

answers:

3

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  A: 

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.
jeffamaphone
Thanks for your answer. Since I use ATL, I realised I could just have another implementation of IDispEventImpl in my class. Thanks though!
GotAmye
A: 

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?

GotAmye
A: 

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

GotAmye