How to get parameters from a dialog, after the dialog has closed?

Hi.
Working with pure Win32 API here; I'm trying to create the following scenario:
- From main window (or a dialog), call int result=DialogBox(...)
- The user sets his stuff in the dialog.
- User presses OK, so EndDialog(hwnd,IDC_OK);
- Back in the main window, switch(result) tells me that the dialog ended with IDC_OK. Now, I want to be able to process the data the user entered in the dialog. GetDlgItemText() or similar functions wouldn't work, as the dialog has already closed, and also because I can't get the dialog's hwnd.
I prefer not to process the data from the dialog's procedure, since it would make things harder and messier. Is there any way to do this?
Thank you.
I prefer not to process the data from the dialog's procedure


This is typically what you do... sorta.

One approach would be to wrap the dialog in another function, which you pass a struct to. Something like this:

1
2
3
4
5
6
7
MyStruct data;

if(RunMyDialog(&data) == IDOK)
{
  // 'data' is filled by the dialog with the info you need
  cout << data.myinfo;  // or whatever
}


To make this work, you basically just put whatever variables you need in the struct and have the dialog fill it before you call EndDialog.


Another, similar approach would be to use a class:

1
2
3
4
5
6
MyDialog dlg;

if(dlg.RunDialog() == IDOK)
{
  cout << dlg.GetInfo(); // or whatever
}


Again, same concept. The Dialog would just set all the data in the appropriate MyDialog object so it can be retrieved after the dialog has closed.


You might notice that this is essentially what common dialogs do. For instance the GetOpenFileName function fills the provided OPENFILENAME structure with data taken from the dialog.
Thank you for answering.
So that's how it generally is done... I'll do it this way then. Thanks.
Topic archived. No new replies allowed.