Exemplo n.º 1
0
        static Bitmap Win32CaptureCursor(ref int x, ref int y)
        {
            Bitmap bmp;
            IntPtr hicon;
            CURSORINFO ci = new CURSORINFO();
            ICONINFO icInfo;
            ci.cbSize = Marshal.SizeOf(ci);
            if (Win32API.GetCursorInfo(out ci)) {
                if (ci.flags == Win32API.CURSOR_SHOWING) {
                    hicon = Win32API.CopyIcon(ci.hCursor);
                    if (Win32API.GetIconInfo(hicon, out icInfo)) {
                        x = ci.ptScreenPos.x - ((int)icInfo.xHotspot);
                        y = ci.ptScreenPos.y - ((int)icInfo.yHotspot);

                        Icon ic = Icon.FromHandle(hicon);
                        bmp = ic.ToBitmap();
                        return bmp;
                    }
                }
            }

            return null;
        }
Exemplo n.º 2
0
 public static extern bool GetCursorInfo(out CURSORINFO pci);