获取当前鼠标光标的类型 [英] get current mouse cursor type

查看:832
本文介绍了获取当前鼠标光标的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何得到目前全球鼠标光标的类型(沙漏/箭头/ ..)?在Windows

How do I get the current GLOBAL mouse cursor type (hourglass/arrow/..)? In Windows.

全球 - 我需要它的即使鼠标是ouside我的应用程序或即使我的计划是windlowless

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);

这篇关于获取当前鼠标光标的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆