How to monitor ie events via toolbar without mfc
-
I found only one article on codeproject is using CCmdTarget for finding sink for AfxConnectionAdvise((LPUNKNOWN)s_pFrameWB,DIID_DWebBrowserEvents2,pUnk,FALSE,dw); I know that I have to use interface DWebBrowserEvents2. But for which It requires CCmdTarget,which is mfc class. I am trying to monitor IE with help of toolbar, so I am using pure atl,com and not mfc.So what is alternative way to monitor events.I have IWebBrowser2 object in my hand.
|| ART OF LIVING ||
-
I found only one article on codeproject is using CCmdTarget for finding sink for AfxConnectionAdvise((LPUNKNOWN)s_pFrameWB,DIID_DWebBrowserEvents2,pUnk,FALSE,dw); I know that I have to use interface DWebBrowserEvents2. But for which It requires CCmdTarget,which is mfc class. I am trying to monitor IE with help of toolbar, so I am using pure atl,com and not mfc.So what is alternative way to monitor events.I have IWebBrowser2 object in my hand.
|| ART OF LIVING ||
To handle those events in ATL, you need to derive a class from IDispEventImpl and add a sink map handling the events you want. Here's some incomplete code that handles mouse over and mouse out events from a browser window embedded as a control:
class MyView : public CWindowImpl<MyView, CAxWindow>, public IDispEventImpl<1, MyView, &DIID_HTMLElementEvents2, &LIBID_MSHTML, 4, 0> { public: typedef IDispEventImpl<1, MyView, &DIID_HTMLElementEvents2, &LIBID_MSHTML, 4, 0> HTMLElementEventsSink; BEGIN_SINK_MAP(MyView) SINK_ENTRY_EX(1, DIID_HTMLElementEvents2, DISPID_HTMLELEMENTEVENTS_ONMOUSEOVER, OnMouseOver) SINK_ENTRY_EX(1, DIID_HTMLElementEvents2, DISPID_HTMLELEMENTEVENTS_ONMOUSEOUT, OnMouseOut) END_SINK_MAP() BEGIN_MSG_MAP_EX(MyView) MESSAGE_HANDLER(WM_CREATE, OnCreate) MESSAGE_HANDLER(WM_DESTROY, OnDestroy) END_MSG_MAP() private:
You'll need to call
HTMLElementEventsSink::DispEventAdvise
to tell IE that you want to handle the events, using an appropriate IDispatch pointer to say which objects events you want.