C# (WinForms) - 查找光标的颜色

C# (WinForms) - Find Colour of Cursor

我的目标:

我的难度:

我的当前代码:

    public static Color RetrieveColour(Point Coordinates)
    {
        //Use this 'image' to create a Graphics class.
        using (Graphics Destination = Graphics.FromImage(ScreenPixel))
        {
             //Creates a graphic from the specified handler to a window.
             //In this case, it uses a handler which has been initialised to zero.
             using (Graphics Source = Graphics.FromHwnd(IntPtr.Zero))
             {
                 //Handler from the source device context.
                 IntPtr HandlerSourceDC = Source.GetHdc();
                 //Handler to the destination device context.
                 IntPtr HandlerDC = Destination.GetHdc();
                 //BitBlt is responsible for doing the copying.
                 //Returns a non-zero value for upon success.
                 int retval = BitBlt(HandlerDC, 0, 0, 1, 1, HandlerSourceDC, Coordinates.X, Coordinates.Y, (int)CopyPixelOperation.SourceCopy);
                 //Release the handlers.
                 Destination.ReleaseHdc();
                 Source.ReleaseHdc();
             }
        }
        //Retrieve the colour of the pixel at the specified coordinates.
        return ScreenPixel.GetPixel(0, 0);
    }

我应该补充一点,它应该可以与非 Windows 游标一起使用。我的意思是来自其他应用程序的自定义光标(如果这对未来的答案有任何影响)。

据我目前所知,您能够做到这一点的唯一方法是创建一个可以充当用户之间中介的自定义驱动程序。

我读得不多,但你可能想看看这个项目 http://www.codeproject.com/KB/cs/DesktopCaptureWithMouse.aspx?display=Print

之前在此处发布:C# - Capturing the Mouse cursor image