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. [Solved] Close Application from OnTimer problem [modified]

[Solved] Close Application from OnTimer problem [modified]

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

    Hello and good day. I have an application which runs threads and waits for all of them to be terminated before closing the application. I used a timer to check the number of threads that are still active, which successfully checked when there was no more threads. However, when I called OnClose() from the OnTimer function, the application fails to close. I needed to close the application one more time for it to successfully close. I checked and the application reads the CDialog::OnClose() in the OnClose function but it does not close when called from the OnTimer. Does anyone have an idea about this situation? Thank you very much for your help. -- modified at 1:52 Monday 22nd October, 2007

    N S 2 Replies Last reply
    0
    • L Llasus

      Hello and good day. I have an application which runs threads and waits for all of them to be terminated before closing the application. I used a timer to check the number of threads that are still active, which successfully checked when there was no more threads. However, when I called OnClose() from the OnTimer function, the application fails to close. I needed to close the application one more time for it to successfully close. I checked and the application reads the CDialog::OnClose() in the OnClose function but it does not close when called from the OnTimer. Does anyone have an idea about this situation? Thank you very much for your help. -- modified at 1:52 Monday 22nd October, 2007

      N Offline
      N Offline
      Nibu babu thomas
      wrote on last edited by
      #2

      This should help you -> http://www.codeproject.com/dialog/transparentdialog.asp?df=100&forumid=13681&exp=0&select=2184474&mpp=50#xx2184474xx[^]


      Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http:\\nibuthomas.wordpress.com

      L 1 Reply Last reply
      0
      • L Llasus

        Hello and good day. I have an application which runs threads and waits for all of them to be terminated before closing the application. I used a timer to check the number of threads that are still active, which successfully checked when there was no more threads. However, when I called OnClose() from the OnTimer function, the application fails to close. I needed to close the application one more time for it to successfully close. I checked and the application reads the CDialog::OnClose() in the OnClose function but it does not close when called from the OnTimer. Does anyone have an idea about this situation? Thank you very much for your help. -- modified at 1:52 Monday 22nd October, 2007

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #3

        Try using calling AfxPostQuitMessage instead of calling OnClose.

        Steve

        L 1 Reply Last reply
        0
        • N Nibu babu thomas

          This should help you -> http://www.codeproject.com/dialog/transparentdialog.asp?df=100&forumid=13681&exp=0&select=2184474&mpp=50#xx2184474xx[^]


          Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http:\\nibuthomas.wordpress.com

          L Offline
          L Offline
          Llasus
          wrote on last edited by
          #4

          Thank you very much! PostMessage(WM_CLOSE) did the job. Thank you!

          N 1 Reply Last reply
          0
          • S Stephen Hewitt

            Try using calling AfxPostQuitMessage instead of calling OnClose.

            Steve

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

            Thank you for your time and help. Though when using AfxPostQuitMessage caused the application to immediately close without calling the OnClose() which caused some leaks since I have some objects released at that function. :) Thanks again for your help!

            S 1 Reply Last reply
            0
            • L Llasus

              Thank you for your time and help. Though when using AfxPostQuitMessage caused the application to immediately close without calling the OnClose() which caused some leaks since I have some objects released at that function. :) Thanks again for your help!

              S Offline
              S Offline
              Stephen Hewitt
              wrote on last edited by
              #6

              In that case try PostMessage(WM_CLOSE); instead.

              Steve

              L 1 Reply Last reply
              0
              • S Stephen Hewitt

                In that case try PostMessage(WM_CLOSE); instead.

                Steve

                L Offline
                L Offline
                Llasus
                wrote on last edited by
                #7

                Yes. I tried that and solved my problem. :) Thank you for your help!

                1 Reply Last reply
                0
                • L Llasus

                  Thank you very much! PostMessage(WM_CLOSE) did the job. Thank you!

                  N Offline
                  N Offline
                  Nibu babu thomas
                  wrote on last edited by
                  #8

                  Llasus wrote:

                  Thank you very much! PostMessage(WM_CLOSE) did the job. Thank you!

                  You should not call OnClose directly. It's an event handler which is invoked by the MFC messaging framework in response to the WM_CLOSE message. That's why your call didn't work.


                  Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http:\\nibuthomas.wordpress.com

                  L 1 Reply Last reply
                  0
                  • N Nibu babu thomas

                    Llasus wrote:

                    Thank you very much! PostMessage(WM_CLOSE) did the job. Thank you!

                    You should not call OnClose directly. It's an event handler which is invoked by the MFC messaging framework in response to the WM_CLOSE message. That's why your call didn't work.


                    Nibu thomas Microsoft MVP for VC++ Code must be written to be read, not by the compiler, but by another human being. Programming Blog: http:\\nibuthomas.wordpress.com

                    L Offline
                    L Offline
                    Llasus
                    wrote on last edited by
                    #9

                    Actually I placed a TRACE in the OnClose function to see if it works before. Since the timer is the one which calls the OnClose function, it printed out in the Output window the message I set inside the OnClose function using TRACE. What I was wondering about was that I had the CDialog::OnClose() inside the function but it did not work. I needed to click on the close button once again to close the application. I made a breakpoint inside the function to double-check and it actually passes the CDialog::OnClose() but it won't close when called directly by the OnTimer function. I also tried DestroyWindow but it really does not work ( though it passes through that line) when called by OnTimer and needed for the close button to be pressed once again to close it.

                    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