From 8e3aff376de669b9cbf664b411e80afb3da98d3d Mon Sep 17 00:00:00 2001 From: "Yu Leng (from Dev Box)" Date: Sun, 27 Apr 2025 16:38:34 +0800 Subject: [PATCH] init --- .../Controls/ShortcutControl/HotkeySettingsControlHook.cs | 2 +- .../Controls/ShortcutControl/NativeKeyboardHelper.cs | 2 +- .../Controls/ShortcutControl/NativeMethods.cs | 3 --- src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs | 7 +++++-- .../cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj | 1 + src/modules/cmdpal/Microsoft.CmdPal.UI/NativeMethods.json | 4 ++++ src/modules/cmdpal/Microsoft.CmdPal.UI/NativeMethods.txt | 3 --- 7 files changed, 12 insertions(+), 10 deletions(-) create mode 100644 src/modules/cmdpal/Microsoft.CmdPal.UI/NativeMethods.json diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/HotkeySettingsControlHook.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/HotkeySettingsControlHook.cs index 66f482f502..6ea1c708a7 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/HotkeySettingsControlHook.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/HotkeySettingsControlHook.cs @@ -12,7 +12,7 @@ public delegate bool IsActive(); public delegate bool FilterAccessibleKeyboardEvents(int key, UIntPtr extraInfo); -public class HotkeySettingsControlHook : IDisposable +public partial class HotkeySettingsControlHook : IDisposable { private const int WmKeyDown = 0x100; private const int WmKeyUp = 0x101; diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/NativeKeyboardHelper.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/NativeKeyboardHelper.cs index 9d3961f907..b9d32e25d3 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/NativeKeyboardHelper.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/NativeKeyboardHelper.cs @@ -18,7 +18,7 @@ namespace Microsoft.PowerToys.Settings.UI.Helpers internal static int Size { - get { return Marshal.SizeOf(typeof(INPUT)); } + get { return Marshal.SizeOf(); } } } diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/NativeMethods.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/NativeMethods.cs index f89b11391b..e5af77b862 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/NativeMethods.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/NativeMethods.cs @@ -64,9 +64,6 @@ public static class NativeMethods [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] public static extern IntPtr LoadLibrary(string dllToLoad); - [DllImport("kernel32.dll", CharSet = CharSet.Unicode)] - public static extern bool FreeLibrary(IntPtr hModule); - #pragma warning restore CA1401 // P/Invokes should not be visible [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)] diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs index ce20c9be77..0a33b24f44 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/MainWindow.xaml.cs @@ -592,7 +592,7 @@ public sealed partial class MainWindow : Window, _largeIcon = GetAppIconHandle(); _trayIconData = new NOTIFYICONDATAW() { - cbSize = (uint)Marshal.SizeOf(typeof(NOTIFYICONDATAW)), + cbSize = (uint)Marshal.SizeOf(), hWnd = _hwnd, uID = MY_NOTIFY_ID, uFlags = NOTIFY_ICON_DATA_FLAGS.NIF_MESSAGE | NOTIFY_ICON_DATA_FLAGS.NIF_ICON | NOTIFY_ICON_DATA_FLAGS.NIF_TIP, @@ -629,7 +629,10 @@ public sealed partial class MainWindow : Window, private DestroyIconSafeHandle GetAppIconHandle() { - var exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; + var basePath = AppContext.BaseDirectory; + var exePath = Path.Combine(basePath, "Microsoft.CmdPal.UI.dll"); + + // var exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; DestroyIconSafeHandle largeIcon; PInvoke.ExtractIconEx(exePath, 0, out largeIcon, out _, 1); return largeIcon; diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj b/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj index c79669e714..98a170eeb8 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj @@ -1,6 +1,7 @@  + diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/NativeMethods.json b/src/modules/cmdpal/Microsoft.CmdPal.UI/NativeMethods.json new file mode 100644 index 0000000000..b893150484 --- /dev/null +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/NativeMethods.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://aka.ms/CsWin32.schema.json", + "allowMarshaling": true +} diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/NativeMethods.txt b/src/modules/cmdpal/Microsoft.CmdPal.UI/NativeMethods.txt index 4db59d7070..615504c70b 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/NativeMethods.txt +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/NativeMethods.txt @@ -1,7 +1,6 @@ GetPhysicallyInstalledSystemMemory GlobalMemoryStatusEx GetSystemInfo -CoCreateInstance GetForegroundWindow SetForegroundWindow GetWindowRect @@ -21,9 +20,7 @@ SetActiveWindow MonitorFromWindow GetMonitorInfo GetDpiForMonitor -SHCreateStreamOnFileEx CoAllowSetForegroundWindow -SHCreateStreamOnFileEx SHLoadIndirectString Shell_NotifyIcon