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. In MFC, which event works when user clicks on close button?

In MFC, which event works when user clicks on close button?

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
8 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
    ayca
    wrote on last edited by
    #1

    I need to handle and override the event that works when user presses the close button on the upper right (on the left of minimize and maximize buttons)? Thanks;)

    G C J B 4 Replies Last reply
    0
    • A ayca

      I need to handle and override the event that works when user presses the close button on the upper right (on the left of minimize and maximize buttons)? Thanks;)

      G Offline
      G Offline
      Gary R Wheeler
      wrote on last edited by
      #2

      That event is signaled via a WM_SYSCOMMAND notification message, with the wParam value set to SC_CLOSE.


      Software Zen: delete this;

      1 Reply Last reply
      0
      • A ayca

        I need to handle and override the event that works when user presses the close button on the upper right (on the left of minimize and maximize buttons)? Thanks;)

        C Offline
        C Offline
        Curi0us_George
        wrote on last edited by
        #3

        You could probably just handle the WM_CLOSE message and accomplish what you want.

        A 1 Reply Last reply
        0
        • A ayca

          I need to handle and override the event that works when user presses the close button on the upper right (on the left of minimize and maximize buttons)? Thanks;)

          J Offline
          J Offline
          Joe Woodbury
          wrote on last edited by
          #4

          I agree with Curious_George since your app may be closed by other methods, such as right clicking on the app in the task bar and selecting close or using Alt-F4. Otherwise, use Spy++ to see what the message is. Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke

          1 Reply Last reply
          0
          • C Curi0us_George

            You could probably just handle the WM_CLOSE message and accomplish what you want.

            A Offline
            A Offline
            ayca
            wrote on last edited by
            #5

            Nope, it didn't work out:(

            C 1 Reply Last reply
            0
            • A ayca

              Nope, it didn't work out:(

              C Offline
              C Offline
              Curi0us_George
              wrote on last edited by
              #6

              Then either I'm not sure what you're trying to accomplish, or you went about it the wrong way. If you could post a code snippet (the part that didn't work), or if you could explain exactly what you are wanting to accomplish, then either myself or someone else would surely be able to help you.

              1 Reply Last reply
              0
              • A ayca

                I need to handle and override the event that works when user presses the close button on the upper right (on the left of minimize and maximize buttons)? Thanks;)

                B Offline
                B Offline
                Blake Miller
                wrote on last edited by
                #7

                I process the WM_CLOSE message and override the virtual OnCancel() if it is a dialog to catch the close attempts. If you do not call the base class for either of those, your window will not close.

                A 1 Reply Last reply
                0
                • B Blake Miller

                  I process the WM_CLOSE message and override the virtual OnCancel() if it is a dialog to catch the close attempts. If you do not call the base class for either of those, your window will not close.

                  A Offline
                  A Offline
                  ayca
                  wrote on last edited by
                  #8

                  OK, I did the same. The window closes there is no problem with that. But the problem is; I am using a process which uses soundcard inside the program, I play some voice on soundcard, and I want to stop it before user presses close button and closes application. I have the function that closes my process, I implemented an event handler to the exit event on exit menu item, and it worked. I wanted to do the same for event that works when close button is pressed, but this time my application window closes but the process does not, it still works. And when I hook up Task Manager i see that my application is also still working, which shows me that my window is destroyed but the application is still running.

                  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