Add cursor info class

This commit is contained in:
Jack251970 2025-07-23 13:41:01 +08:00
parent 1946afbfe8
commit cbbd09b8a5
2 changed files with 27 additions and 5 deletions

View file

@ -0,0 +1,26 @@
using System.Drawing;
using System.Runtime.InteropServices;
using Windows.Win32;
namespace Flow.Launcher.Infrastructure;
/// <summary>
/// Contains full information about a cursor.
/// </summary>
/// <remarks>
/// Use this class to replace the System.Windows.Forms.Cursor class which can cause possible System.PlatformNotSupportedException.
/// </remarks>
public class CursorInfo
{
public static Point Position
{
get
{
if (!PInvoke.GetCursorPos(out var pt))
{
Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
}
return pt;
}
}
}

View file

@ -102,11 +102,7 @@ public class MonitorInfo
/// <returns>The display monitor that contains the cursor, or null if no monitor is found.</returns>
public static unsafe MonitorInfo GetCursorDisplayMonitor()
{
if (!PInvoke.GetCursorPos(out var pt))
{
Marshal.ThrowExceptionForHR(Marshal.GetLastWin32Error());
}
var cursorMonitor = PInvoke.MonitorFromPoint(pt, MONITOR_FROM_FLAGS.MONITOR_DEFAULTTONEAREST);
var cursorMonitor = PInvoke.MonitorFromPoint(CursorInfo.Position, MONITOR_FROM_FLAGS.MONITOR_DEFAULTTONEAREST);
MonitorInfo cursorMonitorInfo = null;
var callback = new MONITORENUMPROC((monitor, deviceContext, rect, data) =>
{