<p>What is the proper way for an MFC application to cleanly close itself?</p>

[{'answer_id': 14492, 'author': 'Mike', 'author_id': 1743, 'author_profile': 'https://Stackoverflow.com/users/1743', 'pm_score': 4, 'selected': False, 'text': '<pre><code>AfxGetMainWnd()-&gt;PostMessage(WM_CLOSE);\n</code></pre>\n'}, {'answer_id': 14663, 'author': 'Aidan Ryan', 'author_id': 1042, 'author_profile': 'https://Stackoverflow.com/users/1042', 'pm_score': 2, 'selected': False, 'text': "<p>In support of @Mike's answer, the reason to use this method is to trigger the correct shutdown sequence. Especially important for MDI/SDI applications because it gives a chance for documents to prompt for save before exit or to cancel the exit.</p>\n\n<p>@Matt Noguchi, your method will circumvent this sequence (which may be the desired effect, I suppose, but you've probably got <em>problems</em> if you're short-circuiting the normal teardown.</p>\n"}, {'answer_id': 14841, 'author': 'Mat Noguchi', 'author_id': 1799, 'author_profile': 'https://Stackoverflow.com/users/1799', 'pm_score': 2, 'selected': False, 'text': '<pre><code>PostQuitMessage( [exit code] );\n</code></pre>\n'}, {'answer_id': 91465, 'author': 'Gautam Jain', 'author_id': 15065, 'author_profile': 'https://Stackoverflow.com/users/15065', 'pm_score': 1, 'selected': False, 'text': '<p>If it is a dialog based application you can do it by calling EndDialog() function.</p>\n\n<p>If it is an SDI/MDI based application you can call DestroyWindow. But before which you will need to do the cleanup yourself (closing documents, deallocating memory and resources, destroying any additional windows created etc).</p>\n'}, {'answer_id': 8768957, 'author': 'Bruno Schwarzkorpf', 'author_id': 1115458, 'author_profile': 'https://Stackoverflow.com/users/1115458', 'pm_score': 5, 'selected': True, 'text': '<p>Programatically Terminate an MFC Application</p>\n\n<pre><code> void ExitMFCApp()\n   {\n        // same as double-clicking on main window close box\n        ASSERT(AfxGetMainWnd() != NULL);\n        AfxGetMainWnd()-&gt;SendMessage(WM_CLOSE);\n   }\n</code></pre>\n\n<p><a href="http://support.microsoft.com/kb/117320">http://support.microsoft.com/kb/117320</a></p>\n'}]
['https://Stackoverflow.com/questions/14491', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1743/']