From 898491304984412ad58bed1f98fef0d755e39446 Mon Sep 17 00:00:00 2001 From: Jaex Date: Tue, 14 Jun 2022 22:20:55 +0300 Subject: [PATCH] #5055: Get cursor size from registry and use it while drawing --- ShareX.HelpersLib/CursorData.cs | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/ShareX.HelpersLib/CursorData.cs b/ShareX.HelpersLib/CursorData.cs index b41ed5ea5..9c22f71cb 100644 --- a/ShareX.HelpersLib/CursorData.cs +++ b/ShareX.HelpersLib/CursorData.cs @@ -33,6 +33,7 @@ public class CursorData { public IntPtr Handle { get; private set; } public Point Position { get; private set; } + public Size Size { get; private set; } public bool IsVisible { get; private set; } public CursorData() @@ -53,6 +54,7 @@ public void UpdateCursorData() { Handle = cursorInfo.hCursor; Position = cursorInfo.ptScreenPos; + Size = GetCursorSize(); IsVisible = cursorInfo.flags == NativeConstants.CURSOR_SHOWING; if (IsVisible) @@ -82,6 +84,19 @@ public void UpdateCursorData() } } + private Size GetCursorSize() + { + try + { + int cursorBaseSize = RegistryHelpers.GetValueDWord(@"Control Panel\Cursors", "CursorBaseSize"); + return new Size(cursorBaseSize, cursorBaseSize); + } + catch + { + return Size.Empty; + } + } + public void DrawCursor(Image img) { DrawCursor(img, Point.Empty); @@ -91,13 +106,11 @@ public void DrawCursor(Image img, Point offset) { if (IsVisible) { - Point drawPosition = new Point(Position.X - offset.X, Position.Y - offset.Y); - drawPosition = CaptureHelpers.ScreenToClient(drawPosition); - using (Graphics g = Graphics.FromImage(img)) - using (Icon icon = Icon.FromHandle(Handle)) { - g.DrawIcon(icon, drawPosition.X, drawPosition.Y); + IntPtr hdcDest = g.GetHdc(); + + DrawCursor(hdcDest, offset); } } } @@ -114,7 +127,7 @@ public void DrawCursor(IntPtr hdcDest, Point offset) Point drawPosition = new Point(Position.X - offset.X, Position.Y - offset.Y); drawPosition = CaptureHelpers.ScreenToClient(drawPosition); - NativeMethods.DrawIconEx(hdcDest, drawPosition.X, drawPosition.Y, Handle, 0, 0, 0, IntPtr.Zero, NativeConstants.DI_NORMAL); + NativeMethods.DrawIconEx(hdcDest, drawPosition.X, drawPosition.Y, Handle, Size.Width, Size.Height, 0, IntPtr.Zero, NativeConstants.DI_NORMAL); } } }