From b824f044923cede20cd1550cb351f4b13bbd6729 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Wed, 10 Jan 2007 04:51:27 +0000 Subject: [PATCH] remove focus from window, when it gets diabled - fixes bug 843 See issue #843 for more details. svn path=/trunk/; revision=25412 --- reactos/dll/win32/user32/windows/input.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/reactos/dll/win32/user32/windows/input.c b/reactos/dll/win32/user32/windows/input.c index 6f7bac23902..43305ae3595 100644 --- a/reactos/dll/win32/user32/windows/input.c +++ b/reactos/dll/win32/user32/windows/input.c @@ -36,6 +36,7 @@ /* Directory to load key layouts from */ #define SYSTEMROOT_DIR L"\\SystemRoot\\System32\\" +#define STATE_GWL_OFFSET 0 /* GLOBALS *******************************************************************/ @@ -338,11 +339,24 @@ EnableWindow(HWND hWnd, BOOL bEnable) { LONG Style = NtUserGetWindowLong(hWnd, GWL_STYLE, FALSE); - Style = bEnable ? Style & ~WS_DISABLED : Style | WS_DISABLED; - NtUserSetWindowLong(hWnd, GWL_STYLE, Style, FALSE); - - SendMessageA(hWnd, WM_ENABLE, (LPARAM) IsWindowEnabled(hWnd), 0); + /* check if updating is needed */ + UINT bIsDisabled = (Style & WS_DISABLED); + if ( (bIsDisabled && bEnable) || (!bIsDisabled && !bEnable) ) + { + if (bEnable) + { + Style &= ~WS_DISABLED; + } + else + { + /* Remove keyboard focus from that window */ + SetFocus(NULL); + Style |= WS_DISABLED; + } + NtUserSetWindowLong(hWnd, GWL_STYLE, Style, FALSE); + SendMessageA(hWnd, WM_ENABLE, (LPARAM) IsWindowEnabled(hWnd), 0); + } // Return nonzero if it was disabled, or zero if it wasn't: return IsWindowEnabled(hWnd); }