Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Closing a dialog box

Closing a dialog box

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    llp00na
    wrote on last edited by
    #1

    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, 2007

    llp00na

    B 1 Reply Last reply
    0
    • L llp00na

      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, 2007

      llp00na

      B Offline
      B Offline
      bob16972
      wrote on last edited by
      #2

      Is this a modal or modeless dialog box? Modeless dialogs require some additional thought and consideration.

      L 1 Reply Last reply
      0
      • B bob16972

        Is this a modal or modeless dialog box? Modeless dialogs require some additional thought and consideration.

        L Offline
        L Offline
        llp00na
        wrote on last edited by
        #3

        I am using a modeless dialog box. Would you also please explain how does it differ when using modal dialog? Thank you

        llp00na

        B 1 Reply Last reply
        0
        • L llp00na

          I am using a modeless dialog box. Would you also please explain how does it differ when using modal dialog? Thank you

          llp00na

          B Offline
          B Offline
          bob16972
          wrote on last edited by
          #4

          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

          L 1 Reply Last reply
          0
          • B bob16972

            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

            L Offline
            L Offline
            llp00na
            wrote on last edited by
            #5

            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

            B 1 Reply Last reply
            0
            • L llp00na

              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

              B Offline
              B Offline
              bob16972
              wrote on last edited by
              #6

              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.

              L 1 Reply Last reply
              0
              • B bob16972

                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.

                L Offline
                L Offline
                llp00na
                wrote on last edited by
                #7

                Thank you, I am grateful

                llp00na

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups