コード例 #1
0
ファイル: Screenshot.cs プロジェクト: swipswaps/OpenScreen
        /// <summary>
        /// Adds a cursor to a screenshot.
        /// </summary>
        /// <param name="graphics">Drawing surface.</param>
        /// <param name="bounds">Screen bounds.</param>
        private static void AddCursorToScreenshot(Graphics graphics, Rectangle bounds)
        {
            if (graphics == null)
            {
                throw new ArgumentNullException(nameof(graphics));
            }

            MouseCursor.CursorInfo pci;
            pci.cbSize = Marshal.SizeOf(typeof(MouseCursor.CursorInfo));

            if (!MouseCursor.GetCursorInfo(out pci))
            {
                return;
            }

            if (pci.flags != MouseCursor.CursorShowing)
            {
                return;
            }

            const int logicalWidth  = 0;
            const int logicalHeight = 0;
            const int indexOfFrame  = 0;

            MouseCursor.DrawIconEx(graphics.GetHdc(), pci.ptScreenPos.x - bounds.X,
                                   pci.ptScreenPos.y - bounds.Y, pci.hCursor, logicalWidth,
                                   logicalHeight, indexOfFrame, IntPtr.Zero, MouseCursor.DiNormal);

            graphics.ReleaseHdc();
        }