wndproc: switch (message) { case WM_SYSCOMMAND: // Early catch of close action. if (wParam == SC_CLOSE) { MessageBox(0, "got about-to-close message", 0, 0); break; // let defwndproc handle it, // you can return 0, and not let closing your app :( } break; case WM_CLOSE: // The actual close action. if (IDYES == MessageBox(0, "quitting?", 0, MB_YESNO)) break; // return 0, so it won't quit, in case user chose 'no'. return 0; case WM_DESTROY: // cleanup time + tell message loop to quit. PostQuitMessage(0); break; } return DefWindowProc(hWnd, message, wParam, lParam);