fix: window creep after restart

This commit is contained in:
枫雨
2023-05-30 21:17:40 +08:00
parent cecefe52fc
commit 346ac44b08

View File

@@ -175,6 +175,24 @@ namespace MaaWpfGui.Helper
if (wp.ShowCmd == SwShownormal && GetWindowRect(window.Handle, out Rect rect))
{
wp.NormalPosition = rect;
// rect is screen coordinates, wp is workspace coordinates
if (SetWindowPlacement(window.Handle, ref wp)
&& GetWindowPlacement(window.Handle, out WindowPlacement currentWp)
&& GetWindowRect(window.Handle, out Rect currentRect))
{
var taskbarWidth = currentRect.Left - currentWp.NormalPosition.Left;
var taskbarHeight = currentRect.Top - currentWp.NormalPosition.Top;
if (taskbarWidth != 0 || taskbarHeight != 0)
{
rect.Left -= taskbarWidth;
rect.Right -= taskbarWidth;
rect.Top -= taskbarHeight;
rect.Bottom -= taskbarHeight;
wp.NormalPosition = rect;
SetWindowPlacement(window.Handle, ref wp);
}
}
}
return true;