Transferred from: http://www.jizhuomi.com/software/149.html
dialog box, we should be familiar with, in most of our commonly used software has a dialog box interface, for example, 360 security defender's main interface is actually a dialog box, but it did a lot of art work, it greatly beautify.
There are two major steps in creating a dialog, first, creating a dialog resource, which includes creating a new dialog box template, setting dialog properties, and adding various controls for the dialog box, and second, building a dialog class that includes new dialog classes, adding control variables and message handlers for controls, and so on.
This section first tells you how to create a dialog box template and Set dialog box properties.
Creating a dialog-based application framework
The previously created HelloWorld program is a single-document application, generating a variety of windows, if you use it to create a dialog box may be a bit complex, the simple understanding of the dialog box has a little impact, so here to create a dialog-based application, to implement the function of addition operations. Creating steps is similar to a single document application, with the following simple steps:
1. Select the menu item file->new->project, and the New Project dialog box pops up.
2. In the left panel, under Visual C + + installed templated Select MFC, select MFC Applicationin the middle window, and then type the project name in the name edit box below, this example is named " addition, set the save path for the project in the location edit box. Point "OK".
3. Click "Next" to "Application Type" dialog, under Application type select Dialog based ( based on dialog box), other Use default settings, click "Finish".
As we can see in the Solution Explorer view, this project has fewer files than a single document application, there are three main classes in Class View: CAboutDlg, Cadditionapp, and Cadditiondlg. CAboutDlg is the "about" dialog class for the application, Cadditionapp is a class derived from CWinApp, Cadditiondlg is the main dialog class, and the main dialog box is the main interface that is displayed after the application runs.
Note: If you cannot find a view such as Solution Explorer or Class View in VS2010, you can find the corresponding view option in the menu item view. It is already explained in the introduction of VS2010.
In Resource view, you can see the resource tree for the project addition, expand Addition.rc, with four subkeys: Dialog (Dialog), icon (icon), string table (string tables), and version (versions). then expand the DIALOG entry with the following two dialog template IDs: Idd_aboutbox and Idd_addition_dialog, which are templates for the About dialog box, which is the template for the main dialog box. An ID is a unique identifier for a resource, essentially an unsigned integer, and the integer value represented by the general ID is defined by the system and we do not need to interfere .
dialog box Templates
Visible for the main dialog box, the Create New dialog box template in the first step of the Create dialog box has been automatically completed by the system. If you add a dialog box to create a new dialog template, you need to right -click on the "Dialog" node of the Resource View and select "Insert Dialog" in the right-click menu, a new dialog template will be generated and the ID will be automatically assigned.
Double-click an ID in the Resource View's resource tree to display the corresponding resource interface within the middle area. When you double-click Idd_addition_dialog, the Addition dialog box template is displayed in the middle area. Such as:
Setting dialog Box Properties
Right-clicking on the addition dialog template and selecting Properties in the right-click menu displays a list of properties for the dialog box in the right-hand panel. Such as:
Here is a brief description of several properties that are used frequently, and a description of the property setting for the addition dialog box.
1.ID: Dialog ID, uniquely identifies the dialog resource, can be modified. Here is Idd_addition_dialog, we do not modify it.
2.Caption: dialog box title. The default here is addition, which we'll change to "addition Calculator".
3.Border: Border type. There are four types: None, Thin, resizing, and dialog Frame. We use the default dialog Frame.
4.maximize: Whether to use the Maximize button. We use the default false.
5.Minimize: Whether to use the Minimize button. Likewise we use the default false.
6.Style: dialog box type. There are three types: Overlapped (overlapping window), popup (pop-up window), and child (sub-window). Pop-up windows are more common. We use the default popup type.
7.System Menu: Whether to include the menu item in the upper-left corner of the title bar, including move, close, etc. We use the default true.
8.TitleBar: Whether it has a title bar. We use the default true.
9. Font(size): font type and font size. If you modify it to a non-system font, the use system automatically changes to false. The font (Size) is automatically set to the system font if the use system turns false and it is modified to true. Here we use the default system font.
According to the above instructions, we have only modified the title property. The interface after we run this program is as follows:
VS2010-MFC (dialog box: Create dialog box template and Modify dialog box properties)