A window is closed (removed from the screen and destroyed) by Presentation Manager in response to the application issuing a WinDestroyWindow() call, specifying the handle of the window to be destroyed. In normal circumstances the handle of the frame window is specified; destroying the frame window destroys that window and all of its children, including the client window associated with that frame.
When an application requests that Presentation Manager close a window, a system-defined message of class WM_DESTROY is sent to the client window, and thus to the window procedure associated with that class. The window procedure may capture and process this message, backing out any uncompleted units of work, and destroying or terminating access to data objects. The window procedure should then return a value of zero.
Note that although closing and destroying a parent window will also close and destroy all children of that window, the WM_DESTROY message is sent to the parent window, and processed before the children are destroyed. Hence when processing a WM_DESTROY message, a window procedure may assume that all its children still exist.
If the user explicitly requests closure of a window by selecting the "Close" option on the system menu, a system-defined message of class WM_CLOSE is sent to the window procedure. The window procedure may also capture and process this message in a similar manner to that used for WM_DESTROY messages.
Note that explicit processing of the WM_CLOSE message class is recommended for all Presentation Manager windows, since the default processing provided by Presentation Manager causes a WM_QUIT message to be posted to the application's message queue. This may result in unwarranted termination of the application. The window procedure for a child window should process a WM_CLOSE message by issuing a WinDestroyWindow() call for its frame window. The window procedure for an application's main window should process a WM_CLOSE message by posting a WM_QUIT message to itself. This will cause the application to terminate (see Terminating an Application).
In order to handle the closure of a window in the most elegant manner, the following course of action is recommended:
The release of data objects and Presentation Manager resources is discussed in Instance Data and Window Words.