From b68b0e3e50268dd20a72bf73f6c95f285690266e Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Thu, 16 Aug 2012 21:58:20 +0100 Subject: [PATCH] Exit cleanly on WM_CLOSE --- main.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index e4eec854..2bb588e7 100644 --- a/main.c +++ b/main.c @@ -440,6 +440,11 @@ static LRESULT CALLBACK WindowProc(HWND hWnd, UINT msg, WPARAM wParam, PostMessage(hWnd, WM_NULL, 0, 0); DestroyMenu(hMenu); break; + case WM_CLOSE: + mg_stop(ctx); + Shell_NotifyIcon(NIM_DELETE, &TrayIcon); + PostQuitMessage(0); + return 0; // We've just sent our own quit message, with proper hwnd. } break; } @@ -473,10 +478,12 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR cmdline, int show) { TrayIcon.uCallbackMessage = WM_USER; Shell_NotifyIcon(NIM_ADD, &TrayIcon); - while (GetMessage(&msg, hWnd, 0, 0)) { + while (GetMessage(&msg, hWnd, 0, 0) > 0) { TranslateMessage(&msg); DispatchMessage(&msg); } + + return msg.wParam; } #else int main(int argc, char *argv[]) {