What is the proper way for an MFC application to cleanly close itself?
In MFC, sending WM_CLOSE is correct. MFC is implemented as such. That is, in CWinApp::OnExit(), the application class is designed to send WM_CLOSE to the main window.
An MFC application is an executable application for Windows that is based on the Microsoft Foundation Class (MFC) Library. MFC executables generally fall into five types: standard Windows applications, dialog boxes, forms-based applications, Explorer-style applications, and Web browser-style applications.
In an MFC application, the entry point is hidden in the library, reportedly, in the file "Appmodule. cpp". Actually, the entry point name is defined as _tWinMain , which is a generic name for Unicode ("wide" wWinMain ) and non-Unicode ( WinMain ) entry-point names, a way to abstract out from Unicode option.
AfxGetMainWnd()->PostMessage(WM_CLOSE);
Programatically Terminate an MFC Application
void ExitMFCApp()
{
// same as double-clicking on main window close box
ASSERT(AfxGetMainWnd() != NULL);
AfxGetMainWnd()->SendMessage(WM_CLOSE);
}
http://support.microsoft.com/kb/117320
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With