diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/Utilities/NativeMethods.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/Utilities/NativeMethods.cs index 6cc5ec90fa..3b4a32c059 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/Utilities/NativeMethods.cs +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/Utilities/NativeMethods.cs @@ -13,5 +13,16 @@ namespace Microsoft.PowerToys.Settings.UI.Library.Utilities { [DllImport("user32.dll")] public static extern bool AllowSetForegroundWindow(int dwProcessId); + + public const int SWRESTORE = 9; + + [System.Runtime.InteropServices.DllImport("User32.dll")] + public static extern bool SetForegroundWindow(IntPtr handle); + + [System.Runtime.InteropServices.DllImport("User32.dll")] + public static extern bool ShowWindow(IntPtr handle, int nCmdShow); + + [System.Runtime.InteropServices.DllImport("User32.dll")] + public static extern bool IsIconic(IntPtr handle); } } diff --git a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ViewModels/KeyboardManagerViewModel.cs b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ViewModels/KeyboardManagerViewModel.cs index a6e8daf99a..0a226c46fc 100644 --- a/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ViewModels/KeyboardManagerViewModel.cs +++ b/src/settings-ui/Microsoft.PowerToys.Settings.UI.Library/ViewModels/KeyboardManagerViewModel.cs @@ -192,27 +192,14 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels } IntPtr handle = process.MainWindowHandle; - if (IsIconic(handle)) + if (NativeMethods.IsIconic(handle)) { - ShowWindow(handle, SWRESTORE); + NativeMethods.ShowWindow(handle, NativeMethods.SWRESTORE); } - SetForegroundWindow(handle); + NativeMethods.SetForegroundWindow(handle); } - private const int SWRESTORE = 9; - - [System.Runtime.InteropServices.DllImport("User32.dll")] - private static extern bool SetForegroundWindow(IntPtr handle); - - [System.Runtime.InteropServices.DllImport("User32.dll")] - - private static extern bool ShowWindow(IntPtr handle, int nCmdShow); - - [System.Runtime.InteropServices.DllImport("User32.dll")] - - private static extern bool IsIconic(IntPtr handle); - [SuppressMessage("Design", "CA1031:Do not catch general exception types", Justification = "Exceptions here (especially mutex errors) should not halt app execution, but they will be logged.")] private void OpenEditor(int type) {