The "Do-Nothing" Application—EX03A

The AppWizard tool generates the code for a functioning MFC library application. This working application simply brings up an empty window with a menu attached. Later you'll add code that draws inside the window. Follow these steps to build the application:

  1. Run AppWizard to generate SDI application source code. Choose New from Visual C++'s File menu, and then click the Projects tab in the resulting New dialog box, as shown here.

    Click to view at full size.

    Make sure that MFC AppWizard (exe) is highlighted, and then type C:\vcpp32\ in the Location edit box. Type ex03a as shown in the Project Name edit box, and then click the OK button. Now you will step through a sequence of AppWizard screens, the first of which is shown here.

    Click to view at full size.

    Be sure to select the Single Document option. Accept the defaults in the next four screens. The last screen should look like the following illustration.

    Click to view at full size.

    Notice that the class names and source-file names have been generated based on the project name EX03A. You could make changes to these names at this point if you wanted to. Click the Finish button. Just before AppWizard generates your code, it displays the New Project Information dialog box, shown here.

    When you click the OK button, AppWizard begins to create your application's subdirectory (ex03a under \vcpp32) and a series of files in that subdirectory. When AppWizard is finished, look in the application's subdirectory. The following files are of interest (for now).

    FileDescription
    ex03a.dspA project file that allows Visual C++ to build your application
    ex03a.dswA workspace file that contains a single entry for ex03a.dsp
    ex03a.rcAn ASCII resource script file
    ex03aView.cppA view class implementation file that contains CEx03aView class member functions
    ex03aView.hA view class header file that contains the CEx03aView class declaration
    ex03a.optA binary file that tells Visual C++ which files are open for this project and how the windows are arranged (This file is not created until you save the project.)
    ReadMe.txtA text file that explains the purpose of the generated files
    resource.hA header file that contains #define constant definitions

    Open the ex03aView.cpp and ex03aView.h files and look at the source code. Together these files define the CEx03aView class, which is central to the application. An object of class CEx03aView corresponds to the application's view window, where all the "action" takes place.

  1. Compile and link the generated code. AppWizard, in addition to generating code, creates custom project and workspace files for your application. The project file, ex03a.dsp, specifies all the file dependencies together with the compile and link option flags. Because the new project becomes Visual C++'s current project, you can now build the application by choosing Build Ex03a.exe from the Build menu or by clicking the Build toolbar button, shown here.

    If the build is successful, an executable program named ex03a.exe is created in a new Debug subdirectory underneath \vcpp32\ex03a. The OBJ files and other intermediate files are also stored in Debug. Compare the file structure on disk with the structure in the Workspace window's FileView page shown here.

    The FileView page contains a logical view of your project. The header files show up under Header Files, even though they are in the same subdirectory as the CPP files. The resource files are stored in the \res subdirectory.

  2. Test the resulting application. Choose Execute Ex03a.exe from the Build menu. Experiment with the program. It doesn't do much, does it? (What do you expect for no coding?) Actually, as you might guess, the program has a lot of features—you simply haven't activated them yet. Close the program window when you've finished experimenting.

  3. Browse the application. Choose Source Browser from the Tools menu. If your project settings don't specify browser database creation, Visual C++ will offer to change the settings and recompile the program for you. (To change the settings yourself, choose Settings from the Project menu. On the C/C++ page, click Generate Browse Info, and on the Browse Info page, click Build Browse Info File.)

    When the Browse window appears, choose Base Classes And Members and then type CEx03aView. After you expand the hierarchy, you should see output similar to this.

    Click to view at full size.

    Compare the browser output to ClassView in the Workspace window.

    ClassView doesn't show the class hierarchy, but it also doesn't involve the extra overhead of the browser. If ClassView is sufficient for you, don't bother building the browser database.