get current mouse cursor type(获取当前鼠标光标类型)
问题描述
如何获取当前的 GLOBAL 鼠标光标类型(沙漏/箭头/..)?在 Windows 中.
How do I get the current GLOBAL mouse cursor type (hourglass/arrow/..)? In Windows.
全局 - 我需要它即使鼠标在我的应用程序之外,或者即使我的程序是无窗口的.
Global - I need it even if the mouse is ouside of my application or even if my program is windlowless.
在 C#、Delphi 或纯 winapi 中,没关系...
In C#, Delphi or pure winapi, nevermind...
非常感谢您!
推荐答案
多年后,是时候回答我自己的问题了.以下是在 C# 中检查当前全局光标是否为沙漏的方法(如果需要,请根据自己的需要扩展代码):
After thee years its time to answer my own question. Here's how you check if the current global cursor is hourglass in C# (extend the code for you own needs if you need):
private static bool IsWaitCursor()
{
    var h = Cursors.WaitCursor.Handle;
    CURSORINFO pci;
    pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
    GetCursorInfo(out pci);
    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")]
static extern bool GetCursorInfo(out CURSORINFO pci);
                        这篇关于获取当前鼠标光标类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:获取当前鼠标光标类型
				
        
 
            
        - 如何用自己压缩一个 IEnumerable 2022-01-01
 - 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
 - C# 中多线程网络服务器的模式 2022-01-01
 - WebMatrix WebSecurity PasswordSalt 2022-01-01
 - 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
 - MoreLinq maxBy vs LINQ max + where 2022-01-01
 - Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
 - C#MongoDB使用Builders查找派生对象 2022-09-04
 - 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
 - 输入按键事件处理程序 2022-01-01
 
						
						
						
						
						
				
				
				
				