Basic knowledge about MFC: Main Dialog Box and subdialog box (1)

Source: Internet
Author: User

(It is only for beginners to learn from vs MFC)

In MFC, you can usually click a button to bring up the basic knowledge of a subdialog box. These are the basic knowledge of learning MFC and are also very important. Here I will briefly talk about these knowledge.

1. Set the Main Dialog Box

1. File-create a project (the process I set is editset)-MFC Application-this page uses "based on dialog box"-to complete.

2. Open the dialog box in "resource view" and delete "Todo: place the dialog box controls", "OK", and "exit.

3. Add a button control and an edit control Control in the toolbox. You can right-click the control to set its properties. Its ID is the default one: idc_button1 and idc_edit1. The caption of the set button is "subdialog box", that is, set its name.

4. Run the displayed result as shown in:

2. Set subdialog box

1. Add a new dialog box in "resource view. Right-click "dialog" and select "Add Resource ";

2. In the pop-up dialog box, double-click dialog to create a dialog box. The default name is idd_dialog1;

3. Add an edit control Control in the subdialog box. Its default name is idc_edit1, But it corresponds to the ID name of the subdialog box. You can click the "test dialog box" button in the status bar to test the style after the current dialog box is run.

3. The Main Dialog Box calls the subdialog box (important)

1. Double-click the subdialog box button in the Main Dialog Box to generate its corresponding button function. Generate a function in the xxxdlg. cpp file (XXX is the process name for creating the project.

Voidceditsetdlg: onbnclickedbutton1 ()

{

// Todo: add the control notification handler code here

}

It indicates that clicking this button will execute the response operation in the corresponding function.

2. Double-click the blank area in the idd_dialog1 subdialog box to create a dialog box class for this dialog box. (You can also open the class-oriented add dialog box class)

3. in the displayed "MFC add Class Wizard", enter the class name to be added (Class in the frequently used C + XXX + DLG naming dialog box ), at the same time, the default base class is cdialogex (Extended dialog box class), and subdlg is automatically generated. h \. CPP file.

Note: In vc6, the default dialog base class is cdialog. In vs2012, the default dialog base class is cdialogex (extend extension ). Cdialogex inherits from cdialog and adds some features: change the background image and background color. (The background color of the subdialog box will be set later)

4. In the Main Dialog Box xxxdlg. cpp that you want to call this dialog box, reference the subdialog box class, that is, add:

// Reference subdialog box class

# Include "subdlg. H"

5. Add the code for calling the subdialog box in the button function onbnclickedbutton1 () generated in xxxdlg. cpp.

Voidceditsetdlg: onbnclickedbutton1 ()

{

// Instance-defined sub-Dialog Box class DLG

Csubdlgdlg;

// Set the background color of the subdialog box to yellow
Cdiologex

DLG. setbackgroundcolor (RGB (255,255, 0 ));

// Domodal click to display the corresponding dialog box

If (DLG. domodal () = idok)

{}

}

6. Run as shown in. When you click the subdialog box in the main dialog box, a subdialog box with a yellow background is displayed.

In this way, the basic steps for calling the subdialog box in the Main Dialog Box are implemented. In the yellow and subdialog boxes, this dialog box is displayed when you click the button.

Hope you can understand this basic knowledge of MFC, at the same time this blog introduced the main dialog box to call the sub-dialog box of several steps, for everyone to learn: http://blog.21ic.com/user1/7447/archives/2011/83411.html

Thanks to many blogs, I have learned a lot of knowledge. I hope they will help you! Sorry for any errors.

(By: eastmount)

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.