I have a MS Visual C++ 2005 project where I am trying to have a main dialog box with a section devoted to displaying selectable subform dialogs boxes. Each subform will be of the same size but have a different layout. The selection is performed using a combo-box control. I searched on the best way to implement this functionality and I came across this class that someone developed in 1999 for handling child dialogs within a main dialog:
http://www.codeproject.com/KB/dialog/childdlg.aspx
With the additional modification:
http://www.codeproject.com/KB/dialog/childdlg.aspx?msg=1287#xx1287xx
The code works quite well for selecting and displaying the various subforms but I don’t seem able to pass data from one subform to another. Specifically each subform is comprised of several edit controls. I would like to have the user be able to enter a value in an edit control on Subform #1 and for this value to be echoed in an edit control or static text control on Subform #2.
I tried implementing this by using a member function of the subform dialog class (named CSubFormType and a subclass of CDialog) that would execute upon killing the focus to the data input edit control (i.e. Box1a).
void CSubFormType::OnEnKillfocusBox1a(){
p2WndControl = (CWnd*)(GetDlgItem(IDC_Box1a)); //Get pointer to the control dialog box for data entry
//Inserted here some specific code used to place data entered into IDC_Box1a into extern wchar_t outstr[32]
SetDlgItemText (IDC_Box1b, outstr); //Echo data entered in IDC_Box1a to IDC_Box1b on same Subform #1
SetDlgItemText (IDC_Box2, outstr);//Echo data entered in IDC_Box1a to IDC_Box2 on different subform, Subform #2
}
The message map for CSubFormType meant to call OnEnKillfocusBox1a directly is:
ON_EN_KILLFOCUS(IDC_Box1a, &CSubFormType:: OnEnKillfocusBox1a)
Or indirectly by:
ON_BN_CLICKED(IDOK, &CSubFormType::OnBnClickedOk) // CSubFormType::OnBnClickedOk then calls OnEnKillfocusBox1a
The problems I am having are:
1) ON_BN_CLICKED(IDOK, &CSubFormType::OnBnClickedOk) does not get called upon hitting Enter key after typing data into Box1a. Instead the OnBnClickedOk member function of the main dialog box gets called instead.
2) When CSubFormType::OnEnKillfocusBox1a does get executed (by mouse click elsewhere) it is able to echo the value entered in Box1a to Box1b on the same Subform #1 but will not echo the value to Box2 on Subform #2.
Any guidance as to what I need to do to resolve these problems or a better approach to implementing the same general functionality would be greatly appreciated.
Combo box selection member function for main dialog box being used:
void CMain::OnCbnSelchange() { int selection;
selection = ((CComboBox*)GetDlgItem(IDC_Select))->GetCurSel();
switch(selection)
{
case 0: // Select Subform 1
//Do nothing
break;
case 1: // Select Subform 2
SetDlgItemText (IDC_Box2, outstr); //Set Box2 text on Subform #2
break;
}
m_SubForms.ShowSubForm(selection);
}