获取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,请大家帮忙!!!
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,请大家帮忙!!!
...全文
相关推荐
webbrowser滚动条位置
获取webbrowser滚动条当前位置,并可以自由设置滚动条位置。用c#语言编写,可以运行。获取webbrowser滚动条当前位置,并可以自由设置滚动条位置。用c#语言编写,可以运行。
C# 用VScrollBar控制webbrowser的滚动条 简单测试
用VScrollBar控制webbrowser的滚动条,如在触摸屏上webBrowser垂直滚动条太小,不方便使用,用VScrollBar来替换,
去掉WebBrowser的边框和滚动条
老问题,新解法:关于去掉WebBrowser的边框和滚动条 连接点+SetUIHander方法 关键代码
C#获取WebBrowser中的cookie和userAgent
C#代码获取WebBrowser中的 cookie和userAgent 参数,方法和请求类
C# 利用WebBrowser获取网页信息
用于获取网页信息!利用WebBrowser获取网页信息


界面
