WM DESTROY

当窗口被销毁时,此消息将发送到你的窗口过程。窗口从屏幕上删除后发送。大多数应用程序释放在 WM_CREATE 中获取的任何资源,如内存或句柄。如果处理此消息,则返回 0。

LRESULT CALLBACK winproc(HWND hwnd, UINT wm, WPARAM wp, LPARAM lp)
{
    static char *text;
    switch (wm) {
        case WM_CREATE:
            text = malloc(256);
            /* use the allocated memory */
            return 0;
        case WM_CLOSE:
             switch (MessageBox(hwnd, "Save changes?", "", MB_YESNOCANCEL)) {
                 case IDYES:
                      savedoc();
                                         /* fall through */
                 case IDNO:
                      DestroyWindow(hwnd);
                      break;
             }
             return 0;
        case WM_DESTROY:
            /* free the memory */
            free(text);
            PostQuitMessage(0);
            return 0;
    }
    return DefWindowProc(hwnd, wm, wp, lp);
}