Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Getting ptr to IHTMLDocument2 from IHTMLElement?

Getting ptr to IHTMLDocument2 from IHTMLElement?

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    David Fleming
    wrote on last edited by
    #1

    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.

    M 1 Reply Last reply
    0
    • D David Fleming

      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.

      M Offline
      M Offline
      Marc Soleda
      wrote on last edited by
      #2

      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.

      D 1 Reply Last reply
      0
      • M Marc Soleda

        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.

        D Offline
        D Offline
        David Fleming
        wrote on last edited by
        #3

        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.

        M 1 Reply Last reply
        0
        • D David Fleming

          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.

          M Offline
          M Offline
          Marc Soleda
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups