PDA

View Full Version : controlling IE - scrolling down a window


pitagora
08-03-2005, 03:25 PM
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...).

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.

Mhtml
08-03-2005, 05:30 PM
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.

nikkiH
08-03-2005, 05:41 PM
Try this instead.


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);
}
}

Mhtml
08-03-2005, 06:05 PM
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?

pitagora
08-03-2005, 08:30 PM
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

nikkiH
08-03-2005, 08:43 PM
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. :D

pitagora
08-04-2005, 05:40 PM
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)