c#截图包含鼠标指针

发布时间:2020-02-27 10:40:54.003编辑:佚名阅读(224)

添加结构CURSORINFO:

[StructLayout(LayoutKind.Sequential)]
struct CURSORINFO
{
    public int cbSize;
    public int flags;
    public IntPtr hCursor;
    public Point ptScreenPos;
}

声明API:

[DllImport("user32.dll")]
static extern bool GetCursorInfo(out CURSORINFO pci);

定义枚举值:

private const int CURSOR_SHOWING = 0x00000001;

添加方法:

/// <summary>
/// 将鼠标指针形状绘制到屏幕截图上
/// </summary>
/// <param name="g"></param>
private void DrawCursorImageToScreenImage(ref Graphics g)
{
    CURSORINFO vCurosrInfo;
    vCurosrInfo.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
    GetCursorInfo(out vCurosrInfo);
    if ((vCurosrInfo.flags & CURSOR_SHOWING) != CURSOR_SHOWING) return;
    Cursor vCursor = new Cursor(vCurosrInfo.hCursor);
    Rectangle vRectangle = new Rectangle(new Point(vCurosrInfo.ptScreenPos.X - vCursor.HotSpot.X, vCurosrInfo.ptScreenPos.Y - vCursor.HotSpot.Y), vCursor.Size);
    vCursor.Draw(g, vRectangle);
}

添加方法调用:

  关键字:c#截图包含鼠标指针


鼓掌

0

正能量

0

0

呵呵

0


评论区