/
githubmirror
/
PowerToys
Обзор
Документация
Войти
/
githubmirror
/
PowerToys
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/modules/ShortcutGuide/ShortcutGuide.Ui/NativeMethods.cs
218 строк
7 KB
Niels Laute
Shortcut Guide: Replace dual windows with single transparent overlay and add holding windows button (#48683)
27 июл 2026, 13:21
Не верифицирован
27 июл 2026, 13:21
346b498
Код
Авторство
О чём код?
// 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. using System; using System.Runtime.InteropServices; using Windows.Graphics; namespace ShortcutGuide; internal static partial class NativeMethods { internal const int GWL_STYLE = -16; internal const int GWL_EXSTYLE = -20; internal const int WS_CAPTION = 0x00C00000; internal const int WS_EX_TOOLWINDOW = 0x00000080; internal const int WS_EX_WINDOWEDGE = 0x00000100; internal const int WS_EX_CLIENTEDGE = 0x00000200; internal const int WS_EX_DLGMODALFRAME = 0x00000001; internal const uint ABM_GETTASKBARPOS = 0x00000005; internal const uint ABE_LEFT = 0; internal const uint ABE_TOP = 1; internal const uint ABE_RIGHT = 2; internal const uint ABE_BOTTOM = 3; [LibraryImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] internal static partial bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags); [LibraryImport("user32.dll", SetLastError = true)] internal static partial int GetWindowLongW(IntPtr hWnd, int nIndex); [LibraryImport("user32.dll")] internal static partial int SetWindowLongW(IntPtr hWnd, int nIndex, int dwNewLong); [LibraryImport("user32.dll", StringMarshalling = StringMarshalling.Utf16)] internal static partial IntPtr FindWindowW(in string lpClassName, in string? lpWindowName); [LibraryImport("User32.dll")] internal static partial IntPtr MonitorFromWindow(IntPtr hwnd, int dwFlags); [LibraryImport("User32.dll")] internal static partial IntPtr MonitorFromPoint(POINT pt, int dwFlags); [LibraryImport("User32.dll")] [return: MarshalAs(UnmanagedType.Bool)] internal static partial bool GetMonitorInfoW(IntPtr hMonitor, ref MONITORINFO lpmi); [LibraryImport("Shcore.dll")] internal static partial long GetDpiForMonitor(IntPtr hmonitor, int dpiType, ref int dpiX, ref int dpiY); [LibraryImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] internal static partial bool GetCursorPos(out POINT lpPoint); [LibraryImport("user32.dll")] internal static partial IntPtr GetForegroundWindow(); [LibraryImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] internal static partial bool SetForegroundWindow(IntPtr hWnd); [LibraryImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] internal static partial bool BringWindowToTop(IntPtr hWnd); [LibraryImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] internal static partial bool AttachThreadInput(uint idAttach, uint idAttachTo, [MarshalAs(UnmanagedType.Bool)] bool fAttach); [LibraryImport("kernel32.dll")] internal static partial uint GetCurrentThreadId(); [LibraryImport("user32.dll", SetLastError = true)] internal static partial uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId); [LibraryImport("user32.dll")] internal static partial short GetAsyncKeyState(int vKey); [DllImport("../PowerToys.Interop.dll", EntryPoint = "get_buttons")] internal static extern IntPtr GetTasklistButtons(IntPtr monitor, out int size); [LibraryImport("shell32.dll", EntryPoint = "SHAppBarMessage")] internal static partial IntPtr SHAppBarMessage(uint dwMessage, ref APPBARDATA pData); [LibraryImport("../PowerToys.Interop.dll", EntryPoint = "IsCurrentWindowExcludedFromShortcutGuide")] [return: MarshalAs(UnmanagedType.Bool)] internal static partial bool IsCurrentWindowExcludedFromShortcutGuide(); [LibraryImport("User32.dll")] [return: MarshalAs(UnmanagedType.Bool)] internal static partial bool EnumDisplayMonitors(IntPtr hdc, IntPtr lprcClip, MonitorEnumDelegate lpfnEnum, IntPtr dwData); internal delegate bool MonitorEnumDelegate(IntPtr hMonitor, IntPtr hdcMonitor, ref RECT lprcMonitor, IntPtr dwData); [LibraryImport("user32.dll")] internal static partial void CallNextHookEx(IntPtr hhk, int nCode, IntPtr wParam, LPARAM lParam); [DllImport("user32.dll")] internal static extern void SendInput(uint nInputs, [MarshalAs(UnmanagedType.LPArray), In] INPUT[] pInputs, int cbSize); internal struct INPUT { public uint Type; public MOUSEKEYBDHARDWAREINPUT Data; } [StructLayout(LayoutKind.Explicit)] internal struct MOUSEKEYBDHARDWAREINPUT { [FieldOffset(0)] public MOUSEINPUT Mouse; [FieldOffset(0)] public KEYBDINPUT Keyboard; [FieldOffset(0)] public HARDWAREINPUT Hardware; } [StructLayout(LayoutKind.Sequential)] internal struct MOUSEINPUT { public int Dx; public int Dy; public uint MouseData; public uint DwFlags; public uint Time; public IntPtr DwExtraInfo; } [StructLayout(LayoutKind.Sequential)] internal struct KEYBDINPUT { public ushort WVk; public ushort WScan; public uint DwFlags; public uint Time; public IntPtr DwExtraInfo; } [StructLayout(LayoutKind.Sequential)] internal struct HARDWAREINPUT { public uint Msg; public ushort ParamL; public ushort ParamH; } internal struct LPARAM(IntPtr value) { internal IntPtr Value = value; public static implicit operator IntPtr(LPARAM lParam) { return lParam.Value; } public static implicit operator LPARAM(IntPtr value) { return new LPARAM(value); } public static implicit operator LPARAM(int value) { return new LPARAM(new IntPtr(value)); } public static implicit operator int(LPARAM lParam) { return lParam.Value.ToInt32(); } } [StructLayout(LayoutKind.Sequential)] internal struct RECT { public int Left; public int Top; public int Right; public int Bottom; } internal struct POINT { internal int X; internal int Y; public static implicit operator PointInt32(POINT point) { return new PointInt32(point.X, point.Y); } } [StructLayout(LayoutKind.Sequential)] internal struct MONITORINFO { public uint CbSize; public RECT RcMonitor; public RECT RcWork; public uint DwFlags; } [StructLayout(LayoutKind.Sequential)] internal struct APPBARDATA { public uint CbSize; public IntPtr HWnd; public uint UCallbackMessage; public uint UEdge; public RECT Rc; public IntPtr LParam; } public enum MonitorFromWindowDwFlags { MONITOR_DEFAULTTONEAREST = 2, } }