浏览代码

force mousecursor if the mouse is over the window

without the call of SetCursor the cursor will only be updated once the
mouse is moved.

this fixes #1536
boombuler 7 年之前
父节点
当前提交
5a5fc13632
共有 2 个文件被更改,包括 8 次插入2 次删除
  1. 3 0
      src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs
  2. 5 2
      src/Windows/Avalonia.Win32/WindowImpl.cs

+ 3 - 0
src/Windows/Avalonia.Win32/Interop/UnmanagedMethods.cs

@@ -849,6 +849,9 @@ namespace Avalonia.Win32.Interop
             return SetClassLong64(hWnd, nIndex, dwNewLong);
         }
 
+        [DllImport("user32.dll", EntryPoint = "SetCursor")]
+        internal static extern IntPtr SetCursor(IntPtr hCursor);
+
         [DllImport("ole32.dll", PreserveSig = true)]
         internal static extern int CoCreateInstance(ref Guid clsid,
             IntPtr ignore1, int ignore2, ref Guid iid, [MarshalAs(UnmanagedType.IUnknown), Out] out object pUnkOuter);

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

@@ -383,8 +383,11 @@ namespace Avalonia.Win32
 
         public void SetCursor(IPlatformHandle cursor)
         {
-            UnmanagedMethods.SetClassLong(_hwnd, UnmanagedMethods.ClassLongIndex.GCL_HCURSOR,
-                cursor?.Handle ?? DefaultCursor);
+            var hCursor = cursor?.Handle ?? DefaultCursor;
+            UnmanagedMethods.SetClassLong(_hwnd, UnmanagedMethods.ClassLongIndex.GCL_HCURSOR, hCursor);
+
+            if (_owner.IsPointerOver)
+                UnmanagedMethods.SetCursor(hCursor);
         }
 
         protected virtual IntPtr CreateWindowOverride(ushort atom)