In the chtmlview, an accurate method for determining whether a page is loaded

Source: Internet
Author: User
It's early in the morning, but you have to record this issue. Otherwise, you will have to make a detour.

Today, I am doing a test on a small system. To facilitate automatic operations, I wrote a software program with VC to replace manual operations. Simply put, the function is to constantly refresh a URL andProgramWill return another URL, depending on whether the server side program will have problems, but also to record something.

I have been using VC for more than two years, but I have never engaged in VC programs directly related to browser. This time I have to rush into the battle: I used chtmlview to implement a super-Simplified browser, then, determine whether the page is loaded. After the page is loaded, perform subsequent processing.

Check msdn and you will know that the ondocumentcomplete function will be triggered after the Framework loads the page. Therefore, this function is reloaded, but when navigate to many pages (such as www.sina.com.cn, this function is triggered n times, so I checked and found that these pages contain multiple frames. After each frame is loaded, I will notify you, after the top-level frame is loaded, the last notification will be sent. To determine whether the whole page is loaded, you can only use other methods.

Later I found that the undisclosed function documentcomplete is a key and needs to be reloaded. Thanks to the power of vassist, I directly typed out the prototype of this function without checking the Manual (Shuang ~), Specifically, if you want to add them manually, add the following in your chtmlview inheritance Class header file:

Public:
Void documentcomplete (lpdispatch Pdisp, variant * URL );

Then add the following to the implementation file:

Void cmyhtmlview: documentcomplete (lpdispatch Pdisp, variant * URL)

{

// What is written here?

}

What is the implementation part of the above function? This is what we call "determine whether the page is loaded successfully ".Code. From this miserable Machine Translation in MSArticleI can still get some inspiration. I modified the Code to make it suitable for the VC 2005 + IE7 environment, as shown below:

Void cmyhtmlview: documentcomplete (lpdispatch Pdisp, variant * URL)
{
M_ncount ++; // This is a member variable of my class for counting.
Lpdispatch lpwbdisp = NULL;
Hresult hR = NULL;

HR = m_pbrowserapp-> QueryInterface (iid_idispatch, (void **) & lpwbdisp );
Assert (succeeded (HR ));

If (Pdisp = lpwbdisp)
{
Cstring strmessage;
Strmessage. Format ("Page loaded! /N: % d ", m_ncount );
// Top-level window object, so document has been loaded
MessageBox (strmessage );
}

Lpwbdisp-> release ();
}

Some of the running results are as follows (when loading the page of www.sina.com.cn ):

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/learnhard/archive/2009/09/12/4540925.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.