From 6a6ed54495be3a41884f1b6a596d04ce85857bec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herm=C3=A8s=20B=C3=A9lusca-Ma=C3=AFto?= Date: Sun, 31 Aug 2025 17:19:45 +0200 Subject: [PATCH] [NTUSER] Some lifting for the Int/UserGet[Active|Capture|Foreground|ThreadFocus]Window() functions --- win32ss/user/ntuser/desktop.c | 5 +--- win32ss/user/ntuser/focus.c | 48 +++++++++++++++++------------------ 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/win32ss/user/ntuser/desktop.c b/win32ss/user/ntuser/desktop.c index 560f5d0376b..d0ffa4584c8 100644 --- a/win32ss/user/ntuser/desktop.c +++ b/win32ss/user/ntuser/desktop.c @@ -1403,7 +1403,6 @@ HWND FASTCALL IntGetDesktopWindow(VOID) PWND FASTCALL UserGetDesktopWindow(VOID) { PDESKTOP pdo = IntGetActiveDesktop(); - if (!pdo) { TRACE("No active desktop\n"); @@ -1416,7 +1415,6 @@ PWND FASTCALL UserGetDesktopWindow(VOID) HWND FASTCALL IntGetMessageWindow(VOID) { PDESKTOP pdo = IntGetActiveDesktop(); - if (!pdo) { TRACE("No active desktop\n"); @@ -1429,7 +1427,6 @@ HWND FASTCALL IntGetMessageWindow(VOID) PWND FASTCALL UserGetMessageWindow(VOID) { PDESKTOP pdo = IntGetActiveDesktop(); - if (!pdo) { TRACE("No active desktop\n"); @@ -1442,7 +1439,7 @@ HWND FASTCALL IntGetCurrentThreadDesktopWindow(VOID) { PTHREADINFO pti = PsGetCurrentThreadWin32Thread(); PDESKTOP pdo = pti->rpdesk; - if (NULL == pdo) + if (!pdo) { ERR("Thread doesn't have a desktop\n"); return NULL; diff --git a/win32ss/user/ntuser/focus.c b/win32ss/user/ntuser/focus.c index 871f1e7f0b9..7173b766677 100644 --- a/win32ss/user/ntuser/focus.c +++ b/win32ss/user/ntuser/focus.c @@ -19,35 +19,34 @@ PTHREADINFO ptiLastInput = NULL; HWND ghwndOldFullscreen = NULL; /* - Check locking of a process or one or more menus are active. -*/ + * Check locking of a process or one or more menus are active. + */ BOOL FASTCALL IsFGLocked(VOID) { - return (gppiLockSFW || guSFWLockCount); + return (gppiLockSFW || guSFWLockCount); } /* - Get capture window via foreground Queue. -*/ + * Get capture window via foreground Queue. + */ HWND FASTCALL IntGetCaptureWindow(VOID) { - PUSER_MESSAGE_QUEUE ForegroundQueue = IntGetFocusMessageQueue(); - return ( ForegroundQueue ? (ForegroundQueue->spwndCapture ? UserHMGetHandle(ForegroundQueue->spwndCapture) : 0) : 0); + PUSER_MESSAGE_QUEUE ForegroundQueue = IntGetFocusMessageQueue(); + if (!ForegroundQueue) + return NULL; + return (ForegroundQueue->spwndCapture ? UserHMGetHandle(ForegroundQueue->spwndCapture) : NULL); } HWND FASTCALL IntGetThreadFocusWindow(VOID) { - PTHREADINFO pti; - PUSER_MESSAGE_QUEUE ThreadQueue; - - pti = PsGetCurrentThreadWin32Thread(); - ThreadQueue = pti->MessageQueue; - if (!ThreadQueue) - return NULL; - return ThreadQueue->spwndFocus ? UserHMGetHandle(ThreadQueue->spwndFocus) : 0; + PTHREADINFO pti = PsGetCurrentThreadWin32Thread(); + PUSER_MESSAGE_QUEUE ThreadQueue = pti->MessageQueue; + if (!ThreadQueue) + return NULL; + return (ThreadQueue->spwndFocus ? UserHMGetHandle(ThreadQueue->spwndFocus) : NULL); } BOOL FASTCALL IntIsWindowFullscreen(PWND Window) @@ -1423,20 +1422,19 @@ co_UserSetFocus(PWND Window) HWND FASTCALL UserGetForegroundWindow(VOID) { - PUSER_MESSAGE_QUEUE ForegroundQueue; - - ForegroundQueue = IntGetFocusMessageQueue(); - return( ForegroundQueue ? (ForegroundQueue->spwndActive ? UserHMGetHandle(ForegroundQueue->spwndActive) : 0) : 0); + PUSER_MESSAGE_QUEUE ForegroundQueue = IntGetFocusMessageQueue(); + if (!ForegroundQueue) + return NULL; + return (ForegroundQueue->spwndActive ? UserHMGetHandle(ForegroundQueue->spwndActive) : NULL); } HWND FASTCALL UserGetActiveWindow(VOID) { - PTHREADINFO pti; - PUSER_MESSAGE_QUEUE ThreadQueue; - - pti = PsGetCurrentThreadWin32Thread(); - ThreadQueue = pti->MessageQueue; - return( ThreadQueue ? (ThreadQueue->spwndActive ? UserHMGetHandle(ThreadQueue->spwndActive) : 0) : 0); + PTHREADINFO pti = PsGetCurrentThreadWin32Thread(); + PUSER_MESSAGE_QUEUE ThreadQueue = pti->MessageQueue; + if (!ThreadQueue) + return NULL; + return (ThreadQueue->spwndActive ? UserHMGetHandle(ThreadQueue->spwndActive) : NULL); } HWND APIENTRY