浏览代码

Merge pull request #7450 from ngarside/windows-position

Fix offset window position
Max Katz 3 年之前
父节点
当前提交
2bc89e79be
共有 1 个文件被更改,包括 23 次插入1 次删除
  1. 23 1
      src/Windows/Avalonia.Win32/WindowImpl.cs

+ 23 - 1
src/Windows/Avalonia.Win32/WindowImpl.cs

@@ -469,10 +469,14 @@ namespace Avalonia.Win32
             {
             {
                 GetWindowRect(_hwnd, out var rc);
                 GetWindowRect(_hwnd, out var rc);
 
 
-                return new PixelPoint(rc.left, rc.top);
+                var border = HiddenBorderSize;
+                return new PixelPoint(rc.left + border.Width, rc.top + border.Height);
             }
             }
             set
             set
             {
             {
+                var border = HiddenBorderSize;
+                value = new PixelPoint(value.X - border.Width, value.Y - border.Height);
+
                 SetWindowPos(
                 SetWindowPos(
                     Handle.Handle,
                     Handle.Handle,
                     IntPtr.Zero,
                     IntPtr.Zero,
@@ -486,6 +490,24 @@ namespace Avalonia.Win32
 
 
         private bool HasFullDecorations => _windowProperties.Decorations == SystemDecorations.Full;
         private bool HasFullDecorations => _windowProperties.Decorations == SystemDecorations.Full;
 
 
+        private PixelSize HiddenBorderSize
+        {
+            get
+            {
+                // Windows 10 and 11 add a 7 pixel invisible border on the left/right/bottom of windows for resizing
+                if (Win32Platform.WindowsVersion.Major < 10 || !HasFullDecorations)
+                {
+                    return PixelSize.Empty;
+                }
+
+                DwmGetWindowAttribute(_hwnd, (int)DwmWindowAttribute.DWMWA_EXTENDED_FRAME_BOUNDS, out var clientRect, Marshal.SizeOf(typeof(RECT)));
+                GetWindowRect(_hwnd, out var frameRect);
+                var borderWidth = GetSystemMetrics(SystemMetric.SM_CXBORDER);
+
+                return new PixelSize(clientRect.left - frameRect.left - borderWidth, 0);
+            }
+        }
+
         public void Move(PixelPoint point) => Position = point;
         public void Move(PixelPoint point) => Position = point;
 
 
         public void SetMinMaxSize(Size minSize, Size maxSize)
         public void SetMinMaxSize(Size minSize, Size maxSize)