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. Diff. between DestroyWindow() and EndDialog()

Diff. between DestroyWindow() and EndDialog()

Scheduled Pinned Locked Moved C / C++ / MFC
question
7 Posts 5 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.
  • A Offline
    A Offline
    Abhijeet Pathak
    wrote on last edited by
    #1

    i want to execute some code when a dialog is destroyed, but the code in DeatroyWindow() function doesn't executes when i use EndDialog() but executes when i use DestroyWindow(). What is the diff. between these two and which should be best to use?

    R N R M 4 Replies Last reply
    0
    • A Abhijeet Pathak

      i want to execute some code when a dialog is destroyed, but the code in DeatroyWindow() function doesn't executes when i use EndDialog() but executes when i use DestroyWindow(). What is the diff. between these two and which should be best to use?

      R Offline
      R Offline
      Rage
      wrote on last edited by
      #2

      I'd go for DestroyWindow(), or OnOK, OnCancel if you are using MFC. I've never done anything with EndDialog().

      http://www.readytogiveup.com/[^] - Do something special today. http://www.totalcoaching.ca/[^] - Give me some feedback about this site !

      1 Reply Last reply
      0
      • A Abhijeet Pathak

        i want to execute some code when a dialog is destroyed, but the code in DeatroyWindow() function doesn't executes when i use EndDialog() but executes when i use DestroyWindow(). What is the diff. between these two and which should be best to use?

        N Offline
        N Offline
        nitin3
        wrote on last edited by
        #3

        i use EndDialog()for modal dialog boxs and DestroyWindow() for modeless dialog boxes :-)

        1 Reply Last reply
        0
        • A Abhijeet Pathak

          i want to execute some code when a dialog is destroyed, but the code in DeatroyWindow() function doesn't executes when i use EndDialog() but executes when i use DestroyWindow(). What is the diff. between these two and which should be best to use?

          R Offline
          R Offline
          Rajkumar R
          wrote on last edited by
          #4

          Dialog Window Created by DialogBox, DialogBoxIndirect .. should be destroyed using EndDialog. OnOk, OnCancel internally uses EndDialog. And surely OnDestroy() will get called when EndDialog is used. Are u using MFC?

          1 Reply Last reply
          0
          • A Abhijeet Pathak

            i want to execute some code when a dialog is destroyed, but the code in DeatroyWindow() function doesn't executes when i use EndDialog() but executes when i use DestroyWindow(). What is the diff. between these two and which should be best to use?

            M Offline
            M Offline
            Mark Salsbery
            wrote on last edited by
            #5

            DestroyWindow is something you call, not something that gets called. In MFC, CWnd::DestroyWindow() is virtual. If you've overridden it, your override will get called at the end of DoModal() but that doesn't make it a good place to do something when a dialog is destroyed. That's a side effect of the way MFC does modal dialogs. I think a better place is any time at or after you receive a WM_NCDESTROY message. Mark

            Mark Salsbery Microsoft MVP - Visual C++ :java:

            A 1 Reply Last reply
            0
            • M Mark Salsbery

              DestroyWindow is something you call, not something that gets called. In MFC, CWnd::DestroyWindow() is virtual. If you've overridden it, your override will get called at the end of DoModal() but that doesn't make it a good place to do something when a dialog is destroyed. That's a side effect of the way MFC does modal dialogs. I think a better place is any time at or after you receive a WM_NCDESTROY message. Mark

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              A Offline
              A Offline
              Abhijeet Pathak
              wrote on last edited by
              #6

              ya... i'm too thinking that... because i've placed code in overridden DestroyWindow() function but it never gets called if EndDialog() method is used to close the dialog box. :(

              M 1 Reply Last reply
              0
              • A Abhijeet Pathak

                ya... i'm too thinking that... because i've placed code in overridden DestroyWindow() function but it never gets called if EndDialog() method is used to close the dialog box. :(

                M Offline
                M Offline
                Mark Salsbery
                wrote on last edited by
                #7

                Abhijeet Pathak wrote:

                but it never gets called if EndDialog() method is used to close the dialog box.

                Looking at the source code, that is correct :) Note that when you receive WM_NCDESTROY, child windows (controls etc) have been destroyed. If you need access to the controls before they are destroyed, respond to WM_DESTROY which is sent before WM_NCDESTROY. Mark

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                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