I’ve used MFC dialogs before where you do:
EnterNameDlg dlg;
dlg.DoModal();
string str = dlg.GetName();
However a dialog I have now actually looks at a list-box control in such a method and it’s not working. Although the class instance clearly exists after DoModal(), does the actual dialog get destroyed? I noticed calling DoModal() a 2nd time leads to OnInitDialog() also being called again which seems to support this theory, the dialog is recreated from the template rather than simply made visible the 2nd time.
Yes,
DoModalcreates a dialog on each call and destroys the window before returning.Only the data members will still be valid. Of course, you can add more data members in your
EnterNameDlgclass if you want to collect data during dialog’s lifetime.As soon as the dlg gets out of scope, everything will be deallocated.