Web Analytics Made Easy -
StatCounter controlling IE - scrolling down a window - CodingForum

Announcement

Collapse
No announcement yet.

controlling IE - scrolling down a window

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • controlling IE - scrolling down a window

    i'm trying to get a IHTMLWindow2 object to use it's Scroll method. It's realy weird but it doesn't work. Here is the code i used.
    m_pWebBrowser is IWebBrowser2* and has been corectly initialized...as in i can use it to control the IE window (Navigate...parse the source...).
    Code:
    HRESULT hr;
    IDispatch* pHtmlDocDispatch = NULL;
    IHTMLDocument2 * pHtmlDoc = NULL;
    IHTMLWindow2 * p = NULL;
    
      hr = m_pWebBrowser->get_Document (&pHtmlDocDispatch);
      if (SUCCEEDED (hr) && (pHtmlDocDispatch != NULL))
      {
        hr = pHtmlDocDispatch->QueryInterface (IID_IHTMLDocument2, (LPVOID *) &pHtmlDoc);
        if (SUCCEEDED (hr) && (pHtmlDoc != NULL))
        {
          pHtmlDoc->get_parentWindow(&p);
          // this is were i get the error. p remains null
         if(SUCCEEDED(hr) && p)
           p->scrollTo(x,y);
       }
    }
    I realy hope some1 can help or at least give me an alternative way to scroll the IE window..other then sending keys.

  • #2
    Have you tried the ScrollWindowEx() API function? What you're doing seems awful complicated, but I've never done anything with IE from API so I really have no idea.
    Omnis mico antequam dominus Spookster!

    Comment


    • #3
      Try this instead.

      Code:
        
      HRESULT hr;
      IDispatch* pHtmlDocDispatch = NULL;
      IHTMLDocument2 * pHtmlDoc = NULL;
      IHTMLWindow2 * p = NULL;
      
      hr = m_pWebBrowser->get_Document (&pHtmlDocDispatch);
      if (SUCCEEDED (hr) && (pHtmlDocDispatch != NULL))
         {
         hr = pHtmlDocDispatch->QueryInterface( __uuidof( IID_IHTMLDocument2), (void**)&pHtmlDoc );
         if (SUCCEEDED (hr) && (pHtmlDoc != NULL))
            {
            hr = pHtmlDoc->get_parentWindow(&p);
            // this is were i get the error. p remains null
            if(SUCCEEDED(hr) && p)
               p->scrollTo(x,y);
            }
         }

      If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
      Bored? Visit
      http://www.kaelisspace.com/

      Comment


      • #4
        Just noticing that, wouldn't the compiler be throwing an error there?
        I noticed that there was no cast in the original code, nor your code...which has me thinking that either the function takes a uid or a IHTMLDocument2.

        [edit] It takes REFID, so how could IHTMLDocument2 not throw a compiler error?
        Last edited by Mhtml; Aug 3, 2005, 01:09 PM.
        Omnis mico antequam dominus Spookster!

        Comment


        • #5
          hr = pHtmlDocDispatch->QueryInterface (__uuidof( IID_IHTMLDocument2), (LPVOID *) &pHtmlDoc);

          error C2787: '_GUID' : no GUID has been associated with this object

          nope...doesn't work that way

          Comment


          • #6
            Originally posted by Mhtml
            Just noticing that, wouldn't the compiler be throwing an error there?
            I noticed that there was no cast in the original code, nor your code...which has me thinking that either the function takes a uid or a IHTMLDocument2.

            [edit] It takes REFID, so how could IHTMLDocument2 not throw a compiler error?
            Beats me, I just looked at a working example from a google result, compared it to what was posted, and changed the OP.
            I'm not even sure what language this is written in.

            If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
            Bored? Visit
            http://www.kaelisspace.com/

            Comment


            • #7
              i checked the returned HRESULT after the get_parenWindow call and looked for it in winerror.h

              // MessageId: E_NOINTERFACE
              //
              // MessageText:
              //
              // No such interface supported
              //
              #define E_NOINTERFACE _HRESULT_TYPEDEF_(0x80004002L)

              Comment

              Working...
              X