[NTUSER][USER32] Simplify SwitchToThisWindow (#4153)

CORE-17894
This commit is contained in:
Katayama Hirofumi MZ 2021-12-13 08:14:33 +09:00 committed by GitHub
parent cf8380100e
commit 55a1c29341
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 42 deletions

View file

@ -512,28 +512,25 @@ NtUserCallTwoParam(
Ret = 0; Ret = 0;
Window = UserGetWindowObject(hwnd); Window = UserGetWindowObject(hwnd);
if (!Window) if (!Window)
{
break; break;
}
if (MsqIsHung(Window->head.pti, MSQ_HUNG)) if (gpqForeground && !fAltTab)
{ {
// TODO: Make the window ghosted and activate. PWND pwndActive = gpqForeground->spwndActive;
break; if (pwndActive && !(pwndActive->ExStyle & WS_EX_TOPMOST))
}
if (fAltTab)
{
if (Window->style & WS_MINIMIZE)
{ {
UserPostMessage(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0); co_WinPosSetWindowPos(pwndActive, HWND_BOTTOM, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE |
SWP_NOSENDCHANGING | SWP_ASYNCWINDOWPOS);
} }
/* bring window to top and activate */
co_WinPosSetWindowPos(Window, HWND_TOP, 0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_NOSENDCHANGING |
SWP_NOOWNERZORDER | SWP_ASYNCWINDOWPOS);
} }
else
UserSetActiveWindow(Window);
if (fAltTab && (Window->style & WS_MINIMIZE))
{ {
UserSetActiveWindow(Window); MSG msg = { Window->head.h, WM_SYSCOMMAND, SC_RESTORE, 0 };
MsqPostMessage(Window->head.pti, &msg, FALSE, QS_POSTMESSAGE, 0, 0);
} }
break; break;
} }

View file

@ -71,18 +71,6 @@ int CoolSwitchColumns = 7;
const DWORD Style = WS_POPUP | WS_BORDER | WS_DISABLED; const DWORD Style = WS_POPUP | WS_BORDER | WS_DISABLED;
const DWORD ExStyle = WS_EX_TOPMOST | WS_EX_DLGMODALFRAME | WS_EX_TOOLWINDOW; const DWORD ExStyle = WS_EX_TOPMOST | WS_EX_DLGMODALFRAME | WS_EX_TOOLWINDOW;
DWORD wtodw(const WCHAR *psz)
{
const WCHAR *pch = psz;
DWORD Value = 0;
while ('0' <= *pch && *pch <= '9')
{
Value *= 10;
Value += *pch - L'0';
}
return Value;
}
BOOL LoadCoolSwitchSettings(void) BOOL LoadCoolSwitchSettings(void)
{ {
CoolSwitch = TRUE; CoolSwitch = TRUE;
@ -122,15 +110,6 @@ void ResizeAndCenter(HWND hwnd, int width, int height)
ptStart.y = y; ptStart.y = y;
} }
void MakeWindowActive(HWND hwnd)
{
if (IsIconic(hwnd))
PostMessageW(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
// See also: https://microsoft.public.win32.programmer.ui.narkive.com/RqOdKqZ8/bringwindowtotop-hangs-if-the-thread-is-busy
SwitchToThisWindow(hwnd, TRUE);
}
void CompleteSwitch(BOOL doSwitch) void CompleteSwitch(BOOL doSwitch)
{ {
if (!isOpen) if (!isOpen)
@ -155,7 +134,7 @@ void CompleteSwitch(BOOL doSwitch)
TRACE("[ATbot] CompleteSwitch Switching to 0x%08x (%ls)\n", hwnd, windowText); TRACE("[ATbot] CompleteSwitch Switching to 0x%08x (%ls)\n", hwnd, windowText);
MakeWindowActive(hwnd); SwitchToThisWindow(hwnd, TRUE);
} }
} }
@ -485,7 +464,7 @@ BOOL ProcessHotKey(VOID)
if (windowCount == 1) if (windowCount == 1)
{ {
MakeWindowActive(windowList[0]); SwitchToThisWindow(windowList[0], TRUE);
return FALSE; return FALSE;
} }
@ -496,7 +475,7 @@ BOOL ProcessHotKey(VOID)
TRACE("[ATbot] HotKey Received. Opening window.\n"); TRACE("[ATbot] HotKey Received. Opening window.\n");
ShowWindowAsync(switchdialog, SW_SHOWNORMAL); ShowWindowAsync(switchdialog, SW_SHOWNORMAL);
MakeWindowActive(switchdialog); SwitchToThisWindow(switchdialog, TRUE);
isOpen = TRUE; isOpen = TRUE;
} }
else else
@ -525,7 +504,7 @@ void RotateTasks(BOOL bShift)
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE |
SWP_NOOWNERZORDER | SWP_NOREPOSITION | SWP_ASYNCWINDOWPOS); SWP_NOOWNERZORDER | SWP_NOREPOSITION | SWP_ASYNCWINDOWPOS);
MakeWindowActive(hwndLast); SwitchToThisWindow(hwndLast, TRUE);
Size = (windowCount - 1) * sizeof(HWND); Size = (windowCount - 1) * sizeof(HWND);
MoveMemory(&windowList[1], &windowList[0], Size); MoveMemory(&windowList[1], &windowList[0], Size);
@ -537,7 +516,7 @@ void RotateTasks(BOOL bShift)
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE |
SWP_NOOWNERZORDER | SWP_NOREPOSITION | SWP_ASYNCWINDOWPOS); SWP_NOOWNERZORDER | SWP_NOREPOSITION | SWP_ASYNCWINDOWPOS);
MakeWindowActive(windowList[1]); SwitchToThisWindow(windowList[1], TRUE);
Size = (windowCount - 1) * sizeof(HWND); Size = (windowCount - 1) * sizeof(HWND);
MoveMemory(&windowList[0], &windowList[1], Size); MoveMemory(&windowList[0], &windowList[1], Size);