Re: Not able to receiving Mouse events in BHO using HTML document even
Microdev1 <Microdev1@discussions.microsoft.com> wrote:
I am new to ATL progrmming. Based on the material in web, I have been
able to write a BHO and successfully receive Web Browser events like
"Document Complete". But I am not able to receive any HTML Document
events. Here's what I am doing to receive HTML Document events -
1) Get IID_IHTMLDocument2 document object from Browser object
2) Get IHTMLElementCollection object from IID_IHTMLDocument2 document
object 3) For each object in IHTMLElementCollection object, query
IID_IHTMLElement object. (I am not able to compile the code if I try
to query "IID_IHTMLElement2")
4) Find connection point to IID_IHTMLElement object.
5) Advise the connection point to browser's document object.
// Find the connection point.
HRESULT hr = pCPC->FindConnectionPoint( DIID_HTMLElementEvents,
&pCP );
My guess is, this call fails. Perhaps surprisingly, almost no HTML
element supports HTMLElementEvents as a connection point. Instead, each
kind of elements has its own event interface. E.g. <a> element fires
HTMLAnchorEvents, <img> element fires HTMLImgEvents, and so on. All
these event interfaces are nearly identical.
Be aware that most HTML events (including mouse events) bubble. This
means that an event fires on the object it initially occured on, then on
its parent, then on parent's parent, and so on up the chain all the way
to document object. This, in turn, means that you don't usually need to
subscribe to events on every element individually: an event sink
attached to the document will get almost all events.
If you want to try that, the event interface for document is
HTMLDocumentEvents.
--
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