MFC single document program loads web sites and html files

Using the CHtmlView class, the main function of the CHtmlView class is to access Web sites and HTML documents; this class can be said to be an encapsulation of the webbrowser control;

Create a new single-document project; select the CHtmlView class as the base class of the visual class; the project name is htmldemo;

In the mfc class library, the inheritance relationship of the CHtmlView class is as follows;

After generation, there is a CHtmdemoView::OnInitialUpdate() function by default, where the first web page appears;

This function defaults to the sentence Navigate2(_T("https://xxxxxx/"),NULL,NULL) to load the webpage; the url can be changed by yourself; after loading the Baidu homepage, an error message will pop up, and the program needs to be improved local;

Load a local html file; create a new html file; insert in the resource; select HTML as the resource type;

After insertion, the ID is IDR_HTML1;

Run the program, as follows, load the inserted html file;

 

Guess you like

Origin blog.csdn.net/bcbobo21cn/article/details/114464335