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. Program closing

Program closing

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

    How could I handling the process of 'Program closing' using Visual C++ (MFC) I want the program to 'decide' how to quit or when to quit.

    M 1 Reply Last reply
    0
    • L lisoft

      How could I handling the process of 'Program closing' using Visual C++ (MFC) I want the program to 'decide' how to quit or when to quit.

      M Offline
      M Offline
      Mike Danberg
      wrote on last edited by
      #2

      You have to override the WM_QUIT and WM_CLOSE messages. The WM_QUIT message is the one that terminates the entire application. WM_CLOSE is sent when exiting a window such as a dialog. An example of how to manually quit the program would be PostMessage(WM_QUIT, 0, 0) Similarly WM_CLOSE can be used as well. Hope that helps.

      L 1 Reply Last reply
      0
      • M Mike Danberg

        You have to override the WM_QUIT and WM_CLOSE messages. The WM_QUIT message is the one that terminates the entire application. WM_CLOSE is sent when exiting a window such as a dialog. An example of how to manually quit the program would be PostMessage(WM_QUIT, 0, 0) Similarly WM_CLOSE can be used as well. Hope that helps.

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

        It doesn't work when I tried to override WM_CLOSE message in my view class. It seems that the system did not send WM_CLOSE message to my CView class when the prgram started to terminate.

        M 1 Reply Last reply
        0
        • L lisoft

          It doesn't work when I tried to override WM_CLOSE message in my view class. It seems that the system did not send WM_CLOSE message to my CView class when the prgram started to terminate.

          M Offline
          M Offline
          Mike Danberg
          wrote on last edited by
          #4

          Hmm. I'll try to help you out more, although I don't know that much about overriding those messages as I've never done it before. I've only worked with closing the program in a dialog based app. The code I posted before should work for manually closing the program. I don't see why it would be any different in an SDI. I'd suggest working with the WM_QUIT message first since that is the message sent when the program terminates. As far as I know the WM_CLOSE message is used if you have for instance a pop-up dialog and want to close it, so it shouldn't be sending any WM_CLOSE messages upon termination of the entire program.

          L 2 Replies Last reply
          0
          • M Mike Danberg

            Hmm. I'll try to help you out more, although I don't know that much about overriding those messages as I've never done it before. I've only worked with closing the program in a dialog based app. The code I posted before should work for manually closing the program. I don't see why it would be any different in an SDI. I'd suggest working with the WM_QUIT message first since that is the message sent when the program terminates. As far as I know the WM_CLOSE message is used if you have for instance a pop-up dialog and want to close it, so it shouldn't be sending any WM_CLOSE messages upon termination of the entire program.

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

            Anyway, thanks.

            1 Reply Last reply
            0
            • M Mike Danberg

              Hmm. I'll try to help you out more, although I don't know that much about overriding those messages as I've never done it before. I've only worked with closing the program in a dialog based app. The code I posted before should work for manually closing the program. I don't see why it would be any different in an SDI. I'd suggest working with the WM_QUIT message first since that is the message sent when the program terminates. As far as I know the WM_CLOSE message is used if you have for instance a pop-up dialog and want to close it, so it shouldn't be sending any WM_CLOSE messages upon termination of the entire program.

              L Offline
              L Offline
              lisoft
              wrote on last edited by
              #6

              I used spy++ to trace messages of my program, but did not get any WM_QUIT message. So I'm afraid if it would take effect if I work with the WM_QUIT message.

              M 1 Reply Last reply
              0
              • L lisoft

                I used spy++ to trace messages of my program, but did not get any WM_QUIT message. So I'm afraid if it would take effect if I work with the WM_QUIT message.

                M Offline
                M Offline
                Mike Danberg
                wrote on last edited by
                #7

                Well I'm pretty sure that's what happens when you press the big orange 'X' button. Try this and you'll see what it does. In any of the drop down menus you have create an option called "Quit" and in the code just put PostMessage(WM_QUIT, 0, 0); That will quit the entire app.

                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