获取WEBBROWSER滚动位置:莫名其妙的问题,大家帮看看

andy_123 andy_123 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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,请大家帮忙!!!
...全文

相关推荐

评论 5
收藏 已收藏
分享
返回顶部
andy_123
界面 15,977 成员 115,865 内容