diff --git a/src/modules/fancyzones/FancyZonesCLI/FancyZonesCLI.csproj b/src/modules/fancyzones/FancyZonesCLI/FancyZonesCLI.csproj
index 1be8bd9140..85c2fa30e5 100644
--- a/src/modules/fancyzones/FancyZonesCLI/FancyZonesCLI.csproj
+++ b/src/modules/fancyzones/FancyZonesCLI/FancyZonesCLI.csproj
@@ -11,6 +11,7 @@
Exe
x64;ARM64
true
+ true
false
false
..\..\..\..\$(Platform)\$(Configuration)
@@ -20,6 +21,7 @@
+
diff --git a/src/modules/fancyzones/FancyZonesCLI/NativeMethods.cs b/src/modules/fancyzones/FancyZonesCLI/NativeMethods.cs
index 65adc5eccd..efab0859bd 100644
--- a/src/modules/fancyzones/FancyZonesCLI/NativeMethods.cs
+++ b/src/modules/fancyzones/FancyZonesCLI/NativeMethods.cs
@@ -2,8 +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;
-using System.Runtime.InteropServices;
+using Windows.Win32;
+using Windows.Win32.Foundation;
namespace FancyZonesCLI;
@@ -12,8 +12,6 @@ namespace FancyZonesCLI;
///
internal static class NativeMethods
{
- public static readonly IntPtr HWND_BROADCAST = new IntPtr(0xffff);
-
// Registered Windows messages for notifying FancyZones
private static uint wmPrivAppliedLayoutsFileUpdate;
private static uint wmPrivLayoutHotkeysFileUpdate;
@@ -33,8 +31,8 @@ internal static class NativeMethods
///
public static void InitializeWindowMessages()
{
- wmPrivAppliedLayoutsFileUpdate = RegisterWindowMessage("{2ef2c8a7-e0d5-4f31-9ede-52aade2d284d}");
- wmPrivLayoutHotkeysFileUpdate = RegisterWindowMessage("{07229b7e-4f22-4357-b136-33c289be2295}");
+ wmPrivAppliedLayoutsFileUpdate = PInvoke.RegisterWindowMessage("{2ef2c8a7-e0d5-4f31-9ede-52aade2d284d}");
+ wmPrivLayoutHotkeysFileUpdate = PInvoke.RegisterWindowMessage("{07229b7e-4f22-4357-b136-33c289be2295}");
}
///
@@ -43,16 +41,16 @@ internal static class NativeMethods
/// The Windows message ID to broadcast.
public static void NotifyFancyZones(uint message)
{
- PostMessage(HWND_BROADCAST, message, IntPtr.Zero, IntPtr.Zero);
+ PInvoke.PostMessage(HWND.HWND_BROADCAST, message, 0, 0);
}
- [DllImport("user32.dll", SetLastError = true)]
- public static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
-
- [DllImport("user32.dll")]
- [return: MarshalAs(UnmanagedType.Bool)]
- public static extern bool SetForegroundWindow(IntPtr hWnd);
-
- [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
- public static extern uint RegisterWindowMessage(string lpString);
+ ///
+ /// Brings the specified window to the foreground.
+ ///
+ /// A handle to the window.
+ /// True if the window was brought to the foreground.
+ public static bool SetForegroundWindow(nint hWnd)
+ {
+ return PInvoke.SetForegroundWindow(new HWND(hWnd));
+ }
}
diff --git a/src/modules/fancyzones/FancyZonesCLI/NativeMethods.json b/src/modules/fancyzones/FancyZonesCLI/NativeMethods.json
new file mode 100644
index 0000000000..89cee38a92
--- /dev/null
+++ b/src/modules/fancyzones/FancyZonesCLI/NativeMethods.json
@@ -0,0 +1,5 @@
+{
+ "$schema": "https://aka.ms/CsWin32.schema.json",
+ "emitSingleFile": true,
+ "allowMarshaling": false
+}
diff --git a/src/modules/fancyzones/FancyZonesCLI/NativeMethods.txt b/src/modules/fancyzones/FancyZonesCLI/NativeMethods.txt
new file mode 100644
index 0000000000..e3555c2333
--- /dev/null
+++ b/src/modules/fancyzones/FancyZonesCLI/NativeMethods.txt
@@ -0,0 +1,4 @@
+PostMessage
+SetForegroundWindow
+RegisterWindowMessage
+HWND_BROADCAST