Hello. I am programming an application in which a main dialog needs to
know the data in other dialogs (opened by clicking buttons in the main
dialog). There are a lot of CEdit's and doing that via Class Wizard
(with member variables for each dialog class) is quite tiring.

If there were just one dialog I would get data in a loop:

void MainDialog::f() {
...
for(int id = IDC_FIRSTID; id<=IDC_LASTID; id++)
this->GetDlgItemText(id,str);
...
}

But the CEdit's are in other dialogs, so their data is lost when you
close them. That is, I can't do the following:

void MainDialog::f() {
...
for(int id = IDC_FIRST_ID_DLG1; id<=IDC_LAST_ID_DLG1; id++)
dlg1.GetDlgItemText(id,str);
...
}



How can I do that without using member variables?

Thanks.

Re: Data between dialogs by Scott

Scott
Wed May 11 08:05:12 CDT 2005

Nafai wrote:

> Hello. I am programming an application in which a main dialog needs to
> know the data in other dialogs (opened by clicking buttons in the main
> dialog). There are a lot of CEdit's and doing that via Class Wizard
> (with member variables for each dialog class) is quite tiring.
>
> If there were just one dialog I would get data in a loop:
>
> void MainDialog::f() {
> ...
> for(int id = IDC_FIRSTID; id<=IDC_LASTID; id++)
> this->GetDlgItemText(id,str);
> ...
> }
>
> But the CEdit's are in other dialogs, so their data is lost when you
> close them. That is, I can't do the following:
>
> void MainDialog::f() {
> ...
> for(int id = IDC_FIRST_ID_DLG1; id<=IDC_LAST_ID_DLG1; id++)
> dlg1.GetDlgItemText(id,str);
> ...
> }
>
>
>
> How can I do that without using member variables?
>
> Thanks.

You can use an array of CEdit's and an array of CString's to do the same
kind of loop in the dialog's OnOK(). A similar loop in DoDataExchange
calls DDX_Control to initialize the CEdit's.

for (int i = 0; i < numedits; i++)
m_edit[i].GetWindowText(...);

--
Scott McPhillips [VC++ MVP]