I need to get information about the scrollbars (position, size, visibility) of a Webbrowser control of an external application, I tried using the GetScrollBarInfo function from my previous question, but the function always return false, I checked this function with another applications and works fine , but not with the IE or the Webbrowser control. So how I can get information about the scrollbars of an Webbrowser control instance or the IE Webbrowser?
Here is how you can know whether the scrollbars are visible or not. Some error checking missed for brevity.
LPDISPATCH lpDispatch;
lpDispatch = m_Browser.GetDocument();
IHTMLDocument2 *doc2 = NULL;
disp->QueryInterface(IID_IHTMLDocument2,(void**)&doc2);
IHTMLElement *lpBodyElement;
IHTMLBodyElement *lpBody;
doc2->get_body(&lpBodyElement);
if ( lpBodyElement )
{
lpBodyElement->QueryInterface(IID_IHTMLBodyElement,(void**)&lpBody);
if ( lpBody )
{
BSTR bstrText;
pBody->get_scroll(&bstrText);
lpBody->Release();
}
lpBodyElement->Release();
}
doc2->Release();
Possible values for bstrText are "yes", "no", "auto" (scroll bars are shown when the page content exceeds the client area)
And here is how you can know the current scroll position:
IHTMLElement2 *pElement = NULL;
hr = pBody->QueryInterface(IID_IHTMLElement2,(void**)&pElement);
ASSERT(SUCCEEDED(hr));
ASSERT( pElement );
long scroll_pos;
pElement->get_scrollTop( &scroll_pos);