Viewing the Newly Created Class

When you use WizardBar to create a new class, WizardBar creates and adds the associated .h and .cpp files to the project. You can view them in the FileView pane of the Project Workspace window; and in the ClassView pane, you can view the iconic representation of the new CPenWidthsDlg class and its default member functions.

In the next topic, Declare a Message-Handling Function for a Dialog Box Control, you’ll use WizardBar to add a message-handling function to the PenWidthsDlg.h and PenWidthsDlg.cpp files. But first, examine the files as they appear as first created.

Header File

Take a minute to examine the initial version of PenWidthsDlg.h. This file contains a declaration for CPenWidthsDlg, the class that implements the Pen Widths dialog box. At this point, the class contains two member functions: a constructor and the DoDataExchange function, which is described later on.

The file contains comment lines that begin //{{AFX_ and //}}AFX_. ClassWizard uses those comment lines to find the sections of code that it maintains. There are three such sections in the header file, each delimited by slightly different comments:

Note   In general, you shouldn’t manually edit any declarations that appear in these sections, or add code here. It is good style, and safe practice, to put any custom declarations in the appropriate group, but below the //}}AFX_ line.

Implementation File

Now examine the initial version of PenWidthsDlg.cpp. This file contains an empty message map and empty function definitions for the constructor and the DoDataExchange member function. For more information on the DoDataExchange function, see Map the Controls to Member Variables later in this lesson.

The CPenWidthsDlg.cpp constructor has a base initializer for CDialog. The CDialog constructor that it invokes creates a modal dialog box, and it takes two parameters: the ID of the dialog resource and a pointer to the parent window. For the first parameter ClassWizard has specified CPenWidthsDlg::IDD. This is an enumerated value that is defined in the AFX_DATA section in the class declaration. This enumerated value is equal to IDD_PEN_WIDTHS, the ID you specified earlier in the topic Create the Dialog Box. Thus the dialog class is associated with the dialog resource you created.

Also notice that the implementation file, like the header file, contains sections delimited by //{{AFX_ and //}}AFX_, into which ClassWizard will insert code later.