获取当前鼠标光标类型

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

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

本文标题为:获取当前鼠标光标类型

基础教程推荐