Module: wine Branch: master Commit: bfe6826a16f5997a8ee119b191874ad077c3d4e7 URL: https://source.winehq.org/git/wine.git/?a=commit;h=bfe6826a16f5997a8ee119b19...
Author: Zhiyi Zhang zzhang@codeweavers.com Date: Mon Jul 16 11:27:47 2018 +0800
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 zzhang@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
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 d7f8843..94eff5e 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 3535c1b..28bc1f6 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.@)