Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 12: Dialog-Based Windows Visual C++ and MFC Fundamentals


};

BOOL CExerciseApp::InitInstance()
{
return TRUE;
}

CExerciseApp theApp;


  1. Save All


12.1.2..Dialog Box Creation...........................................................................


To create a dialog box in MSVC, from the Add Resources dialog box, simply select the
Dialog node and click New. Then you can manipulate its characteristics using the
Properties window.

In reality, unlike most or all other controls, a dialog box requires some preparation before
actually programmatically creating it. While most other controls can be easily added to a
host, a dialog box must already “exist” before it is asked to display. Based on this, a
dialog box can first be manually created as a text file. This is called a resource file. In the
file, you create a section for the dialog box. This section itslef is divided in lines each
serving a specific purpose.

Like most other controls, a dialog box must be identified. The identifer of a dialog box
usually starts with IDD_ wher the second D stands for dialog. An example of a dialog
identifer would be IDD_SCHOOL_SURVEY. Therefore, the section of the dialog box in
the file can start with:

IDD_SCHOOL_SURVEY

At design time, the identifier of the dialog box is specified using the ID combo box.

When having our introduction to controls, we saw that the Win32 library provides a
series of ready-made names of classes to create controls. In the same way, a dialog box
has two types of classes used to create a dialog box. The DIALOG statement was
primarily used to create a dialog box. It has been updated and replaced by the
DIALOGEX name. Therefore, to indicate in the file that the section you are creating is
for a dialog box, type DIALOGEX. Here is an example:

IDD_SCHOOL_SURVEY DIALOGEX

Practical Learning: Creating a Dialog Box



  1. To create a dialog box, on the main menu, click Insert -> Resource... or Project ->
    Add Resource...

Free download pdf