internal static partial class user32
{
// hahdles
[DllImport("USER32.DLL")]
internal static extern int WaitForInputIdle(IntPtr hWnd, int dwMilliseconds);
[DllImport("USER32.DLL", CharSet = CharSet.Auto)]
internal static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
internal static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll")]
internal static extern byte VkKeyScan(char ch);
//[DllImport("User32.Dll", EntryPoint = "PostMessageA")]
[DllImport("User32.Dll")]
internal static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, int lParam);
[DllImport("User32.Dll")]
internal static extern bool SendMessage(IntPtr hWnd, uint msg, int wParam, int lParam);
[DllImport("user32.dll", EntryPoint = "GetWindowText", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
internal static extern int GetWindowText(IntPtr hWnd, StringBuilder lpWindowText, int nMaxCount);
[DllImport("user32.dll", EntryPoint = "SetWindowText", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
internal static extern int SetWindowText(IntPtr hWnd, string lpWindowText);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool IsWindowVisible(IntPtr hWnd);
// Define the callback delegate's type.
internal delegate bool EnumDelegate(IntPtr hWnd, int lParam);
[DllImport("user32.dll", EntryPoint = "EnumDesktopWindows", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
internal static extern bool EnumDesktopWindows(IntPtr hDesktop, EnumDelegate lpEnumCallbackFunction, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)]
internal static extern IntPtr SendMessage(IntPtr handle, UInt32 message, IntPtr w, IntPtr l);
internal static uint WM_CLOSE = 0x10;
internal static void Close(this IntPtr hWnd) { SendMessage(hWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero); }
[DllImport("user32.dll", SetLastError = true)]
internal static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);
[DllImport("user32.dll", SetLastError = true)]
internal static extern bool MoveWindow(IntPtr hWnd, int X, int Y, int nWidth, int nHeight, bool bRepaint);
[DllImport("user32.dll")]
internal static extern int ShowWindowAsync(IntPtr hwnd, int nCmdShow);
internal const int SW_MAXIMIZE = 3;
internal const int SW_MINIMIZE = 6;
internal static void Maximize(this IntPtr hWnd) { ShowWindowAsync(hWnd, SW_MAXIMIZE); }
internal static void Minimize(this IntPtr hWnd) { ShowWindowAsync(hWnd, SW_MINIMIZE); }
[DllImport("USER32.DLL")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("USER32.DLL")]
public static extern bool SetActiveWindow(IntPtr hWnd);
// grabs
[DllImport("user32.dll")]
internal static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
internal static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")]
internal static extern IntPtr GetWindowRect(IntPtr hWnd, ref Bounds rect);
// mouse
[DllImport("User32.dll")]
internal static extern void mouse_event(MouseFlags dwFlags, int dx, int dy, int dwData, UIntPtr dwExtraInfo);
[Flags]
internal enum MouseFlags
{ Move = 0x0001, LeftDown = 0x0002, LeftUp = 0x0004, RightDown = 0x0008, RightUp = 0x0010, Absolute = 0x8000 };
}