http://blog.csdn.net/foreverhuylee/article/details/21707197
There are two things here,
The first case is:
(In a single-document-based application, two new dialog boxes A and B are created, and they are associated with two separate classes)
There is an edit box in dialog A, and a button in a is pressed to pop up dialog B,
b also has an edit box B,
After entering data click OK (id0k) in B, the data in B can be transmitted to a, and can be displayed
Specific implementation methods:
In the Button1 button response function of the A dialog box, add the following code:
void Dlga::onbutton1 () {//Todo:add your control notification handler code HEREDLGB DLGB; The object of the new B dialog box if (Idok==dlgb.domodal ()) {m_stra=dlgb.m_strb; M_stra is the variable associated with the A edit box, M_STRB is the variable}updatedata (FALSE) associated with the b dialog box; }
In the b dialog box, the "OK" ID number is (IDOK), add the following code to the function:
void Dlgb::onok () {//Todo:add extra Validation Heregetdlgitem (IDC_EDIT1)->getwindowtext (M_STRB);//Get the value of the b dialog box, save it in m_ STRB); Cdialog::onok ();}
The second case is:
(In a single-document-based application, two new dialog boxes A and B are created, and they are associated with two separate classes)
Enter data in a edit box in a dialog box, click OK (IDOK) button, the A dialog box disappears
Opens the b dialog box, where the B edit box shows the data from the original a
The implementation method is as follows:
1. In the program's app class, add a member variable, which is equivalent to the whole program's global variables, all classes can be used
float MyFlow;
2. In the OK button of the a dialog, enter the code:
void Cinitial::onok () {//Todo:add extra Validation hereupdatedata (TRUE); Cenvirmonibeta1app *papp= (Cenvirmonibeta1app *) AfxGetApp ();p app->myflow=m_iflow; M_iflow is a edit box associated with the variable Cdialog::onok ();}
3. In the OnPaint function of the b dialog box (this function needs to add WM_PAINT itself), add the following code:
Cenvirmonibeta1app *papp= (Cenvirmonibeta1app *) AfxGetApp ();m_flow=papp->myflow; UpdateData (FALSE);
This will achieve the goal ~ ~
If the parent dialog box and the Child dialog box are passed, use the following method:
Cparentdlg *parent= (cparentdlg*) GetParent ();p Arent->getdlgitem ()->setwindowtext ()
Cparetdlg corresponds to your a dialog box class.
-
Point to the parent dialog box, and then you get the content of B, which is shown in a
Data passing between two dialog boxes in MFC