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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. MFC Dialog Close Handler

MFC Dialog Close Handler

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++visual-studio
5 Posts 3 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.
  • V Offline
    V Offline
    VFaul
    wrote on last edited by
    #1

    I created a dialog-type MFC app in VS 2005. I created a handler for the OK button so I can cleanup prior to exiting. However, if the user clicks the red X in the upper right of the dialog, my cleanup code is not executed. How do I create a handler for when the user quits via the X? Thanks

    M D 2 Replies Last reply
    0
    • V VFaul

      I created a dialog-type MFC app in VS 2005. I created a handler for the OK button so I can cleanup prior to exiting. However, if the user clicks the red X in the upper right of the dialog, my cleanup code is not executed. How do I create a handler for when the user quits via the X? Thanks

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

      Clicking the x acts like the cancel button. You could clean up in a OnCancel() override as well as OnOk(). Mark

      D 1 Reply Last reply
      0
      • M Mark Salsbery

        Clicking the x acts like the cancel button. You could clean up in a OnCancel() override as well as OnOk(). Mark

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        Mark Salsbery wrote:

        You could clean up in a OnCancel() override as well as OnOk().

        Which requires "cleanup" code to be in two spots. Why not do it in just one central spot?


        "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

        "Judge not by the eye but by the heart." - Native American Proverb

        M 1 Reply Last reply
        0
        • V VFaul

          I created a dialog-type MFC app in VS 2005. I created a handler for the OK button so I can cleanup prior to exiting. However, if the user clicks the red X in the upper right of the dialog, my cleanup code is not executed. How do I create a handler for when the user quits via the X? Thanks

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          VFaul wrote:

          How do I create a handler for when the user quits via the X?

          If you want to account for all methods of dismissing the dialog (OK, Cancel, Alt+F4, "X"), handle the WM_DESTROY message.


          "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

          "Judge not by the eye but by the heart." - Native American Proverb

          1 Reply Last reply
          0
          • D David Crow

            Mark Salsbery wrote:

            You could clean up in a OnCancel() override as well as OnOk().

            Which requires "cleanup" code to be in two spots. Why not do it in just one central spot?


            "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

            "Judge not by the eye but by the heart." - Native American Proverb

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

            DavidCrow wrote:

            Why not do it in just one central spot?

            I don't know...why not? That's why I wrote "You could ..." instead of "The only way to do it is ..."

            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