diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Helpers/WindowExtensions.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Helpers/WindowExtensions.cs
index ee782766bc..aa6dde458b 100644
--- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Helpers/WindowExtensions.cs
+++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Helpers/WindowExtensions.cs
@@ -59,6 +59,16 @@ internal static class WindowExtensions
return wasSet;
}
+ ///
+ /// Returns true if the specified extended window style flag(s) are currently set on the window.
+ ///
+ internal static bool HasExtendedStyle(this Window window, WINDOW_EX_STYLE style)
+ {
+ var hWnd = GetWindowHwnd(window);
+ var currentStyle = (WINDOW_EX_STYLE)PInvoke.GetWindowLong(hWnd, WINDOW_LONG_PTR_INDEX.GWL_EXSTYLE);
+ return (currentStyle & style) != 0;
+ }
+
///
/// Sets the window corner preference
///
diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs
index a168176c85..f6d95e401d 100644
--- a/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs
+++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs
@@ -311,15 +311,26 @@ public sealed partial class MainWindow : WindowEx,
var rect = placement.rcNormalPosition;
var displayArea = DisplayArea.GetFromWindowId(AppWindow.Id, DisplayAreaFallback.Nearest) ?? DisplayArea.Primary;
+
+ // GetWindowPlacement returns rcNormalPosition in workspace coordinates for
+ // normal windows, but in screen coordinates for tool windows (WS_EX_TOOLWINDOW).
+ // HiddenOwnerWindowBehavior applies WS_EX_TOOLWINDOW to hide from taskbar/Alt+Tab,
+ // so we must check the current style before converting coordinates.
+ //
+ // To be on the safe side, we should consider the possibility that setting
+ // WS_EX_TOOLWINDOW failed or isn't applied while debugging.
+ var workArea = displayArea.WorkArea;
+ var isToolWindow = this.HasExtendedStyle(WINDOW_EX_STYLE.WS_EX_TOOLWINDOW);
+
_currentWindowPosition = new WindowPosition
{
- X = rect.X,
- Y = rect.Y,
+ X = rect.X + (isToolWindow ? 0 : workArea.X),
+ Y = rect.Y + (isToolWindow ? 0 : workArea.Y),
Width = rect.Width,
Height = rect.Height,
Dpi = (int)this.GetDpiForWindow(),
- ScreenWidth = displayArea.WorkArea.Width,
- ScreenHeight = displayArea.WorkArea.Height,
+ ScreenWidth = workArea.Width,
+ ScreenHeight = workArea.Height,
};
}