[KBM] move interop methods to dedicated class (#10958)

This commit is contained in:
Enrico Giordani
2021-04-26 16:14:59 -07:00
committed by GitHub
parent a8c99e9513
commit aa51f81bb8
2 changed files with 14 additions and 16 deletions

View File

@@ -13,5 +13,16 @@ namespace Microsoft.PowerToys.Settings.UI.Library.Utilities
{ {
[DllImport("user32.dll")] [DllImport("user32.dll")]
public static extern bool AllowSetForegroundWindow(int dwProcessId); 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);
} }
} }

View File

@@ -192,27 +192,14 @@ namespace Microsoft.PowerToys.Settings.UI.Library.ViewModels
} }
IntPtr handle = process.MainWindowHandle; 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.")] [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) private void OpenEditor(int type)
{ {