Recently wrote an MFC interface program, the main interface is based on a single document view structure, but requires edit control to pass a data value to a variable, that is, you need to manually set a parameter. In a dialog-based interface, it is easy to pass a data to the program through the edit control controls. Drag an Edit control to the dialog box directly in the toolbox, modify the ID of the control, and add a variable to it, noting that the base class you belong to is selected.
But not in a single document interface, because the control is not found in the Toolbox in Resource view, so to manually enter data values in the MFC interface based on the document structure, the best way to do that is to set a button in the menu, and a dialog box pops up in the response function of the button, passing the data value in the dialog box with the edit control. The software interface for this document structure can be used when there are many parameters that need to be delivered manually.
first, the steps to pop up a dialog box in a document-structured interface:
1, open the Project resource View->dialog-> right click-> Select Insert Dialog. This will create a new dialog box.
2. Add a class for the newly inserted dialog box. Also in the resource view, move the cursor to the newly inserted dialog box-> Right-click-> Click "Add Class" and set the class name in the Pop-up Class Wizard dialog box, note: The generic class name starts with uppercase letter C.
3, after the completion of the addition of the project directory, will be more than one. h and a. cpp file, here take Dlg.h and dlg.cpp for example, the class name is Cdlg convenient below.
4, in the original document view of the Doc.h file, including Dlg.h file, that is, #include "dlg.h" can be. In the Doc's class definition, add a Cdlg class object (modal dialog) of the public type, or an object pointer (modeless dialog box).
5. Select a button in the menu of the document structure view, right-click to add an event handler (note Select the class that belongs to, the class that is typically doc), and use the DoModal function to pop up the dialog box in the response function. Routines:
void Xxdoc::onxx ()
{
//cdlg0 is a class member
if (Cdlg0.domodal ())
{
}
} of the newly added Cdlg class for the Doc class
The above pop-up is the modal dialog box. Re-description of modal and modeless.
6, the compiler project, in the Document view Interface menu, click the button in 5, you can pop-up 1 inserted in the dialog box.
second, use the edit control controls to pass data:
1, in the inserted dialog box, drag an edit control to the interface in the Toolbox, right-click to add a variable to it, the general variable begins with m_, click OK.
2, note that this time in the Dlg.h file in the definition of DLG class will have just added this variable.
3. Double-click the "OK" button on the new Insert dialog and, in the message handler function of the OK button, add the UpdateData (TRUE) statement to pass the value of the edit control to the corresponding variable for the edit control.
void Cdlgparaset::onbnclickedok ()
{
//TODO: Add control Notification Handler code
updatedata (TRUE) here;
Cdialogex::onok ();
}
4. In the button message function in step 5, assign the value of the edit control variable to the variable you want.
void Xxdoc::onxx ()
{
//cdlg0 is a class member of the newly added Cdlg class for the Doc class
if (Cdlg0.domodal ())
{
int data = Cdlg0.m_data ; M_data the variable name added for the edit control controls, data needs to accept the value of the variable
}
}
5, through the compilation, you can click in the Document View menu button, pop-up dialog box, enter data, click OK, the corresponding data passed to the DOC project.