From b8ecf534f8d4016e9de93c1f5b5c5fd2473b74ca Mon Sep 17 00:00:00 2001 From: Michael Clayton Date: Wed, 18 Oct 2023 19:36:08 +0100 Subject: [PATCH] [MouseJump] cleaning up Tests / NativeMethods (#27511) --- .../Helpers/MouseHelperTests.cs | 8 +-- .../Models/Drawing/RectangleInfoTests.cs | 46 ++++++------- .../Models/Drawing/SizeInfoTests.cs | 36 +++++------ .../MouseJumpUI/Helpers/MouseHelper.cs | 12 +++- .../MouseJumpUI/Models/Drawing/PointInfo.cs | 10 +-- .../Models/Drawing/RectangleInfo.cs | 64 ++++++++++--------- .../MouseJumpUI/Models/Drawing/SizeInfo.cs | 13 ++-- .../MouseJumpUI/NativeMethods/Core/DWORD.cs | 5 ++ .../MouseJumpUI/NativeMethods/Core/HANDLE.cs | 2 +- .../MouseJumpUI/NativeMethods/Core/HDC.cs | 4 ++ .../NativeMethods/Core/HMONITOR.cs | 6 +- .../MouseJumpUI/NativeMethods/Core/HWND.cs | 4 ++ .../MouseJumpUI/NativeMethods/Core/LPARAM.cs | 4 +- .../MouseJumpUI/NativeMethods/Core/LPCRECT.cs | 4 +- .../MouseJumpUI/NativeMethods/Core/LPPOINT.cs | 4 +- .../MouseJumpUI/NativeMethods/Core/LPRECT.cs | 4 +- .../NativeMethods/Core/ULONG_PTR.cs | 2 +- .../User32/Graphics/Gdi/User32.MONITORINFO.cs | 2 +- .../Input/KeyboardAndMouse/User32.LPINPUT.cs | 2 +- 19 files changed, 134 insertions(+), 98 deletions(-) diff --git a/src/modules/MouseUtils/MouseJumpUI.UnitTests/Helpers/MouseHelperTests.cs b/src/modules/MouseUtils/MouseJumpUI.UnitTests/Helpers/MouseHelperTests.cs index e0267d47870c..7a300f73758b 100644 --- a/src/modules/MouseUtils/MouseJumpUI.UnitTests/Helpers/MouseHelperTests.cs +++ b/src/modules/MouseUtils/MouseJumpUI.UnitTests/Helpers/MouseHelperTests.cs @@ -25,13 +25,13 @@ public TestCase(PointInfo previewLocation, SizeInfo previewSize, RectangleInfo this.ExpectedResult = expectedResult; } - public PointInfo PreviewLocation { get; set; } + public PointInfo PreviewLocation { get; } - public SizeInfo PreviewSize { get; set; } + public SizeInfo PreviewSize { get; } - public RectangleInfo DesktopBounds { get; set; } + public RectangleInfo DesktopBounds { get; } - public PointInfo ExpectedResult { get; set; } + public PointInfo ExpectedResult { get; } } public static IEnumerable GetTestCases() diff --git a/src/modules/MouseUtils/MouseJumpUI.UnitTests/Models/Drawing/RectangleInfoTests.cs b/src/modules/MouseUtils/MouseJumpUI.UnitTests/Models/Drawing/RectangleInfoTests.cs index 24d3bac4e106..b90292cf491e 100644 --- a/src/modules/MouseUtils/MouseJumpUI.UnitTests/Models/Drawing/RectangleInfoTests.cs +++ b/src/modules/MouseUtils/MouseJumpUI.UnitTests/Models/Drawing/RectangleInfoTests.cs @@ -23,30 +23,30 @@ public TestCase(RectangleInfo rectangle, PointInfo point, RectangleInfo expected this.ExpectedResult = expectedResult; } - public RectangleInfo Rectangle { get; set; } + public RectangleInfo Rectangle { get; } - public PointInfo Point { get; set; } + public PointInfo Point { get; } - public RectangleInfo ExpectedResult { get; set; } + public RectangleInfo ExpectedResult { get; } } public static IEnumerable GetTestCases() { // zero-sized - yield return new[] { new TestCase(new(0, 0, 0, 0), new(0, 0), new(0, 0, 0, 0)), }; + yield return new object[] { new TestCase(new(0, 0, 0, 0), new(0, 0), new(0, 0, 0, 0)), }; // zero-origin - yield return new[] { new TestCase(new(0, 0, 200, 200), new(100, 100), new(0, 0, 200, 200)), }; - yield return new[] { new TestCase(new(0, 0, 200, 200), new(500, 500), new(400, 400, 200, 200)), }; - yield return new[] { new TestCase(new(0, 0, 800, 600), new(1000, 1000), new(600, 700, 800, 600)), }; + yield return new object[] { new TestCase(new(0, 0, 200, 200), new(100, 100), new(0, 0, 200, 200)), }; + yield return new object[] { new TestCase(new(0, 0, 200, 200), new(500, 500), new(400, 400, 200, 200)), }; + yield return new object[] { new TestCase(new(0, 0, 800, 600), new(1000, 1000), new(600, 700, 800, 600)), }; // non-zero origin - yield return new[] { new TestCase(new(1000, 2000, 200, 200), new(100, 100), new(0, 0, 200, 200)), }; - yield return new[] { new TestCase(new(1000, 2000, 200, 200), new(500, 500), new(400, 400, 200, 200)), }; - yield return new[] { new TestCase(new(1000, 2000, 800, 600), new(1000, 1000), new(600, 700, 800, 600)), }; + yield return new object[] { new TestCase(new(1000, 2000, 200, 200), new(100, 100), new(0, 0, 200, 200)), }; + yield return new object[] { new TestCase(new(1000, 2000, 200, 200), new(500, 500), new(400, 400, 200, 200)), }; + yield return new object[] { new TestCase(new(1000, 2000, 800, 600), new(1000, 1000), new(600, 700, 800, 600)), }; // negative result - yield return new[] { new TestCase(new(0, 0, 1000, 1200), new(300, 300), new(-200, -300, 1000, 1200)), }; + yield return new object[] { new TestCase(new(0, 0, 1000, 1200), new(300, 300), new(-200, -300, 1000, 1200)), }; } [TestMethod] @@ -74,53 +74,53 @@ public TestCase(RectangleInfo inner, RectangleInfo outer, RectangleInfo expected this.ExpectedResult = expectedResult; } - public RectangleInfo Inner { get; set; } + public RectangleInfo Inner { get; } - public RectangleInfo Outer { get; set; } + public RectangleInfo Outer { get; } - public RectangleInfo ExpectedResult { get; set; } + public RectangleInfo ExpectedResult { get; } } public static IEnumerable GetTestCases() { // already inside - obj fills bounds exactly - yield return new[] + yield return new object[] { new TestCase(new(0, 0, 100, 100), new(0, 0, 100, 100), new(0, 0, 100, 100)), }; // already inside - obj exactly in each corner - yield return new[] + yield return new object[] { new TestCase(new(0, 0, 100, 100), new(0, 0, 200, 200), new(0, 0, 100, 100)), }; - yield return new[] + yield return new object[] { new TestCase(new(100, 0, 100, 100), new(0, 0, 200, 200), new(100, 0, 100, 100)), }; - yield return new[] + yield return new object[] { new TestCase(new(0, 100, 100, 100), new(0, 0, 200, 200), new(0, 100, 100, 100)), }; - yield return new[] + yield return new object[] { new TestCase(new(100, 100, 100, 100), new(0, 0, 200, 200), new(100, 100, 100, 100)), }; // move inside - obj outside each corner - yield return new[] + yield return new object[] { new TestCase(new(-50, -50, 100, 100), new(0, 0, 200, 200), new(0, 0, 100, 100)), }; - yield return new[] + yield return new object[] { new TestCase(new(250, -50, 100, 100), new(0, 0, 200, 200), new(100, 0, 100, 100)), }; - yield return new[] + yield return new object[] { new TestCase(new(-50, 250, 100, 100), new(0, 0, 200, 200), new(0, 100, 100, 100)), }; - yield return new[] + yield return new object[] { new TestCase(new(150, 150, 100, 100), new(0, 0, 200, 200), new(100, 100, 100, 100)), }; diff --git a/src/modules/MouseUtils/MouseJumpUI.UnitTests/Models/Drawing/SizeInfoTests.cs b/src/modules/MouseUtils/MouseJumpUI.UnitTests/Models/Drawing/SizeInfoTests.cs index 5e0bd3d4fee8..8de9be37b660 100644 --- a/src/modules/MouseUtils/MouseJumpUI.UnitTests/Models/Drawing/SizeInfoTests.cs +++ b/src/modules/MouseUtils/MouseJumpUI.UnitTests/Models/Drawing/SizeInfoTests.cs @@ -23,28 +23,28 @@ public TestCase(SizeInfo obj, SizeInfo bounds, SizeInfo expectedResult) this.ExpectedResult = expectedResult; } - public SizeInfo Obj { get; set; } + public SizeInfo Obj { get; } - public SizeInfo Bounds { get; set; } + public SizeInfo Bounds { get; } - public SizeInfo ExpectedResult { get; set; } + public SizeInfo ExpectedResult { get; } } public static IEnumerable GetTestCases() { // identity tests - yield return new[] { new TestCase(new(512, 384), new(512, 384), new(512, 384)), }; - yield return new[] { new TestCase(new(1024, 768), new(1024, 768), new(1024, 768)), }; + yield return new object[] { new TestCase(new(512, 384), new(512, 384), new(512, 384)), }; + yield return new object[] { new TestCase(new(1024, 768), new(1024, 768), new(1024, 768)), }; // general tests - yield return new[] { new TestCase(new(512, 384), new(2048, 1536), new(2048, 1536)), }; - yield return new[] { new TestCase(new(2048, 1536), new(1024, 768), new(1024, 768)), }; + yield return new object[] { new TestCase(new(512, 384), new(2048, 1536), new(2048, 1536)), }; + yield return new object[] { new TestCase(new(2048, 1536), new(1024, 768), new(1024, 768)), }; // scale to fit width - yield return new[] { new TestCase(new(512, 384), new(2048, 3072), new(2048, 1536)), }; + yield return new object[] { new TestCase(new(512, 384), new(2048, 3072), new(2048, 1536)), }; // scale to fit height - yield return new[] { new TestCase(new(512, 384), new(4096, 1536), new(2048, 1536)), }; + yield return new object[] { new TestCase(new(512, 384), new(4096, 1536), new(2048, 1536)), }; } [TestMethod] @@ -70,28 +70,28 @@ public TestCase(SizeInfo obj, SizeInfo bounds, decimal expectedResult) this.ExpectedResult = expectedResult; } - public SizeInfo Obj { get; set; } + public SizeInfo Obj { get; } - public SizeInfo Bounds { get; set; } + public SizeInfo Bounds { get; } - public decimal ExpectedResult { get; set; } + public decimal ExpectedResult { get; } } public static IEnumerable GetTestCases() { // identity tests - yield return new[] { new TestCase(new(512, 384), new(512, 384), 1), }; - yield return new[] { new TestCase(new(1024, 768), new(1024, 768), 1), }; + yield return new object[] { new TestCase(new(512, 384), new(512, 384), 1), }; + yield return new object[] { new TestCase(new(1024, 768), new(1024, 768), 1), }; // general tests - yield return new[] { new TestCase(new(512, 384), new(2048, 1536), 4), }; - yield return new[] { new TestCase(new(2048, 1536), new(1024, 768), 0.5M), }; + yield return new object[] { new TestCase(new(512, 384), new(2048, 1536), 4), }; + yield return new object[] { new TestCase(new(2048, 1536), new(1024, 768), 0.5M), }; // scale to fit width - yield return new[] { new TestCase(new(512, 384), new(2048, 3072), 4), }; + yield return new object[] { new TestCase(new(512, 384), new(2048, 3072), 4), }; // scale to fit height - yield return new[] { new TestCase(new(512, 384), new(4096, 1536), 4), }; + yield return new object[] { new TestCase(new(512, 384), new(4096, 1536), 4), }; } [TestMethod] diff --git a/src/modules/MouseUtils/MouseJumpUI/Helpers/MouseHelper.cs b/src/modules/MouseUtils/MouseJumpUI/Helpers/MouseHelper.cs index 78eb9a496d82..3dea48f6c9a7 100644 --- a/src/modules/MouseUtils/MouseJumpUI/Helpers/MouseHelper.cs +++ b/src/modules/MouseUtils/MouseJumpUI/Helpers/MouseHelper.cs @@ -73,15 +73,21 @@ public static void SetCursorPosition(PointInfo location) // // setting the position a second time seems to fix this and moves the // cursor to the expected location (b) - var point = location.ToPoint(); + var target = location.ToPoint(); for (var i = 0; i < 2; i++) { - var result = User32.SetCursorPos(point.X, point.Y); + var result = User32.SetCursorPos(target.X, target.Y); if (!result) { throw new Win32Exception( Marshal.GetLastWin32Error()); } + + var current = MouseHelper.GetCursorPosition(); + if ((current.X == target.X) && (current.Y == target.Y)) + { + break; + } } // temporary workaround for issue #1273 @@ -128,7 +134,7 @@ private static decimal CalculateAbsoluteCoordinateX(decimal x) return (x * 65535) / User32.GetSystemMetrics(User32.SYSTEM_METRICS_INDEX.SM_CXSCREEN); } - internal static decimal CalculateAbsoluteCoordinateY(decimal y) + private static decimal CalculateAbsoluteCoordinateY(decimal y) { // If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute coordinates between 0 and 65,535. // see https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-mouseinput diff --git a/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/PointInfo.cs b/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/PointInfo.cs index 40e452a378dc..b5f406f5696e 100644 --- a/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/PointInfo.cs +++ b/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/PointInfo.cs @@ -32,17 +32,17 @@ public decimal Y get; } - public SizeInfo ToSize() - { - return new((int)this.X, (int)this.Y); - } - public PointInfo Scale(decimal scalingFactor) => new(this.X * scalingFactor, this.Y * scalingFactor); public PointInfo Offset(PointInfo amount) => new(this.X + amount.X, this.Y + amount.Y); public Point ToPoint() => new((int)this.X, (int)this.Y); + public SizeInfo ToSize() + { + return new((int)this.X, (int)this.Y); + } + public override string ToString() { return "{" + diff --git a/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/RectangleInfo.cs b/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/RectangleInfo.cs index af46b8547080..6605e2870fc4 100644 --- a/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/RectangleInfo.cs +++ b/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/RectangleInfo.cs @@ -12,6 +12,8 @@ namespace MouseJumpUI.Models.Drawing; /// public sealed class RectangleInfo { + public static readonly RectangleInfo Empty = new(0, 0, 0, 0); + public RectangleInfo(decimal x, decimal y, decimal width, decimal height) { this.X = x; @@ -63,35 +65,15 @@ public decimal Height public decimal Bottom => this.Y + this.Height; - public SizeInfo Size => new(this.Width, this.Height); - - public PointInfo Location => new(this.X, this.Y); - public decimal Area => this.Width * this.Height; - /// - /// Adapted from https://github.com/dotnet/runtime - /// See https://github.com/dotnet/runtime/blob/dfd618dc648ba9b11dd0f8034f78113d69f223cd/src/libraries/System.Drawing.Primitives/src/System/Drawing/Rectangle.cs - /// - public bool Contains(RectangleInfo rect) => - (this.X <= rect.X) && (rect.X + rect.Width <= this.X + this.Width) && - (this.Y <= rect.Y) && (rect.Y + rect.Height <= this.Y + this.Height); - - public RectangleInfo Enlarge(PaddingInfo padding) => new( - this.X + padding.Left, - this.Y + padding.Top, - this.Width + padding.Horizontal, - this.Height + padding.Vertical); - - public RectangleInfo Offset(SizeInfo amount) => this.Offset(amount.Width, amount.Height); + public PointInfo Location => new(this.X, this.Y); - public RectangleInfo Offset(decimal dx, decimal dy) => new(this.X + dx, this.Y + dy, this.Width, this.Height); + public PointInfo Midpoint => new( + x: this.X + (this.Width / 2), + y: this.Y + (this.Height / 2)); - public RectangleInfo Scale(decimal scalingFactor) => new( - this.X * scalingFactor, - this.Y * scalingFactor, - this.Width * scalingFactor, - this.Height * scalingFactor); + public SizeInfo Size => new(this.Width, this.Height); public RectangleInfo Center(PointInfo point) => new( x: point.X - (this.Width / 2), @@ -99,10 +81,9 @@ public bool Contains(RectangleInfo rect) => width: this.Width, height: this.Height); - public PointInfo Midpoint => new( - x: this.X + (this.Width / 2), - y: this.Y + (this.Height / 2)); - + /// + /// Moves this RectangleInfo inside the specified RectangleInfo. + /// public RectangleInfo Clamp(RectangleInfo outer) { if ((this.Width > outer.Width) || (this.Height > outer.Height)) @@ -117,6 +98,31 @@ public RectangleInfo Clamp(RectangleInfo outer) height: this.Height); } + /// + /// Adapted from https://github.com/dotnet/runtime + /// See https://github.com/dotnet/runtime/blob/dfd618dc648ba9b11dd0f8034f78113d69f223cd/src/libraries/System.Drawing.Primitives/src/System/Drawing/Rectangle.cs + /// + public bool Contains(RectangleInfo rect) => + (this.X <= rect.X) && (rect.X + rect.Width <= this.X + this.Width) && + (this.Y <= rect.Y) && (rect.Y + rect.Height <= this.Y + this.Height); + + public RectangleInfo Enlarge(PaddingInfo padding) => + new( + this.X + padding.Left, + this.Y + padding.Top, + this.Width + padding.Horizontal, + this.Height + padding.Vertical); + + public RectangleInfo Offset(SizeInfo amount) => this.Offset(amount.Width, amount.Height); + + public RectangleInfo Offset(decimal dx, decimal dy) => new(this.X + dx, this.Y + dy, this.Width, this.Height); + + public RectangleInfo Scale(decimal scalingFactor) => new( + this.X * scalingFactor, + this.Y * scalingFactor, + this.Width * scalingFactor, + this.Height * scalingFactor); + public Rectangle ToRectangle() => new((int)this.X, (int)this.Y, (int)this.Width, (int)this.Height); public override string ToString() diff --git a/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/SizeInfo.cs b/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/SizeInfo.cs index a91febc23cfa..7ee3ad3f39c6 100644 --- a/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/SizeInfo.cs +++ b/src/modules/MouseUtils/MouseJumpUI/Models/Drawing/SizeInfo.cs @@ -33,13 +33,16 @@ public decimal Height get; } - public SizeInfo Negate() => new(-this.Width, -this.Height); + public SizeInfo Intersect(SizeInfo size) => + new( + Math.Min(this.Width, size.Width), + Math.Min(this.Height, size.Height)); - public SizeInfo Shrink(PaddingInfo padding) => new(this.Width - padding.Horizontal, this.Height - padding.Vertical); + public SizeInfo Negate() => + new(-this.Width, -this.Height); - public SizeInfo Intersect(SizeInfo size) => new( - Math.Min(this.Width, size.Width), - Math.Min(this.Height, size.Height)); + public SizeInfo Shrink(PaddingInfo padding) => + new(this.Width - padding.Horizontal, this.Height - padding.Vertical); public RectangleInfo PlaceAt(decimal x, decimal y) => new(x, y, this.Width, this.Height); diff --git a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/DWORD.cs b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/DWORD.cs index 9009b63c86bc..5967ab936c84 100644 --- a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/DWORD.cs +++ b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/DWORD.cs @@ -2,6 +2,8 @@ // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Runtime.InteropServices; + namespace MouseJumpUI.NativeMethods; internal static partial class Core @@ -23,6 +25,9 @@ public DWORD(uint value) this.Value = value; } + public static int Size => + Marshal.SizeOf(typeof(DWORD)); + public static implicit operator uint(DWORD value) => value.Value; public static implicit operator DWORD(uint value) => new(value); diff --git a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/HANDLE.cs b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/HANDLE.cs index 1df2624ed518..5e9b45de7476 100644 --- a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/HANDLE.cs +++ b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/HANDLE.cs @@ -31,7 +31,7 @@ public HANDLE(IntPtr value) public static implicit operator IntPtr(HANDLE value) => value.Value; - public static implicit operator HANDLE(IntPtr value) => new(value); + public static explicit operator HANDLE(IntPtr value) => new(value); public override string ToString() { diff --git a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/HDC.cs b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/HDC.cs index b02a811c06b3..ab5b8ff44ae1 100644 --- a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/HDC.cs +++ b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/HDC.cs @@ -29,6 +29,10 @@ public HDC(IntPtr value) public bool IsNull => this.Value == HDC.Null.Value; + public static implicit operator IntPtr(HDC value) => value.Value; + + public static explicit operator HDC(IntPtr value) => new(value); + public override string ToString() { return $"{this.GetType().Name}({this.Value})"; diff --git a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/HMONITOR.cs b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/HMONITOR.cs index 047c654f6f9b..de38e46a8f84 100644 --- a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/HMONITOR.cs +++ b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/HMONITOR.cs @@ -31,15 +31,15 @@ public HMONITOR(IntPtr value) public static implicit operator int(HMONITOR value) => value.Value.ToInt32(); - public static implicit operator HMONITOR(int value) => new(value); + public static explicit operator HMONITOR(int value) => new(value); public static implicit operator IntPtr(HMONITOR value) => value.Value; - public static implicit operator HMONITOR(IntPtr value) => new(value); + public static explicit operator HMONITOR(IntPtr value) => new(value); public static implicit operator HANDLE(HMONITOR value) => new(value.Value); - public static implicit operator HMONITOR(HANDLE value) => new(value.Value); + public static explicit operator HMONITOR(HANDLE value) => new(value.Value); public override string ToString() { diff --git a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/HWND.cs b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/HWND.cs index e12f2846f334..f0ac67b93de1 100644 --- a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/HWND.cs +++ b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/HWND.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using System.Diagnostics.CodeAnalysis; namespace MouseJumpUI.NativeMethods; @@ -20,6 +21,9 @@ internal readonly struct HWND { public static readonly HWND Null = new(IntPtr.Zero); + [SuppressMessage("SA1310", "SA1310:FieldNamesMustNotContainUnderscore", Justification = "Names match Win32 api")] + public static readonly HWND HWND_MESSAGE = new(-3); + public readonly IntPtr Value; public HWND(IntPtr value) diff --git a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/LPARAM.cs b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/LPARAM.cs index 6a227f5e21f1..56d143747e0e 100644 --- a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/LPARAM.cs +++ b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/LPARAM.cs @@ -26,9 +26,11 @@ public LPARAM(IntPtr value) this.Value = value; } + public bool IsNull => this.Value == LPARAM.Null.Value; + public static implicit operator IntPtr(LPARAM value) => value.Value; - public static implicit operator LPARAM(IntPtr value) => new(value); + public static explicit operator LPARAM(IntPtr value) => new(value); public override string ToString() { diff --git a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/LPCRECT.cs b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/LPCRECT.cs index d19abd9c3938..2a83d4918684 100644 --- a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/LPCRECT.cs +++ b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/LPCRECT.cs @@ -25,6 +25,8 @@ public LPCRECT(CRECT value) this.Value = LPCRECT.ToPtr(value); } + public bool IsNull => this.Value == LPCRECT.Null.Value; + private static IntPtr ToPtr(CRECT value) { var ptr = Marshal.AllocHGlobal(CRECT.Size); @@ -39,7 +41,7 @@ public void Free() public static implicit operator IntPtr(LPCRECT value) => value.Value; - public static implicit operator LPCRECT(IntPtr value) => new(value); + public static explicit operator LPCRECT(IntPtr value) => new(value); public override string ToString() { diff --git a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/LPPOINT.cs b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/LPPOINT.cs index db3423decde2..5a6c7deb609f 100644 --- a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/LPPOINT.cs +++ b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/LPPOINT.cs @@ -25,6 +25,8 @@ public LPPOINT(POINT value) this.Value = LPPOINT.ToPtr(value); } + public bool IsNull => this.Value == LPPOINT.Null.Value; + private static IntPtr ToPtr(POINT value) { var ptr = Marshal.AllocHGlobal(POINT.Size); @@ -44,7 +46,7 @@ public void Free() public static implicit operator IntPtr(LPPOINT value) => value.Value; - public static implicit operator LPPOINT(IntPtr value) => new(value); + public static explicit operator LPPOINT(IntPtr value) => new(value); public override string ToString() { diff --git a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/LPRECT.cs b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/LPRECT.cs index 087e22abe3f7..ce1d8b4eeaf2 100644 --- a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/LPRECT.cs +++ b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/LPRECT.cs @@ -24,6 +24,8 @@ public LPRECT(RECT value) this.Value = LPRECT.ToPtr(value); } + public bool IsNull => this.Value == LPRECT.Null.Value; + private static IntPtr ToPtr(RECT value) { var ptr = Marshal.AllocHGlobal(RECT.Size); @@ -38,7 +40,7 @@ public void Free() public static implicit operator IntPtr(LPRECT value) => value.Value; - public static implicit operator LPRECT(IntPtr value) => new(value); + public static explicit operator LPRECT(IntPtr value) => new(value); public override string ToString() { diff --git a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/ULONG_PTR.cs b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/ULONG_PTR.cs index 76d99d88be80..7d2f30d30b9b 100644 --- a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/ULONG_PTR.cs +++ b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/ULONG_PTR.cs @@ -34,7 +34,7 @@ public ULONG_PTR(UIntPtr value) public static implicit operator UIntPtr(ULONG_PTR value) => value.Value; - public static implicit operator ULONG_PTR(UIntPtr value) => new(value); + public static explicit operator ULONG_PTR(UIntPtr value) => new(value); public override string ToString() { diff --git a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/User32/Graphics/Gdi/User32.MONITORINFO.cs b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/User32/Graphics/Gdi/User32.MONITORINFO.cs index 24fb2709381d..0e23f8c33356 100644 --- a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/User32/Graphics/Gdi/User32.MONITORINFO.cs +++ b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/User32/Graphics/Gdi/User32.MONITORINFO.cs @@ -34,6 +34,6 @@ public MONITORINFO(DWORD cbSize, RECT rcMonitor, RECT rcWork, MONITOR_INFO_FLAGS } public static int Size => - Marshal.SizeOf(typeof(INPUT)); + Marshal.SizeOf(typeof(MONITORINFO)); } } diff --git a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/User32/UI/Input/KeyboardAndMouse/User32.LPINPUT.cs b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/User32/UI/Input/KeyboardAndMouse/User32.LPINPUT.cs index ff689a5931ab..add520463dfe 100644 --- a/src/modules/MouseUtils/MouseJumpUI/NativeMethods/User32/UI/Input/KeyboardAndMouse/User32.LPINPUT.cs +++ b/src/modules/MouseUtils/MouseJumpUI/NativeMethods/User32/UI/Input/KeyboardAndMouse/User32.LPINPUT.cs @@ -52,7 +52,7 @@ private static IntPtr ToPtr(INPUT[] values) var size = INPUT.Size; foreach (var value in values) { - Marshal.StructureToPtr(value, ptr, true); + Marshal.StructureToPtr(value, ptr, false); ptr += size; }