From bfe6826a16f5997a8ee119b191874ad077c3d4e7 Mon Sep 17 00:00:00 2001 From: Zhiyi Zhang Date: Mon, 16 Jul 2018 11:27:47 +0800 Subject: [PATCH] user32: Return FALSE for invalid handle in IsWindowEnabled(). GetWindowLong() returns 0 if passed an invalid window handle, causing IsWindowEnabled() to incorrectly report TRUE. Signed-off-by: Zhiyi Zhang Signed-off-by: Alexandre Julliard --- dlls/user32/tests/win.c | 22 ++++++++++++++++++++++ dlls/user32/win.c | 8 ++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c index d7f8843c98b..94eff5ee4f6 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 3535c1b5f58..28bc1f604ba 100644 --- a/dlls/user32/win.c +++ b/dlls/user32/win.c @@ -2157,9 +2157,13 @@ 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 ); + if (!ret && GetLastError() != NO_ERROR) return FALSE; + return !(ret & WS_DISABLED); +} /*********************************************************************** * IsWindowUnicode (USER32.@)