Browse Source

Correctly handle WM_DPICHANGED

We need to set the window position to the position in the message in
order to avoid #491. Fixes #491.
Steven Kirk 9 years ago
parent
commit
2f42688919
1 changed files with 5 additions and 1 deletions
  1. 5 1
      src/Windows/Avalonia.Win32/WindowImpl.cs

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

@@ -90,6 +90,8 @@ namespace Avalonia.Win32
                     value *= Scaling;
                     value += BorderThickness;
 
+                    System.Diagnostics.Debug.WriteLine($"Set client size to {value}");
+
                     UnmanagedMethods.SetWindowPos(
                         _hwnd,
                         IntPtr.Zero,
@@ -405,9 +407,11 @@ namespace Avalonia.Win32
 
                 case UnmanagedMethods.WindowsMessage.WM_DPICHANGED:
                     var dpi = (int)wParam & 0xffff;
+                    var newDisplayRect = (UnmanagedMethods.RECT)Marshal.PtrToStructure(lParam, typeof(UnmanagedMethods.RECT));
+                    Position = new Point(newDisplayRect.left, newDisplayRect.top);
                     _scaling = dpi / 96.0;
                     ScalingChanged?.Invoke(_scaling);
-                    break;
+                    return IntPtr.Zero;
 
                 case UnmanagedMethods.WindowsMessage.WM_KEYDOWN:
                 case UnmanagedMethods.WindowsMessage.WM_SYSKEYDOWN: