I'm trying to make my child dialog box to be created as a member of the main application class as follows:
class ParentWindow : public CWinApp
{
public:
// Other MFC and user-implemented classes before this line
MiscSettings activeMiscSettings;
public:
ParentWindow();
~ParentWindow();
// Overrides
virtual BOOL InitInstance();
// Implementation
afx_msg void OnAppAbout();
afx_msg void OnMiscSettingsPrompt();
DECLARE_MESSAGE_MAP()
};
I would like to have the dialog box described by MiscSettings to be instantiated when the program starts up, destructed when the program exits, and show/hide according to whether the user select a particular menu option vs. the user clicking a "OK" or "Cancel" button of the dialog box. However, when I implemented the OnMiscSettingsPrompt() handler function as follows:
void ParentWindow::OnMiscSettingsPrompt()
{
float temp;
INT_PTR status = activeMiscSettings.DoModal();
switch(status)
{
case IDOK:
temp = activeMiscSettings.GetSpeed();
break;
case IDCANCEL:
default:
break;
}
}
I cannot access activeMiscSettings.GetSpeed() method b/c the handle is invalid after the DoModal() call. I used this method similar to other examples on showing child dialog boxes. However, the contents of activeMiscSettings were not accessible by ParentWindow class. I know I can put handlers in MiscSettings class to transfer the contents properly in the OK button handler of the edit control and other user control settings to the appropriate class contents of the rest of the application. At this point, I'm not sure what would be the cleanest way of transferring the settings on the child popup dialog to the rest of the application.
Another specification that I am trying to achieve is to have the misc. settings pop-up dialog to show pre-configured settings when it first appears when the user selected the menu option for the first time. After changing some settings and pressing ok, if the user opens the settings window again, I would like to have the current settings show up in the user controls rather than showing the preconfigured settings previously seen in the very first instance. Is this an easily achievable goal?
Thanks in advance for the comments.