Home > Software engineering >  MFC dialog - how to get child dialog the default value of each control, please answer
MFC dialog - how to get child dialog the default value of each control, please answer

Time:11-25

Due to this problem bothering me for a long time, so I write the detailed point, ask and answer
Manufacturer to provide the demo, is in the main dialog box for the main form of the various controls on the default values, such as some initialization time to write in the address what of, equipment type, etc.;
Now I want to change in the child form, is I now have a main form, set up a button on the main form, click on this button, you can pop up child form, and then add in child form manufacturer to provide the code, add code when they encounter a problem;
The original code used in a statement:=(CAtPipDlg *) AfxGetApp CAtPipDlg * DLG () - & gt; GetMainWnd (); CAtPipDlg is main form class, through the words, write a lot of value in the pointer DLG, some of them I need the list of most control control, at the same time I also want to write something here;
But now I want to use in the child form, in using the words above, completely get less than child form the default values of each control, and the corresponding w_hWnd CListCtrl class handles the corresponding address is 0 x00000000, if I want to be in child form similar to that in the CAtPipDlg=(CAtPipDlg *) * DLG AfxGetApp () - & gt; GetMainWnd (); The function of the words, how can I modify, o Daniel,

CodePudding user response:

I've tried GetForegroundWindow (); The GetActiveWindow (); Take less than the desired result;

CodePudding user response:

Use the Create Create (non-modal) or DoModal (modal)
Similar
DLG CAtPipDlg *=new CAtPipDlg;
DLG - & gt; DoModal ();
The delete DLG.

CodePudding user response:

refer to the second floor zgl7903 response:
Create (non-modal) or using the Create DoModal (modal)
Similar
DLG CAtPipDlg *=new CAtPipDlg;
DLG - & gt; DoModal ();
The delete DLG.

This a few words of code where to add? Is child form inside or main form inside?

CodePudding user response:

Pop-up child form after the child form is the control's container, must get through child form controls

CodePudding user response:

Tried it once, be suddenly thought of the idea, the problem is solved;
Solving process is as follows:
Mainly explained first CAtPipDlg form class, CTestDlg for child form class;
If you want to be in the form of a thread function, still the default value of the various controls for child form, or use the List control control receive and display the refresh data;
First of all, in your main form of header files, such as CAtPipDlg. H of adding CTestDlg CAtPipDlg m_testdlg; (to the Public),
Then, I am here by clicking a button pop-up dialog box, use the two words: CTestDlg DLG; DLG. DoModal ();
Now stop using the above two sentences, in order to use these two words: m_testdlg. Create (IDD_TEST_DIALOG, this); M_testdlg. ShowWindow (SW_SHOW); Including IDD_TEST_DIALOG is your child form ID (see form properties will know),
Then, in your thread function, still use CAtPipDlg=(CAtPipDlg *) * DLG AfxGetApp () - & gt; GetMainWnd (); This sentence, you will find that the members of the DLG m_testdlg already contains a child form above all the default values, alacrity. May express unclear; Simple point code below:

First in CAtPipDlg. H add:
The class CAtPipDlg: : public CDialog
{
/...
Public:
CTestDlg m_testdlg;
/...

}


You click button pop-up child form function:



in the CPP in CAtPipDlg.

Void CAtPipDlg: : for the ()
{
M_testdlg. Create (IDD_TEST_DIALOG, this);
M_testdlg. ShowWindow (SW_SHOW);//if the program crashes, press the button for the second time work on it ourselves, 0.0
}

The child form CTestDlg. CPP, add
Void CTestDlg: : ReciveThread ()//or function you need
{
=(CAtPipDlg *) AfxGetApp CAtPipDlg * DLG () - & gt; GetMainWnd ();
DLG - & gt; M_testdlg;//this is what I want, then can carry out a series of operations, la la la.
}


Above level to like me more bad of the classmate,

CodePudding user response:

You can be in child Windows in a certain function to the main window to send the message, to pass the data related to the main window
  • Related