描述:
代码如下:
CComPtr< IWebBrowser2 > spWB2;
//spWB2.CoCreateInstance( CLSID_InternetExplorer );
spWB2.CoCreateInstance( CLSID_WebBrowser );
CComVariant flag;
CComVariant empty;
CComBSTR url;
spWB2->Navigate( url, &flag, &empty, &empty, &empty );
while( !IsDocumentReady( spWB2.p ) )
Sleep( 500 );
CComPtr< IDispatch > spDisp;
spWB2->get_Document( &spDisp );
如果使用CLSID_InternetExplorer,可以获得网页,
但如果使用CLSID_WebBrowser,就不行了,有没有方法使用WebBrowser,而不是IE?
解决方案1:
可能是没有下载完你就执行 get_Documents()了,所以取的是空指针。
while( !IsDocumentReady( spWB2.p ) )
Sleep( 500 );
-------------
去掉这个。
CComPtr< IDispatch > spDisp;
spWB2->get_Document( &spDisp );
---------------------------------
把这段的功能放在OnDocumentComplete事件中。
可以考虑用DIID_DWebBrowserEvents2实现
您可能想查找下面的文章:
- 如何控制WebBrowser,并使其提交其中的网页或者操纵其中的文本框等?
- 如何模拟点击Webbrowser显示网页中的选项卡
- webbrowser禁止网页被拖拽
- webbrowser获得部分网页并按照原样显示出来
- webbrowser网页元素ID相同怎么办?
- MimeFliter过滤webbrowser中网页代码项目中如何获取CLSID
- 请问使用WebBrowsercontrol如何修改网页的内容?
- 如何使用WebBrowser获得一个网页的内容?
- CAxWindow创建webbrowser后,网页中无法使用ctrl+c,ctrl+v快捷健
- 请问如何判断WebBrowser中的当前网页是否已经下载完成