Creating a MFC Dialog-Based Project


Click here to change the theme.

This is a little tutorial about creating a Microsoft Visual C++ MFC Dialog-based application.

Introduction

When I began learning MFC I had difficulty remembering the difference between the AppWizard and the ClassWizard yet the difference is quite simple. The following is a summary of each.

AppWizard
used only once per application to initially generate it
ClassWizard
used to modify the application in various way

Creating the Project

You can create a MFC Dialog-based application using the AppWizard.

 (I need to describe what a project and a workspace is.) (Also explain what a dialog-based application is.)

File | New

In the File menu select New, then select the Projects tab, then select MFC AppWizard. Specify a Project Name and a Location. For this project I used HelloDlg for the Project Name. The dialog box should look something like the following:

Click "Ok". The AppWizard property sheet will then be shown. For a MFC project there are four property pages.

Step 1

Step 1 is where the type of application to be generated is specified. Click the radio button for "Dialog based". Then the property page should look something like the following:

Then click "Next".

Step 2

You can use the defaults in step 2, except one useful modification is to change the title that will be used for the dialog. That is done in the text box near the bottom of the page. The property page should look something like the following:

Then click "Next".

Step 3

You can use the defaults in step 3. The property page should look something like the following:

Then click "Next".

Step 4

You can use the defaults in step 4 also. The property page should look something like the following:

Then click "Finish".

Project Information

After clicking "Finish" the AppWizard shows a window that summarizes the options chosen. That information will be put in a ReadMe.txt file so you can look at it later if you wish.

Click "Ok". The AppWizard will then generate the project. Files will be created in the directory specified in the initial dialog box.

Build and Execute the Project

You can build the project immediately after generating it. Build means that the program will be compiled and an executable (exe) file will be created that will execute and show a dialog. To build the project (program), either use the F7 key or in the "Build" menu, choose "Build HelloDlg.exe" (the filename depends on the name of the project). Assuming the build works, execute the program either using the Ctrl-F5 keys or in the "Build" menu, choose "Execute HelloDlg.exe". When executed, the dialog will look something like the following:

Debug and Release Builds

Initially, the program that is created (built) is a debug version. A debug version of executable is useful when writing a program because it has special capabilities that help us figure out problems we might encounter while developing the program. When the program is ready to be used by others, we must create a release version. A debug version of a program is much bigger than a release version, since a debug version has a lot of extra stuff in it. The Visual C++ AppWizard creates separate directories for the debug and release builds. The compiled executable will be put into the corresponding directory, but the directories will also be used for many temporary (intermediate) files. When you are ready to create a release build, use the "Build" menu and choose "Set Active Configuration".