获取WEBBROWSER滚动位置:莫名其妙的问题,大家帮看看
HRESULT hr;
IDispatch *pDisp = this->M_Browser.get_Document();
if(pDisp == NULL) return NULL;
// 获得Html文档指针
IHTMLDocument2 *pDocument = NULL;
hr = pDisp->QueryInterface( IID_IHTMLDocument2, (void**)pDocument );
if(!SUCCEEDED( hr ) || !pDocument) return NULL;
IHTMLElement *pBody = NULL;
hr = pDocument->get_body( &pBody );
if(!SUCCEEDED( hr ) || !pBody) return NULL;
pDocument->Release();
// 从body获得IHTMLElement2接口指针,用以访问滚动条
IHTMLElement2 *pElement = NULL;
hr = pBody->QueryInterface(IID_IHTMLElement2,(void**)&pElement);
if(!SUCCEEDED( hr ) || !pElement) return NULL;
pBody->Release();
long mScrollTop;
pElement->get_scrollTop(&mScrollTop);
pElement->Release();
return mScrollTop;
这样得到的滚动位置有时候是正确的,有时候总是0,请大家帮忙!!!