标签:des cWeb style blog http color
摘自:http://blog.csdn.net/cometnet/article/details/5261192
一般情况下,当ReadyState属性变成READYSTATE_COMPLETE时,Webbrowser控件会通过触发DocumentCompleted事件来指示网页加载完毕。但当加载的网页包含frame时,可能会多次触发该事件,所以不能简单地通过它来判断网页加载完毕。
从微软的官方网站上了解到,并非每个frame都对应了一个DocumentCompleted事件,只有触发了DownloadBegin事件的frame才会有相应的DocumentCompleted事件。另外,最外层的frame总是最后触发DocumentCompleted事件。DocumentCompleted事件具有一个IDispatch *类型的参数,它指示了是在哪个frame上触发的该事件。所以,要判断文档是否加载完毕,只需要判断IDispatch *参数是否是Webbrowser控件的IDispatch。
微软support网站上关于这个问题的说明:
http://support.microsoft.com/?scid=kb%3Ben-us%3B180366&x=9&y=14
原文及译文如下:(我用Google翻译的,不一定正确,大家见谅)
The Internet Explorer WebBrowser control fires the DocumentComplete event when it is finished downloading a Web page. You can create a event handler function in your application for this event. This article describes the steps to take in determining if a the WebBrowser control is finished downloading a Web page.
在Internet Explorer WebBrowser控件激发DocumentComplete事件完成时下载网页。您可以在应用程序中创建的这一事件的事件处理函数。本文介绍的步骤可以参与决定,如果WebBrowser控件下载完成一个网页。
The WebBrowser control fires the DocumentComplete event when its ReadyState property is changed to READYSTATE_COMPLETE. This indicates that the WebBrowser control has completed downloading the Web page. Here are some important points regarding this event:
WebBrowser控件激发DocumentComplete事件时,它的readyState属性更改为READYSTATE_COMPLETE。这表明,WebBrowser控件已完成下载的网页。以下是一些对这起事件的要点: 在网页的情况下,没有框架,一旦被激发的DocumentComplete一切完成之后。 在多个帧的情况,得到的DocumentComplete多次发射。不是每帧触发这一事件,但每个帧触发一个DownloadBegin事件触发相应的DocumentComplete事件。 DocumentComplete事件的IDispatch *有一个参数,它是框架(shdocvw),这些被激发的DocumentComplete的IDispatch。 在顶级框架火灾最终的DocumentComplete。因此,要检查一个页面完成下载,您需要检查的IDispatch *参数作为WebBrowser控件的IDispatch相同。
For Visual Basic, here is code that performs this check:
To handle the DocumentComplete event in Visual C++ and determine if the download of the Web page is complete, follow these steps.
Note that the steps you follow depend on the way you use the WebBrowser control.
为了处理在Visual C + + DocumentComplete事件,并确定如果网页下载完成后,按照下列步骤。
请注意,您按照步骤取决于你如何使用WebBrowser控件。 如果你在创建一个CWnd / CView对象WebBrowser控件,则必须按照步骤1至4。 如果您要创建一个CDialog在WebBrowser控件/ CFormView对象,只需要按照步骤4。 如果您使用的是CHtmlView类提供与Visual C + + 6.0,重写CHtmlView::的DocumentComplete()和后续步骤4,使用该CHtmlView类m_pBrowserApp成员访问WebBrowser控件。
1.Define the OnDocumentComplete method in the header file for your CWnd/CView-derived class:
2.Declare the event sink in the same header file:
3.In the implementation file (.cpp) for your CWnd/CView-derived class, implement the event sink map:
4.Implement the OnDocumentComplete method:
This approach works when the WebBrowser control navigates to a page that changes the top-level frame. Say if the navigation occurs within a frame itself, then the final DocumentComplete that is fired is that of the frame and not the top-level frame. For example, consider the following scenario.
The WebBrowser control is hosting a frameset. Within one frame of the frameset, the user clicks on a link that opens a new page in the frame itself and keeps the rest of the frameset intact. The new page could contain multiple frames again. So, there will be multiple DocumentComplete notifications (one for each new frame). But, since the top-level frame has not changed, the final DocumentComplete would be that of the frame that has changed.
If you are interested in checking for the final document complete in this scenario, you could do the following:
Webbrowser控件判断网页加载完毕的简单方法 (转),布布扣,bubuko.com
标签:des cWeb style blog http color
原文地址:http://www.cnblogs.com/KeenLeung/p/3837853.html