Getting ptr to IHTMLDocument2 from IHTMLElement?
-
This theoretical snippet of code would be within the PreHandleEvent function of my MSHTML EditDesigner object (IHTMLEventObj* pIEventObj is one of the parameters).
IHTMLDocument2* pDoc; IHTMLElement* pElem; IDispatch* pDisp; pIEventObj->get_srcElement(&pElem); //this gets me a pointer to an IHTMLElement object pElem->get_document(&pDisp); //this supposedly gets me a pointer to the IHTMLDocument2
OK, so I supposedly have a pointer to the Document. But what I don't understand is how do I then use that IDispatch pointer to invoke the methods available through the IHTMLDocument2 object? Specifically, I'm trying to use the IHTMLDocument2 object's "elementFromPoint" method to retrieve IHTMLElement objects from specific points within the client area. I'm clearly missing some cast that I need to do. -
This theoretical snippet of code would be within the PreHandleEvent function of my MSHTML EditDesigner object (IHTMLEventObj* pIEventObj is one of the parameters).
IHTMLDocument2* pDoc; IHTMLElement* pElem; IDispatch* pDisp; pIEventObj->get_srcElement(&pElem); //this gets me a pointer to an IHTMLElement object pElem->get_document(&pDisp); //this supposedly gets me a pointer to the IHTMLDocument2
OK, so I supposedly have a pointer to the Document. But what I don't understand is how do I then use that IDispatch pointer to invoke the methods available through the IHTMLDocument2 object? Specifically, I'm trying to use the IHTMLDocument2 object's "elementFromPoint" method to retrieve IHTMLElement objects from specific points within the client area. I'm clearly missing some cast that I need to do.David Fleming wrote: OK, so I supposedly have a pointer to the Document. But what I don't understand is how do I then use that IDispatch pointer to invoke the methods available through the IHTMLDocument2 object?
IDispatchPtr pDisp = this->GetHtmlDocument(); IHTMLDocument2* pDoc; hr = pDisp->QueryInterface( __uuidof( IHTMLDocument2 ), (void**)&pDoc );
Now you have an interface to the HTML document and then you can use elementFromPoint[^] Marc Soleda. ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits. -
David Fleming wrote: OK, so I supposedly have a pointer to the Document. But what I don't understand is how do I then use that IDispatch pointer to invoke the methods available through the IHTMLDocument2 object?
IDispatchPtr pDisp = this->GetHtmlDocument(); IHTMLDocument2* pDoc; hr = pDisp->QueryInterface( __uuidof( IHTMLDocument2 ), (void**)&pDoc );
Now you have an interface to the HTML document and then you can use elementFromPoint[^] Marc Soleda. ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.Excellent. Thanks. But now I have another question. What I'm trying to do is implement a HTMLEditDesigner and trap keyboard input in the TranslateAccelerator event. If the user is moving into an element that is "off limits", I want to cancel it. The elementFromPoint() method is using the mouse coordinates (which I did not realize upon reading it, but... duh!). My question is: let's say the user is on a line below a restricted line and presses the up arrow key (thus moving into a restricted area -- or at least attempting to); I trap the keydown event in the TranslateAccelerator callback, but it seems to me that the element I get (using pIEventObj->getSrcElement) always has BODY as the tag (using pElement->getTagName), even if the cursor is moving into a BOLD, DIV, etc. What's the snag or trick? Why can't I seem to get the actual tag? BTW, it works fine on mouse clicks trapped in the PretranslateEvent callback, but this callback does not seem to trap arrow key presses (my understanding is that that is what TranslateAccelerator is for, and supposedly it is called before PretranslateEvent). Thanks.
-
Excellent. Thanks. But now I have another question. What I'm trying to do is implement a HTMLEditDesigner and trap keyboard input in the TranslateAccelerator event. If the user is moving into an element that is "off limits", I want to cancel it. The elementFromPoint() method is using the mouse coordinates (which I did not realize upon reading it, but... duh!). My question is: let's say the user is on a line below a restricted line and presses the up arrow key (thus moving into a restricted area -- or at least attempting to); I trap the keydown event in the TranslateAccelerator callback, but it seems to me that the element I get (using pIEventObj->getSrcElement) always has BODY as the tag (using pElement->getTagName), even if the cursor is moving into a BOLD, DIV, etc. What's the snag or trick? Why can't I seem to get the actual tag? BTW, it works fine on mouse clicks trapped in the PretranslateEvent callback, but this callback does not seem to trap arrow key presses (my understanding is that that is what TranslateAccelerator is for, and supposedly it is called before PretranslateEvent). Thanks.
I've never used the IHTMLEditDesigner interface. When I need to provide DHTML into a CHtmlView I use JavaScript inside the DHTML code and search for a certain tag id (get_id). In the case you've exposed, I agree with you that get_srcElement it'd be the correct method to know the event source. Have you trusted that TranslateAccelerator only fires one time for each keybord hit? I mean if you validate the DISPID (DISPID_HTMLELEMENTEVENTS2) to be the correct one. Marc Soleda. ... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.