GetWindowLong() returns 0 if passed an invalid window handle, causing IsWindowEnabled() to incorrectly report TRUE.
Signed-off-by: Zhiyi Zhang zzhang@codeweavers.com --- dlls/user32/tests/win.c | 22 ++++++++++++++++++++++ dlls/user32/win.c | 10 ++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c index d7f8843c98..94eff5ee4f 100644 --- a/dlls/user32/tests/win.c +++ b/dlls/user32/tests/win.c @@ -10700,6 +10700,27 @@ static void test_destroy_quit(void) CloseHandle( thread1 ); }
+static void test_IsWindowEnabled(void) +{ + BOOL ret; + HWND hwnd; + + ret = IsWindowEnabled(NULL); + ok(!ret, "Expect IsWindowEnabled() return FALSE\n"); + + hwnd = GetDesktopWindow(); + ret = IsWindowEnabled(hwnd); + ok(ret, "Expect IsWindowEnabled() return TRUE\n"); + + hwnd = create_tool_window(WS_CHILD | WS_VISIBLE, hwndMain); + ret = IsWindowEnabled(hwnd); + ok(ret, "Expect IsWindowEnabled() return TRUE\n"); + EnableWindow(hwnd, FALSE); + ret = IsWindowEnabled(hwnd); + ok(!ret, "Expect IsWindowEnabled() return FALSE\n"); + DestroyWindow(hwnd); +} + START_TEST(win) { char **argv; @@ -10856,6 +10877,7 @@ START_TEST(win) test_hide_window(); test_minimize_window(hwndMain); test_destroy_quit(); + test_IsWindowEnabled();
/* add the tests above this line */ if (hhook) UnhookWindowsHookEx(hhook); diff --git a/dlls/user32/win.c b/dlls/user32/win.c index 13984583c2..9e0b2cc805 100644 --- a/dlls/user32/win.c +++ b/dlls/user32/win.c @@ -2160,9 +2160,15 @@ BOOL WINAPI EnableWindow( HWND hwnd, BOOL enable ) */ BOOL WINAPI IsWindowEnabled(HWND hWnd) { - return !(GetWindowLongW( hWnd, GWL_STYLE ) & WS_DISABLED); -} + LONG ret; + + SetLastError(NO_ERROR); + ret = GetWindowLongW( hWnd, GWL_STYLE ); + /* returned value maybe invalid */ + if (GetLastError() != NO_ERROR) return FALSE;
+ return !(ret & WS_DISABLED); +}
/*********************************************************************** * IsWindowUnicode (USER32.@)