[Solved] Close Application from OnTimer problem [modified]
-
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
-
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
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
-
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
Try using calling
AfxPostQuitMessage
instead of callingOnClose
.Steve
-
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
-
Try using calling
AfxPostQuitMessage
instead of callingOnClose
.Steve
-
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!
In that case try
PostMessage(WM_CLOSE);
instead.Steve
-
In that case try
PostMessage(WM_CLOSE);
instead.Steve
-
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 theWM_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
-
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 theWM_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
Actually I placed a
TRACE
in theOnClose
function to see if it works before. Since the timer is the one which calls theOnClose
function, it printed out in the Output window the message I set inside theOnClose
function usingTRACE
. What I was wondering about was that I had theCDialog::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 theCDialog::OnClose()
but it won't close when called directly by theOnTimer
function. I also triedDestroyWindow
but it really does not work ( though it passes through that line) when called byOnTimer
and needed for the close button to be pressed once again to close it.