[FancyZones] Bypass restriction on SetForegroundWindow (#14383)

Co-authored-by: float4 <float4-unspecified-mail>
This commit is contained in:
FLOAT4
2021-11-18 11:16:04 +02:00
committed by GitHub
parent 5a4822f89e
commit 5a9f52fb11
3 changed files with 22 additions and 6 deletions

View File

@@ -369,6 +369,22 @@ namespace FancyZonesUtils
::SetWindowPlacement(window, &placement);
}
void SwitchToWindow(HWND window) noexcept
{
// Check if the window is minimized
if (IsIconic(window))
{
// Show the window since SetForegroundWindow fails on minimized windows
ShowWindow(window, SW_RESTORE);
}
// This is a hack to bypass the restriction on setting the foreground window
INPUT inputs[1] = { { .type = INPUT_MOUSE } };
SendInput(ARRAYSIZE(inputs), inputs, sizeof(INPUT));
SetForegroundWindow(window);
}
bool HasNoVisibleOwner(HWND window) noexcept
{
auto owner = GetWindow(window, GW_OWNER);