How to sink OnScroll event in IE using attachEvent or put_onscroll?

How to sink OnScroll event in IE using attachEvent or put_onscroll?

Post by brian.john » Sat, 14 Feb 2009 13:59:54


Hi, I'm having some trouble sinking the OnScroll event when attaching
to IE, using C++. I can connect to an already running copy of IE and
get the IWebBrowser2 interface. I can sink the browser events with the
following code:

BEGIN_DISPATCH_MAP(CIEHandler, CCmdTarget)
DISP_FUNCTION_ID(CIEHandler, "OnQuit",DISPID_ONQUIT,OnQuit,VT_EMPTY,
VTS_NONE)
...
END_DISPATCH_MAP()

BOOL CIEHandler::MyAdviseSink()
{
LPUNKNOWN pUnkSink = GetIDispatch(FALSE);
AfxConnectionAdvise((LPUNKNOWN)m_pWebBrowser2,
DIID_DWebBrowserEvents2, pUnkSink, FALSE, &m_dwCookie);

return TRUE;
}

But I cannot figure out how to sink the onscroll event
DISPID_HTMLWINDOWEVENTS_ONSCROLL. I've tried to set it using the
put_onscroll of IHTMLWindow2:

HRESULT IHTMLWindow2::put_onscroll(VARIANT v);

But I do not know how to set up the VARIANT to pass the function? I've
tried:

VARIANT var;
var.vt=VT_DISPATCH;
var.pdispVal=(IDispatch*)this;

Where my class is: class CIEHandler : public CCmdTarget

But that doesn't work. I've also tried to use the attachEvent of
IHTMLWindow3 but again I don't know how to setup the pDisp:

HRESULT attachEvent(
BSTR event,
IDispatch *pDisp,
VARIANT_BOOL *pfResult
);

where event is CComBSTR bstr_onscroll(L"onscroll");

Any help is greatly appreciated!
 
 
 

How to sink OnScroll event in IE using attachEvent or put_onscroll?

Post by Igor Tande » Sat, 14 Feb 2009 14:12:58


Same way, with AfxConnectionAdvise. The outgoing interface is
DIID_HTMLWindowEvents.


You can do it this way, too. You would need an IDispatch implementation
supporting a method with a DISPID of DISPID_VALUE.


You probably want to use CComTarget::GetIDispatch rather than a cast.
I'm not very well versed in MFC though.


Same way as for put_onscroll.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925