Closing a dialog box
-
Dear All; I have noticed that once I close a dialog box from the (x) icon -top most right corner-, the dialog is not destroyed. By the way, this dialog is a child of a another main window. How do i destroy a child window only whenever the user tries to close it from x icon? Is it enough to add OnClose() event handler to the dialog box? and what should it contain? I have tried the code below but this resulted in the closure of the whole application which i dont want:
void ChildDlg::OnClose() { // TODO: Add your message handler code here and/or call default PostQuitMessage(WM_QUIT); CDialog::OnClose(); }
Thank you -- modified at 10:40 Friday 13th April, 2007llp00na
-
Dear All; I have noticed that once I close a dialog box from the (x) icon -top most right corner-, the dialog is not destroyed. By the way, this dialog is a child of a another main window. How do i destroy a child window only whenever the user tries to close it from x icon? Is it enough to add OnClose() event handler to the dialog box? and what should it contain? I have tried the code below but this resulted in the closure of the whole application which i dont want:
void ChildDlg::OnClose() { // TODO: Add your message handler code here and/or call default PostQuitMessage(WM_QUIT); CDialog::OnClose(); }
Thank you -- modified at 10:40 Friday 13th April, 2007llp00na
-
Is this a modal or modeless dialog box? Modeless dialogs require some additional thought and consideration.
-
I am using a modeless dialog box. Would you also please explain how does it differ when using modal dialog? Thank you
llp00na
A modal dialog is invoked with DoModal() and it does not return until the dialog is dismissed effectively preventing interaction with the owner. A modeless is created with Create() and returns immediately leaving the owner AND the dialog open for interaction. Referencing Jeff Prosise's book I get... Modeless: 1) Dismiss the dialog using DestroyWindow and not EndDialog() 2) Do not allow CDialog::OnOK or CDialog::OnCancel because both call EndDialog() 3) Instantiated with "new" 4) Override CDialog::PostNCDestroy in the derived dialog class and execute "delete this" Modal: 1) Dismiss the dialog with EndDialog(). Refer to Mr. Sivakumar's views on modality[^] for additonal info 2) Instantiated on the stack
-
A modal dialog is invoked with DoModal() and it does not return until the dialog is dismissed effectively preventing interaction with the owner. A modeless is created with Create() and returns immediately leaving the owner AND the dialog open for interaction. Referencing Jeff Prosise's book I get... Modeless: 1) Dismiss the dialog using DestroyWindow and not EndDialog() 2) Do not allow CDialog::OnOK or CDialog::OnCancel because both call EndDialog() 3) Instantiated with "new" 4) Override CDialog::PostNCDestroy in the derived dialog class and execute "delete this" Modal: 1) Dismiss the dialog with EndDialog(). Refer to Mr. Sivakumar's views on modality[^] for additonal info 2) Instantiated on the stack
-
Thanx, Would the following destroy the dialog window?
void ChildDlg::OnClose() { // TODO: Add your message handler code here and/or call default CDialog::OnClose(); }
llp00na
To the best of my knowledge, no. However, maybe I'm misunderstanding what you are trying to do. Either way, my point was to get you to reflect on whether you really needed to use a modeless dialog in the first place because there is some extra work and maintenance, not to mention the need to communicate that whoever "owns" the dialog should not use the pointer once the dialog executes "delete this". Modeless dialogs are kinda messy at best, imo. From an MFC standpoint, I think I listed most of the pertinent information one should know if they are determined to use modeless dialogs in their app. I hope that helps.
-
To the best of my knowledge, no. However, maybe I'm misunderstanding what you are trying to do. Either way, my point was to get you to reflect on whether you really needed to use a modeless dialog in the first place because there is some extra work and maintenance, not to mention the need to communicate that whoever "owns" the dialog should not use the pointer once the dialog executes "delete this". Modeless dialogs are kinda messy at best, imo. From an MFC standpoint, I think I listed most of the pertinent information one should know if they are determined to use modeless dialogs in their app. I hope that helps.