Compartir a través de


Destroying a Window (Windows CE 5.0)

Send Feedback

Destroying a window automatically destroys the descendant windows of that window. The DestroyWindow function first sends a WM_DESTROY message to the initial window that is being destroyed and then sends one to its descendant windows.

To destroy a window

  • Call DestroyWindow to destroy the window.

Typically, an application calls DestroyWindow inside the WinProc function for the window when handling both the WM_DESTORY and WM_CLOSE window messages. You should handle the WM_CLOSE window message to close your application so that your application will shut down in a standard way if requested to by some other application.

The following code example shows how to handle the WM_CLOSE and WM_DESTORY messages within the WinProc function.

//Handle the WM_CLOSE message so your application will
//shut down gracefully when requested.
    case WM_CLOSE:
      //Save any application-specific information
      DestroyWindow (hWnd);
      return 0;

    case WM_DESTROY:
      PostQuitMessage (0);
      return 0;

When a thread or process terminates, Windows CE removes all of the windows that are owned by that thread or process. Windows that are removed when a thread or process terminates do not always receive WM_DESTROY messages. For this reason, it is recommended that you manually destroy windows. When a window is destroyed, the system hides the window, sends a WM_DESTROY message to the window procedure of the window being destroyed, and removes any associated internal data. The window handle becomes invalid and can no longer be used by the application.

You should destroy any window that no longer is needed. Before destroying a window, save or remove any data that is associated with the window, and release system resources that are allocated to the window.

Destroying a window does not affect the window class from which the window is created. You still can create new windows by using the class, and any existing windows of that class continue to operate.

See Also

Working with Windows and Messages | GWES Application Development

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.