133 lines
4.2 KiB
C#
133 lines
4.2 KiB
C#
using System.Runtime.InteropServices;
|
|
|
|
namespace OneClickRun.App.Services;
|
|
|
|
/// <summary>项目用到的 Win32 P/Invoke 声明。</summary>
|
|
internal static class NativeMethods
|
|
{
|
|
internal const uint MOD_ALT = 0x0001;
|
|
internal const uint MOD_CONTROL = 0x0002;
|
|
internal const uint MOD_SHIFT = 0x0004;
|
|
internal const uint MOD_WIN = 0x0008;
|
|
internal const uint MOD_NOREPEAT = 0x4000;
|
|
|
|
internal const uint WM_HOTKEY = 0x0312;
|
|
internal const uint WM_QUIT = 0x0012;
|
|
internal const uint MONITOR_DEFAULTTONEAREST = 0x2;
|
|
internal const int MDT_EFFECTIVE_DPI = 0;
|
|
internal static readonly IntPtr HWND_MESSAGE = new(-3);
|
|
|
|
[DllImport("user32.dll", SetLastError = true)]
|
|
internal static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);
|
|
|
|
[DllImport("user32.dll", SetLastError = true)]
|
|
internal static extern bool UnregisterHotKey(IntPtr hWnd, int id);
|
|
|
|
[DllImport("user32.dll")]
|
|
internal static extern short GetAsyncKeyState(int vKey);
|
|
|
|
[DllImport("user32.dll")]
|
|
internal static extern uint GetDoubleClickTime();
|
|
|
|
[DllImport("user32.dll")]
|
|
internal static extern bool GetCursorPos(out POINT lpPoint);
|
|
|
|
[DllImport("user32.dll")]
|
|
internal static extern IntPtr MonitorFromPoint(POINT pt, uint dwFlags);
|
|
|
|
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
|
|
internal static extern bool GetMonitorInfo(IntPtr hMonitor, ref MONITORINFO lpmi);
|
|
|
|
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
internal static extern IntPtr CreateWindowEx(
|
|
uint dwExStyle, string lpClassName, string lpWindowName, uint dwStyle,
|
|
int x, int y, int nWidth, int nHeight,
|
|
IntPtr hWndParent, IntPtr hMenu, IntPtr hInstance, IntPtr lpParam);
|
|
|
|
[DllImport("user32.dll", SetLastError = true)]
|
|
internal static extern bool DestroyWindow(IntPtr hWnd);
|
|
|
|
[DllImport("user32.dll")]
|
|
internal static extern IntPtr DefWindowProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
|
|
|
|
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
|
|
internal static extern ushort RegisterClassEx(ref WNDCLASSEX lpwcx);
|
|
|
|
[DllImport("user32.dll", SetLastError = true)]
|
|
internal static extern int GetMessage(out MSG lpMsg, IntPtr hWnd, uint wMsgFilterMin, uint wMsgFilterMax);
|
|
|
|
[DllImport("user32.dll")]
|
|
internal static extern bool TranslateMessage(ref MSG lpMsg);
|
|
|
|
[DllImport("user32.dll")]
|
|
internal static extern IntPtr DispatchMessage(ref MSG lpMsg);
|
|
|
|
[DllImport("user32.dll", SetLastError = true)]
|
|
internal static extern bool PostMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam);
|
|
|
|
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
|
|
internal static extern IntPtr GetModuleHandle(string? lpModuleName);
|
|
|
|
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
|
|
internal static extern int MessageBox(IntPtr hWnd, string text, string caption, uint type);
|
|
|
|
[DllImport("user32.dll", SetLastError = true)]
|
|
internal static extern bool DestroyIcon(IntPtr hIcon);
|
|
|
|
[DllImport("Shcore.dll")]
|
|
internal static extern int GetDpiForMonitor(IntPtr hmonitor, int dpiType, out uint dpiX, out uint dpiY);
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
internal struct POINT
|
|
{
|
|
public int X;
|
|
public int Y;
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
internal struct RECT
|
|
{
|
|
public int Left;
|
|
public int Top;
|
|
public int Right;
|
|
public int Bottom;
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
|
internal struct MONITORINFO
|
|
{
|
|
public int cbSize;
|
|
public RECT rcMonitor;
|
|
public RECT rcWork;
|
|
public uint dwFlags;
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential)]
|
|
internal struct MSG
|
|
{
|
|
public IntPtr hwnd;
|
|
public uint message;
|
|
public IntPtr wParam;
|
|
public IntPtr lParam;
|
|
public uint time;
|
|
public POINT pt;
|
|
}
|
|
|
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
|
internal struct WNDCLASSEX
|
|
{
|
|
public uint cbSize;
|
|
public uint style;
|
|
public MessageWindow.WndProcDelegate? lpfnWndProc;
|
|
public int cbClsExtra;
|
|
public int cbWndExtra;
|
|
public IntPtr hInstance;
|
|
public IntPtr hIcon;
|
|
public IntPtr hCursor;
|
|
public IntPtr hbrBackground;
|
|
public string? lpszMenuName;
|
|
public string? lpszClassName;
|
|
public IntPtr hIconSm;
|
|
}
|