Webocreation

Tuesday, November 17, 2009

Lab 4.2: Using AppWizard to Create an MFC Application

Lab 4.2: Using AppWizard to Create an MFC Application


 


In this lab, you will create, build, and run a simple MFC application in the Developer Studio development environment using AppWizard.

To see a demonstration that shows what you will accomplish during the lab, click this icon.

F 

Estimated time to complete this lab: 15 minutes

To complete the exercises in this lab, you must have the required software. For detailed information about the labs and setup for the labs, see Labs in this course.

Objectives

After completing this lab, you will be able to:

®  Use AppWizard to create a simple text editor application using MFC.

®  Use Microsoft Developer Studio and Microsoft Visual C++ 5.0 to build and run the application.

 

Prerequisites

There are no prerequisites for this lab.

Exercise

The following exercise provides practice with the concepts and techniques covered in this chapter.

®  Exercise 1: Creating a Simple Text Editor

In this exercise, you will use Microsoft Developer Studio, MFC AppWizard, and Microsoft Visual C++ 5.0 to create, build, and run a simple MFC single document interface (SDI) text editor application.

 



  1. Exercise 1: Creating a Simple Text Editor


In this exercise, you will create a simple text editor using AppWizard. All of the functionality in this application is provided in the classes automatically generated by AppWizard.

       u  Create a new project using AppWizard

       1.   In Developer Studio, on the File menu, click New.

       2.   In the New dialog box, click the Projects tab, and then do the following:

           a.           For the project type, click MFC AppWizard (exe).

           b.           For the project name, type TextEditor.

           c.           Set the location for your project.

           d.           Accept the default platform Win32.

           e.           To create the new project workspace, click OK.

       3.   MFC AppWizard will start. In MFC AppWizard, Step 1, click Single document and English, and then click Next to go to Step 2.

       4.   Since this project needs no database support, accept the default None for database support and click Next to go to Step 3.

       5.   In Step 3, accept None for the document support, clear the ActiveX Controls check box, and then click Next to go to Step 4.

       6.   In Step 4, accept the defaults (Docking toolbar, Initial status bar, Printing and print preview, 3D controls, and four files for the recent file list) and click Advanced. On the Document Template Strings tab, type txt in the File extension box. Click Close, and then click Next to go to Step 5.

       7.   In Step 5, select Yes, please for generating source file comments and select As a shared DLL for MFC support. Click Next to go to Step 6.

       8.   In Step 6, select the CTextEditorView class and change its base class to CEditView. Click Finish to display the New Project Information dialog box summarizing your choices.

       9.   To cause AppWizard to create the application files, click OK.

When AppWizard is finished, you will be returned to Developer Studio. To see the classes that AppWizard created, click the ClassView tab in the Project Workspace window.

 

       u  Build and run the project

       1.   On the Build menu in Developer Studio, click Build TextEditor.exe or press F7. Developer Studio displays the status of the build process as it builds your project.

       2.   After the build is complete, on the Build menu, click Execute TextEditor.exe. The application, TextEditor, will start.

 

At this point, the TextEditor application contains a minimal set of functionality. However, many of the basics are in place: menus, a toolbar, a status bar, and a window frame. You can write text in the window, save it, close the file, reload the file, and create new text files.

You can find the completed code for this exercise in \Labs\Ch04\Lab02\Ex01.


Self-Check Questions


 


       1.   Which of the following statements is true about the relationship between document and views?

F         A.         The documents and views are derived from the CFrameWnd class.

F         B.         In an MFC application, view objects are embedded in their corresponding document classes.

F         C.         The function CDocument::UpdateAllViews works by calling CView::Invalidate for each view attached to it.

F         D.         The view is responsible for displaying, and perhaps modifying, the document, but not for storing the

                                document.

 

       2.   What is the purpose of the GetDocument member function?

F         A.         To be called by the framework when a document is loaded from disk.

FF         B.         To return a list of currently open documents.

F         C.         To return a pointer to the associated document object.

F         D.         To open the document using the common dialog box.

 

       3.   The minimum classes required to create a Window-based MFC application are:

F         A.         CWinApp and CView

F         B.         CView and CDocument

F         C.         CFrameWnd and CWinApp

F         D.         CView and CFrameWnd

 

       4.   When you derive an application class from CWinApp, what function must you override to create your application's main window object?

F         A.         InitInstance

F         B.         Run

F         C.         AddDocTemplate

F         D.         CreateInstance

  

       5.   What is the purpose of the DECLARE_DYNCREATE macro?

F         A.         To enable objects of CObject-derived classes to be created dynamically at run time.

F         B.         To enable objects of any class to be created dynamically at run time.

FF         C.         To dynamically create documents.

F         D.         To dynamically create views.

 

       6.   If the DECLARE_DYNCREATE macro is included in the class declaration, then what must be included in the class implementation?

F         A.         Use IMPLEMENT_ in header file.

FF         B.         Use the RUNTIME_CLASS macro to dynamically create objects.

F         C.         Include the IMPLEMENT_DYNCREATE macro in the class implementation file.

FFF         D.         Call the PreCreateWindow function.

No comments:

Post a Comment