2020-10-08 08:45:09 -07:00
|
|
|
|
// 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.
|
|
|
|
|
|
|
2021-07-28 17:26:06 +03:00
|
|
|
|
using System;
|
2020-10-08 08:45:09 -07:00
|
|
|
|
using System.Runtime.InteropServices;
|
2021-11-18 20:35:07 +01:00
|
|
|
|
using System.Text;
|
2020-10-08 08:45:09 -07:00
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Helpers
|
|
|
|
|
|
{
|
2021-03-02 20:56:37 +03:00
|
|
|
|
public static class NativeMethods
|
2020-10-08 08:45:09 -07:00
|
|
|
|
{
|
2022-02-23 15:17:44 +00:00
|
|
|
|
private const int GWL_STYLE = -16;
|
|
|
|
|
|
private const int WS_POPUP = 1 << 31; // 0x80000000
|
2021-11-18 20:35:07 +01:00
|
|
|
|
internal const int SPI_GETDESKWALLPAPER = 0x0073;
|
2022-04-19 22:00:28 +02:00
|
|
|
|
internal const int SW_SHOWNORMAL = 1;
|
|
|
|
|
|
internal const int SW_SHOWMAXIMIZED = 3;
|
2022-05-19 15:12:59 +02:00
|
|
|
|
internal const int SW_HIDE = 0;
|
2022-04-19 22:00:28 +02:00
|
|
|
|
|
|
|
|
|
|
[DllImport("user32.dll")]
|
|
|
|
|
|
internal static extern IntPtr GetActiveWindow();
|
|
|
|
|
|
|
|
|
|
|
|
[DllImport("user32.dll")]
|
|
|
|
|
|
internal static extern bool SetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndpl);
|
|
|
|
|
|
|
|
|
|
|
|
[DllImport("user32.dll")]
|
|
|
|
|
|
internal static extern bool GetWindowPlacement(IntPtr hWnd, out WINDOWPLACEMENT lpwndpl);
|
2021-10-06 15:37:33 +02:00
|
|
|
|
|
2020-10-08 08:45:09 -07:00
|
|
|
|
[DllImport("user32.dll")]
|
|
|
|
|
|
internal static extern uint SendInput(uint nInputs, NativeKeyboardHelper.INPUT[] pInputs, int cbSize);
|
|
|
|
|
|
|
|
|
|
|
|
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
|
|
|
|
|
|
internal static extern short GetAsyncKeyState(int vKey);
|
2020-10-29 14:24:16 -07:00
|
|
|
|
|
2021-10-06 15:37:33 +02:00
|
|
|
|
[DllImport("user32.dll", SetLastError = true)]
|
|
|
|
|
|
internal static extern int GetWindowLong(IntPtr hWnd, int nIndex);
|
|
|
|
|
|
|
|
|
|
|
|
[DllImport("user32.dll")]
|
|
|
|
|
|
internal static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
|
|
|
|
|
|
|
2023-03-17 18:14:23 +00:00
|
|
|
|
[DllImport("shell32.dll")]
|
|
|
|
|
|
internal static extern IntPtr SHBrowseForFolderW(ref ShellGetFolder.BrowseInformation browseInfo);
|
|
|
|
|
|
|
|
|
|
|
|
[DllImport("shell32.dll")]
|
|
|
|
|
|
internal static extern int SHGetPathFromIDListW(IntPtr pidl, IntPtr pszPath);
|
|
|
|
|
|
|
2021-03-02 20:56:37 +03:00
|
|
|
|
#pragma warning disable CA1401 // P/Invokes should not be visible
|
2020-10-29 14:24:16 -07:00
|
|
|
|
[DllImport("user32.dll")]
|
|
|
|
|
|
public static extern bool ShowWindow(System.IntPtr hWnd, int nCmdShow);
|
2021-03-02 20:56:37 +03:00
|
|
|
|
|
2022-04-29 11:06:50 +02:00
|
|
|
|
[DllImport("user32.dll")]
|
|
|
|
|
|
public static extern int GetDpiForWindow(System.IntPtr hWnd);
|
|
|
|
|
|
|
2022-05-19 15:12:59 +02:00
|
|
|
|
[DllImport("user32.dll")]
|
|
|
|
|
|
public static extern bool IsWindowVisible(IntPtr hWnd);
|
|
|
|
|
|
|
2021-03-02 20:56:37 +03:00
|
|
|
|
[DllImport("user32.dll")]
|
|
|
|
|
|
public static extern bool AllowSetForegroundWindow(int dwProcessId);
|
2021-07-28 17:26:06 +03:00
|
|
|
|
|
2023-01-31 00:00:11 +01:00
|
|
|
|
[System.Runtime.InteropServices.DllImport("User32.dll")]
|
|
|
|
|
|
public static extern bool SetForegroundWindow(IntPtr handle);
|
|
|
|
|
|
|
2021-07-28 17:26:06 +03:00
|
|
|
|
[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);
|
2023-03-17 18:14:23 +00:00
|
|
|
|
|
2021-03-02 20:56:37 +03:00
|
|
|
|
#pragma warning restore CA1401 // P/Invokes should not be visible
|
2021-10-06 15:37:33 +02:00
|
|
|
|
|
2021-11-18 20:35:07 +01:00
|
|
|
|
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
|
|
|
|
|
|
[return: MarshalAs(UnmanagedType.Bool)]
|
2022-04-19 22:00:28 +02:00
|
|
|
|
|
2021-11-18 20:35:07 +01:00
|
|
|
|
internal static extern bool SystemParametersInfo(int uiAction, int uiParam, StringBuilder pvParam, int fWinIni);
|
|
|
|
|
|
|
2022-02-23 15:17:44 +00:00
|
|
|
|
public static void SetPopupStyle(IntPtr hwnd)
|
2021-10-06 15:37:33 +02:00
|
|
|
|
{
|
2022-02-23 15:17:44 +00:00
|
|
|
|
_ = SetWindowLong(hwnd, GWL_STYLE, GetWindowLong(hwnd, GWL_STYLE) | WS_POPUP);
|
2021-10-06 15:37:33 +02:00
|
|
|
|
}
|
2020-10-08 08:45:09 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|