|
RESULT hr;
IDispatch *pDisp = m_cMyWebBrowser.GetDocument();
ASSERT( pDisp ); //if NULL, we failed
To
// Get Html document pointer
IHTMLDocument2 *pDocument = NULL;
hr = pDisp->QueryInterface( IID_IHTMLDocument2, (void**)&pDocument );
ASSERT( SUCCEEDED( hr) );
ASSERT( pDocument );
To
IHTMLElement *pBody = NULL;
hr = pDocument->get_body(&pBody );
ASSERT( SUCCEEDED( hr) );
ASSERT( pBody );
To
// Obtain the IHTMLElement2 interface pointer from the body to access the scroll bar
IHTMLElement2 *pElement = NULL;
hr = pBody->QueryInterface(IID_IHTMLElement,(void**)&pElement);
ASSERT(SUCCEEDED(hr));
ASSERT( pElement );
To
IHTMLTextContainer *pCont;
pBody->QueryInterface(IID_IHTMLTextContainer, (LPVOID *)(&pCont));
ASSERT(pCont);
To
To
// scroll down 100 pixels
// pElement->put_scrollTop( 100 );
To
To
// Get the height of the scroll bar
long scroll_height;
pCont->get_scrollHeight(&scroll_height );
To
// Get the width of the scroll bar
long scroll_width;
if(FAILED(pCont->get_scrollWidth(&scroll_width )))
AfxMessageBox("get scrollWidth failed.");
To
// Get the scroll bar position, starting from the top
long scroll_top;
if(FAILED(pCont->get_scrollTop(&scroll_top )))
AfxMessageBox("get scrollWidth failed.");
// Get the scroll bar position, starting from the left end
long scroll_left;
if(FAILED(pCont->get_scrollLeft(&scroll_left )))
AfxMessageBox("get scrollWidth failed.");
To
CString str;
str.Format("%d,%d,%d,%d",scroll_height,scroll_width,scroll_top,scroll_left);
AfxMessageBox(str);
To
pCont->Release();
pElement->Release();
pBody->Release();
pDocument->Release();
pDisp->Release();
Ps: If used in the page
WEB standards will invalidate ScrollTop and ScrollLeft properties! ! ! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0
Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> |
|