如何获取当前的 GLOBAL 鼠标光标类型(沙漏/箭头/..)?在 Windows 中。
全局 - 我需要它即使鼠标在我的应用程序之外或者即使我的程序没有窗口。
在 C#、Delphi 或纯 winapi 中,没关系...
非常感谢您!!
最佳答案
过了这么多年,是时候回答我自己的问题了。以下是在 C# 中检查当前全局光标是否为沙漏的方法(如果需要,请根据自己的需要扩展代码):
private static bool IsWaitCursor()
{
var h = Cursors.WaitCursor.Handle;
CURSORINFO pci;
pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
if(!GetCursorInfo(out pci))
throw new Win32Exception(Marshal.GetLastWin32Error());
return pci.hCursor == h;
}
[StructLayout(LayoutKind.Sequential)]
struct POINT
{
public Int32 x;
public Int32 y;
}
[StructLayout(LayoutKind.Sequential)]
struct CURSORINFO
{
public Int32 cbSize; // Specifies the size, in bytes, of the structure.
// The caller must set this to Marshal.SizeOf(typeof(CURSORINFO)).
public Int32 flags; // Specifies the cursor state. This parameter can be one of the following values:
// 0 The cursor is hidden.
// CURSOR_SHOWING The cursor is showing.
public IntPtr hCursor; // Handle to the cursor.
public POINT ptScreenPos; // A POINT structure that receives the screen coordinates of the cursor.
}
[DllImport("user32.dll", SetLastError = true)]
static extern bool GetCursorInfo(out CURSORINFO pci);
关于c# - 获取当前鼠标光标类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/457069/