Click here to Skip to main content
15,353,818 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have the following code line to close a MFC Application which was working in VC++ 6, but it fails in VC++ 2010

m_pMainWnd->PostMessage( WM_CLOSE )

Any idea what is wrong with it?


This handling of this message could be blocked in one or another way. Alternatively, you can request OS to terminate the thread:[^].

Please try.

Member 20 10-Apr-14 18:45pm
Thanks for the response. Application is closed when i use WM_QUIT instead of WM_CLOSE. But i read in few places that QUIT will end the application abruptly whereas CLOSE ends application gracefully.
What is the difference? does MFC need to process something after calling WM_CLOSE? Please clarify.
Sergey Alexandrovich Kryukov 10-Apr-14 19:35pm
WM_CLOSE entails WM_DESTROY which usually handles with called PostQuitMessage. But WM_CLOSE can be handled to avoid closing, say, hiding instead of closing...
Member 20 10-Apr-14 19:42pm
Hi, when i use PostQuitMessage, application is closed but i am getting nActiveCount before it is closed. Do i need to check something?
Sergey Alexandrovich Kryukov 10-Apr-14 19:48pm
Sorry, I have no idea what is that count and what does it mean. If your application is closed, it's closed. If you have more then one thread, you need to close them all.
Member 20 10-Apr-14 19:55pm
Ok, my application internally calls 2 more applications, i should close them all before calling Quit.
Sergey Alexandrovich Kryukov 10-Apr-14 20:23pm
I did not mean applications, I mean threads. The separate applications are separate processes, well isolated from each other, running in different address spaces, etc. As soon as you started a process, it is independent. External process can be terminated by the call to TerminateProcess:

Member 20 10-Apr-14 19:43pm
Ok, so for my requirement PostQuitMessage is better.
Sergey Alexandrovich Kryukov 10-Apr-14 19:49pm
Then use it, until you need more fine-grain termination process; there is nothing wrong with it. Will you accept the answer formally (green "Accept" button)?
Member 20 10-Apr-14 19:55pm
Thanks a lot. Yes, i did :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900