diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs index 3b8ec43ef1..56803a59ee 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs @@ -234,6 +234,10 @@ public sealed partial class MainWindow : WindowEx, PInvoke.SetForegroundWindow(hwnd); PInvoke.SetActiveWindow(hwnd); + + // Push our window to the top of the Z-order and make it the topmost, so that it appears above all other windows. + // We want to remove the topmost status when we hide the window (because we cloak it instead of hiding it). + PInvoke.SetWindowPos(hwnd, HWND.HWND_TOPMOST, 0, 0, 0, 0, SET_WINDOW_POS_FLAGS.SWP_NOMOVE | SET_WINDOW_POS_FLAGS.SWP_NOSIZE); } private DisplayArea GetScreen(HWND currentHwnd, MonitorBehavior target) @@ -332,6 +336,10 @@ public sealed partial class MainWindow : WindowEx, BOOL value = true; PInvoke.DwmSetWindowAttribute(_hwnd, DWMWINDOWATTRIBUTE.DWMWA_CLOAK, &value, (uint)sizeof(BOOL)); } + + // Because we're only cloaking the window, bury it at the bottom in case something can + // see it - e.g. some accessibility helper (note: this also removes the top-most status). + PInvoke.SetWindowPos(_hwnd, HWND.HWND_BOTTOM, 0, 0, 0, 0, SET_WINDOW_POS_FLAGS.SWP_NOMOVE | SET_WINDOW_POS_FLAGS.SWP_NOSIZE); } private void Uncloak() diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/NativeMethods.txt b/src/modules/cmdpal/Microsoft.CmdPal.UI/NativeMethods.txt index 981c283815..165933fe93 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/NativeMethods.txt +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/NativeMethods.txt @@ -6,6 +6,8 @@ SetForegroundWindow GetWindowRect GetCursorPos SetWindowPos +HWND_TOPMOST +HWND_BOTTOM IsIconic RegisterHotKey UnregisterHotKey