-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mouse Jump] - replace use of System.Windows.Forms.Cursor with Native…
… Methods (#25482)
- Loading branch information
1 parent
df70a09
commit d0489ae
Showing
5 changed files
with
141 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/modules/MouseUtils/MouseJumpUI/NativeMethods/Core/LPPOINT.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// 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 | ||
{ | ||
internal readonly struct LPPOINT | ||
{ | ||
public static readonly LPPOINT Null = new(IntPtr.Zero); | ||
|
||
public readonly IntPtr Value; | ||
|
||
public LPPOINT(IntPtr value) | ||
{ | ||
this.Value = value; | ||
} | ||
|
||
public LPPOINT(POINT value) | ||
{ | ||
this.Value = LPPOINT.ToPtr(value); | ||
} | ||
|
||
private static IntPtr ToPtr(POINT value) | ||
{ | ||
var ptr = Marshal.AllocHGlobal(POINT.Size); | ||
Marshal.StructureToPtr(value, ptr, false); | ||
return ptr; | ||
} | ||
|
||
public POINT ToStructure() | ||
{ | ||
return Marshal.PtrToStructure<POINT>(this.Value); | ||
} | ||
|
||
public void Free() | ||
{ | ||
Marshal.FreeHGlobal(this.Value); | ||
} | ||
|
||
public static implicit operator IntPtr(LPPOINT value) => value.Value; | ||
|
||
public static implicit operator LPPOINT(IntPtr value) => new(value); | ||
|
||
public override string ToString() | ||
{ | ||
return $"{this.GetType().Name}({this.Value})"; | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...MouseUtils/MouseJumpUI/NativeMethods/User32/UI/WindowsAndMessaging/User32.GetCursorPos.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// 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; | ||
using static MouseJumpUI.NativeMethods.Core; | ||
|
||
namespace MouseJumpUI.NativeMethods; | ||
|
||
internal static partial class User32 | ||
{ | ||
/// <summary> | ||
/// Retrieves the position of the mouse cursor, in screen coordinates. | ||
/// </summary> | ||
/// <returns> | ||
/// Returns nonzero if successful or zero otherwise. | ||
/// To get extended error information, call GetLastError. | ||
/// </returns> | ||
/// <remarks> | ||
/// See https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getcursorpos | ||
/// </remarks> | ||
[LibraryImport(Libraries.User32, SetLastError = true)] | ||
internal static partial BOOL GetCursorPos( | ||
LPPOINT lpPoint); | ||
} |
28 changes: 28 additions & 0 deletions
28
...MouseUtils/MouseJumpUI/NativeMethods/User32/UI/WindowsAndMessaging/User32.SetCursorPos.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) Microsoft Corporation | ||
// 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; | ||
using static MouseJumpUI.NativeMethods.Core; | ||
|
||
namespace MouseJumpUI.NativeMethods; | ||
|
||
internal static partial class User32 | ||
{ | ||
/// <summary> | ||
/// Moves the cursor to the specified screen coordinates. If the new coordinates are not within | ||
/// the screen rectangle set by the most recent ClipCursor function call, the system automatically | ||
/// adjusts the coordinates so that the cursor stays within the rectangle. | ||
/// </summary> | ||
/// <returns> | ||
/// Returns nonzero if successful or zero otherwise. | ||
/// To get extended error information, call GetLastError. | ||
/// </returns> | ||
/// <remarks> | ||
/// See https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getcursorpos | ||
/// </remarks> | ||
[LibraryImport(Libraries.User32, SetLastError = true)] | ||
internal static partial BOOL SetCursorPos( | ||
int X, | ||
int Y); | ||
} |