using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace PckStudio.Core.Extensions { public static class CursorExtensions { [StructLayout(LayoutKind.Sequential)] struct PointStruct { public Int32 x; public Int32 y; } [StructLayout(LayoutKind.Sequential)] struct CursorInfoStruct { /// The structure size in bytes that must be set via calling Marshal.SizeOf(typeof(CursorInfoStruct)). public Int32 cbSize; /// The cursor state: 0 == hidden, 1 == showing, 2 == suppressed (is supposed to be when finger touch is used, but in practice finger touch results in 0, not 2) public Int32 flags; /// A handle to the cursor. public IntPtr hCursor; /// The cursor screen coordinates. public PointStruct pt; } /// Must initialize cbSize [DllImport("user32.dll")] static extern bool GetCursorInfo(ref CursorInfoStruct pci); public static bool IsVisible(this Cursor _) { CursorInfoStruct pci = new CursorInfoStruct(); pci.cbSize = Marshal.SizeOf(typeof(CursorInfoStruct)); GetCursorInfo(ref pci); // const Int32 hidden = 0x00; const Int32 showing = 0x01; // const Int32 suppressed = 0x02; bool isVisible = ((pci.flags & showing) != 0); return isVisible; } } }