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. How to avoid to close my App?

How to avoid to close my App?

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
9 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.
  • D Offline
    D Offline
    doctorpi
    wrote on last edited by
    #1

    Hi guys I was wandering where I have to put this... ----------------------------------------------------------------------- int ret=AfxMessageBox("You will exit the program.\nContinue?",MB_YESNO); if (ret==IDNO) return ; (someone more is needed ?) ----------------------------------------------------------------------- ...in my SDI application when someone clicks on the right upper Cross (standard close button) of my app. Thanks in forwarding. Dr.Pi

    D K M 3 Replies Last reply
    0
    • D doctorpi

      Hi guys I was wandering where I have to put this... ----------------------------------------------------------------------- int ret=AfxMessageBox("You will exit the program.\nContinue?",MB_YESNO); if (ret==IDNO) return ; (someone more is needed ?) ----------------------------------------------------------------------- ...in my SDI application when someone clicks on the right upper Cross (standard close button) of my app. Thanks in forwarding. Dr.Pi

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

      Have you considered handling the WM_DESTROY message? This will handle all methods of your app closing ("X", Alt+F4, File/Exit).


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

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

      D 1 Reply Last reply
      0
      • D David Crow

        Have you considered handling the WM_DESTROY message? This will handle all methods of your app closing ("X", Alt+F4, File/Exit).


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

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

        D Offline
        D Offline
        doctorpi
        wrote on last edited by
        #3

        In my CFormView? In my App? I've tried in my CFormView but the app is closing anyway. I miss something to do? Dr.Pi

        D M 2 Replies Last reply
        0
        • D doctorpi

          In my CFormView? In my App? I've tried in my CFormView but the app is closing anyway. I miss something to do? Dr.Pi

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

          doctorpi wrote:

          In my CFormView?

          Yes.

          doctorpi wrote:

          I've tried in my CFormView but the app is closing anyway.

          Are you still calling the base-class implementation. What does the OnDestroy() method look like?


          "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 doctorpi

            In my CFormView? In my App? I've tried in my CFormView but the app is closing anyway. I miss something to do? Dr.Pi

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

            How about in response to WM_SYSCOMMAND where wParam==SC_CLOSE? This should be done in the app main window, wherever that is.

            "If you can dodge a wrench, you can dodge a ball."

            1 Reply Last reply
            0
            • D doctorpi

              Hi guys I was wandering where I have to put this... ----------------------------------------------------------------------- int ret=AfxMessageBox("You will exit the program.\nContinue?",MB_YESNO); if (ret==IDNO) return ; (someone more is needed ?) ----------------------------------------------------------------------- ...in my SDI application when someone clicks on the right upper Cross (standard close button) of my app. Thanks in forwarding. Dr.Pi

              K Offline
              K Offline
              krmed
              wrote on last edited by
              #6

              Override the WM_CLOSE message (OnClose) in your MainFrame class, and put your code it there. It will catch the X in the uppoer right corner, as well as Alt-F4, or an attempt to close from the task manager. Hope that helps.

              Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

              D 1 Reply Last reply
              0
              • K krmed

                Override the WM_CLOSE message (OnClose) in your MainFrame class, and put your code it there. It will catch the X in the uppoer right corner, as well as Alt-F4, or an attempt to close from the task manager. Hope that helps.

                Karl - WK5M PP-ASEL-IA (N43CS) PGP Key: 0xDB02E193 PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

                D Offline
                D Offline
                doctorpi
                wrote on last edited by
                #7

                It helps a lot, that works fine, thanks. Dr.Pi

                1 Reply Last reply
                0
                • D doctorpi

                  Hi guys I was wandering where I have to put this... ----------------------------------------------------------------------- int ret=AfxMessageBox("You will exit the program.\nContinue?",MB_YESNO); if (ret==IDNO) return ; (someone more is needed ?) ----------------------------------------------------------------------- ...in my SDI application when someone clicks on the right upper Cross (standard close button) of my app. Thanks in forwarding. Dr.Pi

                  M Offline
                  M Offline
                  Michael Dunn
                  wrote on last edited by
                  #8

                  The recommended place for a close confirmation is in an overload of CanCloseFrame() in your CDocument-derived class.

                  --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?

                  D 1 Reply Last reply
                  0
                  • M Michael Dunn

                    The recommended place for a close confirmation is in an overload of CanCloseFrame() in your CDocument-derived class.

                    --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Ford, what's this fish doing in my ear?

                    D Offline
                    D Offline
                    doctorpi
                    wrote on last edited by
                    #9

                    This is the place, thanks. Dr.Pi

                    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