Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can an MFC application terminate itself?

What is the proper way for an MFC application to cleanly close itself?

like image 996
Mike Avatar asked Aug 18 '08 12:08

Mike


People also ask

How do I close my MFC application?

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.

What is an MFC application?

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.

What is the entry point to MFC application?

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.


2 Answers

AfxGetMainWnd()->PostMessage(WM_CLOSE);
like image 189
Mike Avatar answered Oct 02 '22 02:10

Mike


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

like image 36
Bruno Schwarzkorpf Avatar answered Oct 02 '22 02:10

Bruno Schwarzkorpf