![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Fast Track Visual C++ 6.0 Programming
As you can see, quite a number of functions are in the CHtmlView class. Navigate() is particularly useful, because it lets us navigate to a new URL and display the corresponding document in our HTML view. Lets use that function to put together a Web-browsing MDI program now. Create a new MDI project named HTMLView. In Step 6 of the AppWizard, use CHtmlView as the base class for our view class, then create the project. Our first step is to create a URL dialog box that lets the user type in the new URL to navigate to. Designing the URL Dialog BoxTo add a new dialog box to our project, select the Insert menus Resource item to open the Insert Resource box; select Dialog as the new type of resource to create, and click New. This creates the new dialog box with an ID IDD_DIALOG1. Click that ID in the ResourceViews Dialog folder to open the Dialog Editor as shown in Figure 3.6. Add a new label to that dialog box, New Url:, and a text box, as shown in Figure 3.6. The design of the dialog box is complete. Now we have to add it to our code, which means creating a new class wrapper for it.
Adding the Dialog Box to CodeRight-click the dialog box and open ClassWizard. ClassWizard displays a message saying that you have just created a new dialog box and asks whether you want to create new class for that dialog box. Click OK, opening ClassWizard. Give the new class the name URLDlg, make sure its base class is CDialog, then create this new class. We need a way to retrieve data from the text box in the dialog box to read the new URL. In ClassWizard, open the URLDlg class, click the Member Variables tab, then connect a new CString variable named m_URL to the text box, IDC_EDIT1. Our dialog box is set. Now we need a way of putting it on the screen. We do that by adding a new menu item to the File menu: Navigate... . When we type a new URL into the URL dialog box and click OK, we navigate to that new document. Connect a view class function to the new Navigate menu item using ClassWizard. void CHTMLViewView::OnFileNavigate() { // TODO: Add your command handler code here } This is where we use the new dialog box. Before we use the dialog box class, however, we have to include its header file in the view class code to make sure Visual C++ has access to all the dialog box declarations. // HTMLViewView.cpp : implementation of the CHTMLViewView class // #include stdafx.h #include HTMLView.h #include HTMLViewDoc.h #include HTMLViewView.h #include URLDlg.h ⇐ . . . Now, create a dialog box of the URLDlg class. void CHTMLViewView::OnFileNavigate() { URLDlg urldlg; ⇐ . . . } To display the dialog box, use its DoModal() function. void CHTMLViewView::OnFileNavigate() { URLDlg urldlg; int dlgvalue = urldlg.DoModal(); ⇐ . . . } After the user closes the dialog box, examine the dialog boxs return value. If its IDOK, the user clicked the OK button; if its IDCANCEL, the user pressed the Cancel button. We want to navigate to the new URL as follows: void CHTMLViewView::OnFileNavigate() { URLDlg urldlg; int dlgvalue = urldlg.DoModal(); if(dlgvalue == IDOK){ ⇐ Navigate(urldlg.m_URL); ⇐ } ⇐ }
Now we are able to run the program, as shown in Figure 3.7. In that figure, the Navigate menu item is used to navigate to Microsofts Web page (the default Web page for HTML views is the Microsoft Visual C++ Web page). Now were on the Web with Visual C++.
The code for this program, HTMLViewView.h and HTMLViewView.cpp, appears in Listing 3.1.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |