This lesson introduces you to Visual C++ development projects and shows you how to use the AppWizard to create projects based on the Microsoft Foundation Classes (MFC). You will use the AppWizard to generate a framework of code and resources that can be compiled into a working executable program. This program can be used as a basis for the development of an application to suit your specific requirements.
After this lesson, you will be able to:Estimated lesson time: 30 minutes
- Describe how projects and workspaces are organized in Visual C++.
- Describe the types of projects you can create with the AppWizard.
- Understand the steps involved in using the AppWizard to create an MFC executable application.
In Visual Studio, application source code files and the files that specify application resources, such as menus, toolbars and dialog boxes, are grouped together into projects. A project allows you to edit your files and manage the relationships—such as build dependencies—between them.
In a Visual C++ project, settings for the build tools such as the compiler, resource compiler, and linker are centrally controlled through the Project Settings dialog box. You can specify any number of independent configurations of settings for your project. When you use the AppWizard to create a project, both Debug and Release configurations are created for you automatically.
Projects are always contained within a workspace. By default, a single project will be created inside a workspace, and both configurations will have the same name. To organize your development more effectively, you can group related projects together into a single workspace. You can also set dependency relationships between them to ensure build consistency between projects that share files.
Although your workspace might contain more than one project, you work on only one project at a time, known as the active project. Figure 2.1 is an illustration of a workspace that includes three projects. Note that the active project is displayed in bold type.
Figure 2.1 Workspace window (FileView)
The starting point for any development in Visual C++ is the Visual C++ New Project dialog box (shown in Figure 2.2), which lists project types.
Start Visual C++ by clicking Start, pointing to Programs, pointing to Microsoft Visual C++ 6.0, and then clicking Visual C++. On the File menu, click New.
Figure 2.2 Visual C++ New dialog box (Enterprise Edition)
You use the New command to create new workspaces, projects, source files, or resource files. You can also create blank documents for other Microsoft applications such as Microsoft Word or Microsoft Excel.
The Visual C++ New Project dialog box gives you the option of creating a project for the development of applications, components, or libraries using the following methods:
Although MFC saves you time and effort in the creation of Windows programs, simple programs might not justify the code size and performance overhead of MFC. To use MFC in an application, you need to link the MFC static libraries to your code or ensure that the MFC DLLs are installed on each computer that will run your application. Consider whether your application needs the types of application framework created by the MFC project options.
NOTE
The Enterprise edition of Visual C++ contains some project options not found in the Standard or Professional editions. These allow you to work with DEFINTION (ODBC) databases directly from Visual Studio and to create SQL Server extended stored procedures.
In this exercise, you will use the AppWizard to create an MFC executable project.
NOTE
AppWizard will create your project in the default location in the directory: C:\Program Files\Microsoft Visual Studio\MyProjects. If you want, you can enter a different location in the Location edit box.
The first dialog box of the MFC AppWizard, shown in Figure 2.3, appears.
Figure 2.3 MFC AppWizard—Step 1
Step 1 of the MFC AppWizard gives you the option to choose whether your project is to produce a single-document interface (SDI) application (the Single document option); a multiple-document interface (MDI) application (the Multiple documents option); or an application that is based around a dialog box (Dialog based option). SDI applications permit only one document, displayed within the application's main window, to be open at a time. MDI applications allow multiple documents, displayed in multiple child windows, to be opened within a single instance of an application. Dialog-based applications use a dialog box as their main application window rather than the style of window that displays a client area inside a frame. Lesson 4 in Chapter 3 discusses these application types in more detail.
You can get help on any of the options in the AppWizard by selecting the appropriate option and pressing F1.
The following steps show you how to make MyApp.exe an SDI application.
Figure 2.4 MFC AppWizard—Step 2
Figure 2.5 MFC AppWizard—Step 3
Figure 2.6 MFC AppWizard—Step 4
Figure 2.7 The Document Template Strings tab of the Advanced Options dialog box
Figure 2.8 The Window Styles tab of the Advanced Options dialog box
Figure 2.9 MFC AppWizard—Step 5
Figure 2.10 MFC AppWizard—Step 6
Powerful features are available from this drop-down list. Many of the base classes listed incorporate functionality based on Windows common controls, which you can use to help you organize the display of your application data. If you select CRichEditView, you can construct an application based on a full-featured text editor. With CHtmlView, your application would be based on an HTML browser. The default CView provides your application with a blank window where you can display your application data in any form you choose. CScrollView is similar to CView, but it creates a scrollable view that enables you to display more data than can be shown in a single screen window.
The source code and resource files that make up an application or component are grouped together in projects. Projects enable you to easily manage your files and build settings. You can specify any number of independent configurations of settings for your project. Related projects may be grouped together into a single workspace.
Visual C++ provides a number of project wizards that provide frameworks from which you can develop different types of applications and components, using a variety of technologies.
The MFC AppWizard allows you to quickly and easily create a set of classes and resources that can be compiled to produce a complete MFC executable application. By using the AppWizard you can: