Creating a Web browser-style Application

HomeOverviewHow Do IDetailsSample

You can use the MFC AppWizard to create an application that displays any Web content you specify.

To create a Web browser application

  1. Follow the steps to create an MFC AppWizard (.exe version).

    Your application must be based on the MFC document/view architecture (default).

  2. In Step 6 of the wizard, use the Base class drop-down list to select CHtmlView.

  3. Click Finish.

The CHtmlView class acts as a wrapper for the Web browser control, which gives your application a view onto a Web, or HTML page. The wizard creates an override to the OnInitialUpdate function in the view class, providing a navigational link to the Microsoft Visual C++ Web site:

void CWebView::OnInitialUpdate()
{
   CHtmlView::OnInitialUpdate();

   // TODO: This code navigates to a popular spot on the web.
   //  change the code to go where you'd like.
   Navigate2(_T("http://www.microsoft.com/visualc/"),NULL,NULL);
}

You can replace this site with one of your own, or you can use the LoadFromResource function to open an HTML page that resides in the project's resource script as the default content for the view. For example:

void CWebView::OnInitialUpdate()
{
   CHtmlView::OnInitialUpdate();

   // TODO: This code navigates to a popular spot on the web.
   //  change the code to go where you'd like.
   LoadFromResource(IDR_HTML1);
}

What do you want to know more about?

Navigate2 method

LoadFromResource function

CHtmlView class

What do you want to do?

Open my HTML page as the default in my Web Browser application

Create a New HTML Resource

Import an existing HTML file as a resource