diff --git a/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs b/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs index f31d5b2fc3c..872e5e92d81 100644 --- a/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs +++ b/src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs @@ -1183,7 +1183,12 @@ public static extern IntPtr CreateWindowEx( [DllImport("user32.dll", EntryPoint = "DefWindowProcW")] public static extern IntPtr DefWindowProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam); - + + public const int SC_MOUSEMOVE = 0xf012; + + [DllImport("user32.dll", CharSet = CharSet.Unicode, EntryPoint = "SendMessageW")] + public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam); + [DllImport("user32.dll", EntryPoint = "DispatchMessageW")] public static extern IntPtr DispatchMessage(ref MSG lpmsg); diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index 5651e3b5097..ba4a828f1c2 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -667,8 +667,22 @@ public void SetParent(IWindowImpl? parent) public void BeginMoveDrag(PointerPressedEventArgs e) { e.Pointer.Capture(null); - DefWindowProc(_hwnd, (int)WindowsMessage.WM_NCLBUTTONDOWN, - new IntPtr((int)HitTestValues.HTCAPTION), IntPtr.Zero); + + // Mouse.LeftButton actually reflects the primary button user is using. + // So we don't need to check whether the button has been swapped here. + if (e.Pointer.IsPrimary) + { + // SendMessage's return value is dependent on the message send. WM_SYSCOMMAND + // and WM_LBUTTONUP return value just signify whether the WndProc handled the + // message or not, so they are not interesting + + SendMessage(_hwnd, (int)WindowsMessage.WM_SYSCOMMAND, (IntPtr)SC_MOUSEMOVE, IntPtr.Zero); + SendMessage(_hwnd, (int)WindowsMessage.WM_LBUTTONUP, IntPtr.Zero, IntPtr.Zero); + } + else + { + throw new InvalidOperationException("BeginMoveDrag Failed"); + } } public void BeginResizeDrag(WindowEdge edge, PointerPressedEventArgs e)