c# - 获取当前鼠标光标类型

标签 c# delphi winapi vb6

如何获取当前的 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/

相关文章:

c# - 如何过滤 dxChart 数据

c# - CIL 'fault' 子句与 C# 中的 'catch' 子句有何不同?

delphi - 是否有类似StrToCurr的函数可以处理数千个分隔符?

delphi - 隐藏 VCL 类

c++ - 如何复制已经打开的文件?

c# - 如何从 byte[] 中读取整数

c# - System.Net.Http.HttpClient 如何选择认证类型?

delphi - 无法选择过程作为事件 OnMouseDown 的选项

windows - 搁置线程是最优的吗?

c++ - WaitForSingleObject 与互锁*