Home >Backend Development >C#.Net Tutorial >C# development example-customized screenshot tool (10) including the mouse pointer shape in the screenshot

C# development example-customized screenshot tool (10) including the mouse pointer shape in the screenshot

黄舟
黄舟Original
2017-03-14 13:41:472245browse

When writing a help document, the intercepted pictureif there is a mouse pointer shape, it will look more intuitive and friendly. Next, let’s talk about how to include the mouse pointer shape in the screenshot.

Add structure CURSORINFO:

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

Declare API:

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

Define enumeration value:

private const int CURSOR_SHOWING = 0x00000001;

Add method:

        /// <summary>
        /// 将鼠标指针形状绘制到屏幕截图上
        /// </summary>
        /// <param name="g"></param>
        private void DrawCursorImageToScreenImage(ref Graphics g)
        {
            if (!this.IsCutCursor) { return; }

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

Add method call:

OK, let’s take a screenshot again!


The above is the detailed content of C# development example-customized screenshot tool (10) including the mouse pointer shape in the screenshot. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn