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>
This commit is contained in:
Zhiyi Zhang 2018-07-16 11:27:47 +08:00 committed by Alexandre Julliard
parent 0b69359a24
commit bfe6826a16
2 changed files with 28 additions and 2 deletions

View File

@ -10700,6 +10700,27 @@ static void test_destroy_quit(void)
CloseHandle( thread1 ); 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) START_TEST(win)
{ {
char **argv; char **argv;
@ -10856,6 +10877,7 @@ START_TEST(win)
test_hide_window(); test_hide_window();
test_minimize_window(hwndMain); test_minimize_window(hwndMain);
test_destroy_quit(); test_destroy_quit();
test_IsWindowEnabled();
/* add the tests above this line */ /* add the tests above this line */
if (hhook) UnhookWindowsHookEx(hhook); if (hhook) UnhookWindowsHookEx(hhook);

View File

@ -2157,9 +2157,13 @@ BOOL WINAPI EnableWindow( HWND hwnd, BOOL enable )
*/ */
BOOL WINAPI IsWindowEnabled(HWND hWnd) 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.@) * IsWindowUnicode (USER32.@)