diff --git a/windows/main.cpp b/windows/main.cpp index 35be9942..4bcef139 100644 --- a/windows/main.cpp +++ b/windows/main.cpp @@ -115,17 +115,16 @@ int uiInit(void *options, uiInitError *err) void uiMain(void) { MSG msg; - BOOL ret; HRESULT hr; for (;;) { - hr = uiprivHrGetMessageW(&msg, NULL, 0, 0, &ret); + hr = uiprivHrGetMessageW(&msg, NULL, 0, 0); + if (hr == S_FALSE) // WM_QUIT + return; if (hr != S_OK) { // TODO log error return; } - if (ret == 0) // WM_QUIT - return; // TODO IsDialogMessage() TranslateMessage(&msg); DispatchMessageW(&msg); diff --git a/windows/winhresult.cpp b/windows/winhresult.cpp index cf8998d6..0b7ea0fc 100644 --- a/windows/winhresult.cpp +++ b/windows/winhresult.cpp @@ -41,13 +41,16 @@ HRESULT WINAPI uiprivHrCreateWindowExW(DWORD exStyle, LPCWSTR className, LPCWSTR return S_OK; } -// TODO turn ret into S_OK/S_FALSE? -HRESULT WINAPI uiprivHrGetMessageW(LPMSG msg, HWND hwnd, UINT filterMin, UINT filterMax, BOOL *ret) +HRESULT WINAPI uiprivHrGetMessageW(LPMSG msg, HWND hwnd, UINT filterMin, UINT filterMax) { + BOOL ret; + SetLastError(0); - *ret = GetMessageW(msg, hwnd, filterMin, filterMax); - if (*ret < 0) + ret = GetMessageW(msg, hwnd, filterMin, filterMax); + if (ret < 0) return lastErrorToHRESULT(); + if (ret == 0) + return S_FALSE; return S_OK; } diff --git a/windows/winhresult.hpp b/windows/winhresult.hpp index a723f04c..a2126ce2 100644 --- a/windows/winhresult.hpp +++ b/windows/winhresult.hpp @@ -2,7 +2,8 @@ extern HRESULT WINAPI uiprivHrRegisterClassW(const WNDCLASSW *wc); extern HRESULT WINAPI uiprivHrCreateWindowExW(DWORD exStyle, LPCWSTR className, LPCWSTR windowName, DWORD style, int x, int y, int width, int height, HWND parent, HMENU menu, HINSTANCE hInstance, LPVOID lpParam, HWND *hwnd); -extern HRESULT WINAPI uiprivHrGetMessageW(LPMSG msg, HWND hwnd, UINT filterMin, UINT filterMax, BOOL *ret); +// Note: if no error, returns S_FALSE on WM_QUIT, and S_OK otherwise. +extern HRESULT WINAPI uiprivHrGetMessageW(LPMSG msg, HWND hwnd, UINT filterMin, UINT filterMax); extern HRESULT WINAPI uiprivHrPostMessageW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); extern HRESULT WINAPI uiprivHrLoadIconW(HINSTANCE hInstance, LPCWSTR name, HICON *hIcon); extern HRESULT WINAPI uiprivHrLoadCursorW(HINSTANCE hInstance, LPCWSTR name, HCURSOR *hCursor);