Skip to content

Latest commit

 

History

History
59 lines (53 loc) · 2.32 KB

File metadata and controls

59 lines (53 loc) · 2.32 KB
title Destroying Frame Windows | Microsoft Docs
ms.custom
ms.date 11/04/2016
ms.reviewer
ms.suite
ms.technology
cpp-windows
ms.tgt_pltfrm
ms.topic article
f1_keywords
PostNcDestroy
dev_langs
C++
helpviewer_keywords
Default method
DestroyWindow method
frame windows [C++], destroying
OnNcDestroy method, and frame windows
document frame windows, destroying
destroying frame windows
MFC [C++], frame windows
windows [C++], destroying
OnClose method
PostNcDestroy method
ms.assetid 5affca77-1999-4507-a2b2-9aa226611b4b
caps.latest.revision 9
author mikeblome
ms.author mblome
manager ghogen
translation.priority.ht
cs-cz
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
pl-pl
pt-br
ru-ru
tr-tr
zh-cn
zh-tw

Destroying Frame Windows

The MFC framework manages window destruction as well as creation for those windows associated with framework documents and views. If you create additional windows, you are responsible for destroying them.

In the framework, when the user closes the frame window, the window's default OnClose handler calls DestroyWindow. The last member function called when the Windows window is destroyed is OnNcDestroy, which does some cleanup, calls the Default member function to perform Windows cleanup, and lastly calls the virtual member function PostNcDestroy. The CFrameWnd implementation of PostNcDestroy deletes the C++ window object. You should never use the C++ delete operator on a frame window. Use DestroyWindow instead.

When the main window closes, the application closes. If there are modified unsaved documents, the framework displays a message box to ask if the documents should be saved and ensures that the appropriate documents are saved if necessary.

What do you want to know more about

See Also

Using Frame Windows