I have a MFC project I am working on. In the main dialog box there is a button to open a child dialog box for some user input. This data is then set to variables in the parent dialog box when OK is clicked in the child box. This bit all works perfectly fine.
Right now the text boxes in the child box initialize to preset values in the OnInitDialog() of the child dialog box. I would like these values to initialize to whatever the variable they are connected to in the parent dialog box currently is.
So, for example I have a text box that sets in integer variable called sampleCount. In the child dialog box I have (just showing the code for this variable)
void ChildBox::DoDataExchange(CdataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_SAMPCOUNT, sampCnt);
}
BOOL FNameIn::OnInitDialog()
{
CDialog::OnInitDialog();
GetDlgItem(IDC_SAMPCOUNT)->SetWindowTextA("1");
return TRUE;
}
Then in the parent dialog box I have
void ParentDialog::OnInput()
{
ChildBox dlg;
if (dlg.DoModal() == IDOK)
{
sampleCount = dlg.sampCnt;
}
}
As I said, this code all works, but every time I open the ChildBox the sampleCount text box is set to 1. If I type in 20, then hit ok and set the sampleCount variable in ParentDialog to 20 I want it to show a 20 in the text box next time I open the child dialog box. The variable could also be set automatically by another function in ParentDialog, so the last value entered in child dialog isn't always correct, it needs to use whatever is currently the value of the variable sampleCount in ParentDialog.
I feel like this should be pretty straight forward but I can't quite figure it out, thanks for the help.