|
@@ -0,0 +1,109 @@
|
|
|
+using System;
|
|
|
+using System.Text;
|
|
|
+using System.Diagnostics.CodeAnalysis;
|
|
|
+using System.Runtime.InteropServices;
|
|
|
+namespace DayOf1440.NativeMethods
|
|
|
+{
|
|
|
+ class User32
|
|
|
+ {
|
|
|
+ #region 限制一个实例
|
|
|
+ [DllImport("User32.dll", EntryPoint = "FindWindow")]
|
|
|
+ private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
|
|
|
+
|
|
|
+ [DllImport("User32.dll")]
|
|
|
+ private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);
|
|
|
+
|
|
|
+ [DllImport("User32.dll")]
|
|
|
+ private static extern bool SetForegroundWindow(IntPtr hWnd);
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ public delegate int KeyboardHookProc(int code, int wParam, ref KeyboardHookStruct lParam);
|
|
|
+
|
|
|
+ [DllImport("user32.dll")]
|
|
|
+ public static extern int MoveWindow(IntPtr hWnd, int x, int y, int nWidth, int nHeight,
|
|
|
+ [MarshalAs(UnmanagedType.Bool)] bool bRepaint);
|
|
|
+
|
|
|
+ [DllImport("user32.dll")]
|
|
|
+ public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy,
|
|
|
+ uint uFlags);
|
|
|
+
|
|
|
+ [DllImport("user32.dll")]
|
|
|
+ public static extern IntPtr SetWindowsHookEx(int idHook, KeyboardHookProc callback, IntPtr hInstance,
|
|
|
+ uint threadId);
|
|
|
+
|
|
|
+ [DllImport("user32.dll")]
|
|
|
+ public static extern bool UnhookWindowsHookEx(IntPtr hInstance);
|
|
|
+
|
|
|
+ [DllImport("user32.dll")]
|
|
|
+ public static extern int CallNextHookEx(IntPtr idHook, int nCode, int wParam, ref KeyboardHookStruct lParam);
|
|
|
+
|
|
|
+ [DllImport("user32.dll")]
|
|
|
+ public static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
|
|
|
+
|
|
|
+ [DllImport("user32.dll")]
|
|
|
+ public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
|
|
|
+
|
|
|
+ [DllImport("user32.dll")]
|
|
|
+ public static extern IntPtr GetForegroundWindow();
|
|
|
+
|
|
|
+ [DllImport("user32.dll")]
|
|
|
+ public static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, IntPtr processId);
|
|
|
+
|
|
|
+ [DllImport("user32.dll")]
|
|
|
+ public static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out uint processId);
|
|
|
+
|
|
|
+ [DllImport("user32.dll")]
|
|
|
+ public static extern IntPtr AttachThreadInput(IntPtr idAttach, IntPtr idAttachTo, bool fAttach);
|
|
|
+
|
|
|
+ [DllImport("user32.dll")]
|
|
|
+ public static extern IntPtr GetFocus();
|
|
|
+
|
|
|
+ [DllImport("user32.dll", CharSet = CharSet.Auto)]
|
|
|
+ public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
|
|
|
+
|
|
|
+ [DllImport("user32.dll")]
|
|
|
+ public static extern IntPtr GetParent(IntPtr hWnd);
|
|
|
+
|
|
|
+ [SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
|
+ public struct KeyboardHookStruct
|
|
|
+ {
|
|
|
+ public int vkCode;
|
|
|
+ public int scanCode;
|
|
|
+ public int flags;
|
|
|
+ public int time;
|
|
|
+ public int dwExtraInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ // ReSharper disable InconsistentNaming
|
|
|
+ public static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
|
|
|
+ public static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
|
|
|
+ public static readonly IntPtr HWND_TOP = new IntPtr(0);
|
|
|
+ public static readonly IntPtr HWND_BOTTOM = new IntPtr(1);
|
|
|
+
|
|
|
+ public const uint SWP_NOSIZE = 0x0001;
|
|
|
+ public const uint SWP_NOMOVE = 0x0002;
|
|
|
+ public const uint SWP_NOZORDER = 0x0004;
|
|
|
+ public const uint SWP_NOREDRAW = 0x0008;
|
|
|
+ public const uint SWP_NOACTIVATE = 0x0010;
|
|
|
+ public const uint SWP_DRAWFRAME = 0x0020;
|
|
|
+ public const uint SWP_FRAMECHANGED = 0x0020;
|
|
|
+ public const uint SWP_SHOWWINDOW = 0x0040;
|
|
|
+ public const uint SWP_HIDEWINDOW = 0x0080;
|
|
|
+ public const uint SWP_NOCOPYBITS = 0x0100;
|
|
|
+ public const uint SWP_NOOWNERZORDER = 0x0200;
|
|
|
+ public const uint SWP_NOREPOSITION = 0x0200;
|
|
|
+ public const uint SWP_NOSENDCHANGING = 0x0400;
|
|
|
+ public const uint SWP_DEFERERASE = 0x2000;
|
|
|
+ public const uint SWP_ASYNCWINDOWPOS = 0x4000;
|
|
|
+
|
|
|
+ public const int WH_KEYBOARD_LL = 13;
|
|
|
+ public const int WM_KEYDOWN = 0x100;
|
|
|
+ public const int WM_KEYUP = 0x101;
|
|
|
+ public const int WM_SYSKEYDOWN = 0x104;
|
|
|
+ public const int WM_SYSKEYUP = 0x105;
|
|
|
+ public const int GWL_EXSTYLE = -20;
|
|
|
+ public const int WS_EX_NOACTIVATE = 0x08000000;
|
|
|
+ // ReSharper restore InconsistentNaming
|
|
|
+ }
|
|
|
+}
|