Click here to Skip to main content
15,884,741 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?

Thanks!
Posted

This handling of this message could be blocked in one or another way. Alternatively, you can request OS to terminate the thread: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644945%28v=vs.85%29.aspx[^].

Please try.

—SA
 
Share this answer
 
Comments
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...
—SA
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.
—SA
Member 20 10-Apr-14 19:55pm    
Ok, my application internally calls 2 more applications, i should close them all before calling Quit.

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