(It is only for beginners to learn from vs MFC)
Access the content of "MFC basics: Main Dialog Box and subdialog box (1 )"
In the "Basic knowledge of MFC: Main Dialog Box and subdialog box (1)", the content is output in the edit control (edit box) control, I mainly want to explain how to implement some operations in the created subdialog box: that is, to add the oninitdialog initialization function operation, here the operations vs2012 and VC ++ 6.0 are slightly changed.
I. Content output in the edit box of the Main Dialog Box
1. Find the oninitdialog () initialization function in the Main Dialog Box xxxdlg. cpp, and add the code displayed in edit after the function comment "// todo: add additional initialization code here.
// Obtain the edit box ID and display the content
Getdlgitem (idc_edit1)-> setwindowtext (_ T ("displayed in edit of the Main Dialog Box "));
As shown in:
If you want to output the variable value after Chinese characters, use cstring: Format ()
Cstring STR;
Str. Format (_ T ("value = % d"), 1000
);
Getdlgitem (id_edit)-> setwindowtext (STR );
2. Shows the running result:
Note: _ T () indicates the Unicode-encoded text. If it is not Unicode, _ T () is not used. Generally, the check box before "use Unicode library" is removed during project creation.
3. the edit box provides two ways to wrap a line:
Input line feed: Set the edit box attributes: mutilines-> true; want return-> true
Output line feed: Set the control property to mutilines-> true; Output string Line Break "\ r \ n" (Press enter to line feed) instead of "\ n ".
Note: The method used to set Edit to read-only is to set its attribute read only-> true. You can also add the cedit class variable m_edit in the Class Wizard by calling the function to set m_edit.xxx.
Ii. Content output in the edit box of the subdialog box
Generally, there is no oninitdialog () function in the subdialog box created by MFC. You need to add it manually by opening the Class Wizard.
The method in vc6 is: View-> Create Class Wizard (shortcut: Ctrl + W Open Class Wizard) -> message maps-> select classname-> ID of the objects IDs selection dialog box-> wm_initdialog in messages-> click Add function.
References: http://blog.163.com/youthpasses@yeah/blog/static/161849228201141510112949/
1. Add the oninitdialog () function to the subdialog box: In the vs2012 Class Wizard (shortcut: Ctrl + Shift + x) Class
In wizard, wm_initdialog in vc6 does not respond to messages. Instead, the message is added using the oninitdialog () function in the virtual function. For example, double-click oninitdialog to add the initialization function.
(Note: add this function to the csubdlg subdialog box class)
2. Double-click oninitdialog in "overwritten virtual functions" to automatically create an initialization function in subdlg. cpp, as shown in, I keep a return true.
3. Add code
Getdlgitem (idc_edit1)-> setwindowtext (_ T ("properties displayed in the edit box of the subdialog Box \ r \ n "));
4. Shows the running result:
NOTE: If error: "ddx_control" appears, parameter 3 cannot be converted from cstring to cwnd & see: http://blog.csdn.net/eastmount/article/details/9052735
I would like to thank many bloggers who have learned a lot. I hope they can help you! Sorry for any errors.
(By: eastmount)