Destroying a Window (Windows Embedded CE 6.0)

1/6/2010

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

  1. 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 Embedded 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

Concepts

Working with Windows and Messages

Other Resources

GWES Application Development