/// <summary> /// 该函数从当前线程中的窗口释放鼠标捕获,并恢复通常的鼠标输入处理 /// </summary> /// <returns>如果函数调用成功,返回非零值;如果函数调用失败,返回值是零。</returns> [DllImport("user32")] public static extern bool ReleaseCapture(); /// <summary> /// 将一个消息放入(寄送)到与指定窗口创建的线程相联系消息队列里,不等待线程处理消息就返回,是异步消息模式。消息队列里的消息通过调用GetMessage和PeekMessage取得。 /// </summary> /// <param name="hWnd">其窗口程序接收消息的窗口的句柄,NULL:此函数的操作和调用参数dwThread设置为当前线程的标识符PostThreadMessage函数一样</param> /// <param name="Mwg">指定被寄送的消息</param> /// <param name="wParam">指定附加的消息特定的信息</param> /// <param name="lParam">指定附加的消息特定的信息。</param> /// <returns>如果函数调用成功,返回非零值:如果函数调用失败,返回值是零。</returns> [DllImport("user32")] public static extern bool PostMessage(int hWnd, int Mwg, int wParam, int lParam); /// <summary> /// 设置父窗体 /// </summary> /// <param name="hWndChild">对象窗体句柄</param> /// <param name="hWndNewParent">父窗体句柄</param> /// <returns></returns> [DllImport("user32.dll", EntryPoint = "SetParent")] public static extern int SetParent(IntPtr hWndChild, IntPtr hWndNewParent); /// <summary> /// windows当前活动窗体句柄 /// </summary> /// <returns>windows当前活动窗体句柄</returns> [DllImport("user32")] public static extern IntPtr GetForegroundWindow(); /// <summary> /// 当前进程焦点窗体句柄 /// </summary> /// <returns>当前进程焦点窗体句柄</returns> [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)] public static extern IntPtr GetActiveWindow(); /// <summary> /// 句柄窗体标题 /// </summary> /// <param name="hwnd">窗体句柄</param> /// <param name="lpString">StringBuilder</param> /// <param name="cch">StringBuilder.Capacity</param> /// <returns>StringBuilder.ToString()</returns> [DllImport("user32.dll", EntryPoint = "GetWindowText")] public static extern int GetWindowText(IntPtr hwnd, StringBuilder lpString, int cch); /// <summary> /// 句柄窗体状态,ShowWindow(Handle, (short)ShowWindowStyles.SW_SHOWDEFAULT); /// </summary> /// <param name="hWnd">窗体句柄</param> /// <param name="State">状态参数</param> /// <returns></returns> [DllImport("user32.dll", CharSet = CharSet.Auto)] public static extern bool ShowWindow(IntPtr hWnd, short State); /// <summary> /// 获取关联窗体句柄,hwnd为源窗口句柄 /// </summary> /// <param name="hwnd">源窗口句柄</param> /// <param name="wCmd">(子)GW_CHILD = 5,(父)GW_OWNER = 4</param> /// <returns></returns> [DllImport("user32.dll", EntryPoint = "GetWindow")] public static extern IntPtr GetWindow(IntPtr hwnd, int wCmd); //获取窗体句柄,hwnd为源窗口句柄 /* wCmd指定结果窗口与源窗口的关系,它们建立在下述常数基础上: GW_CHILD = 5 寻找源窗口的第一个子窗口 GW_HWNDFIRST 为一个源子窗口寻找第一个兄弟(同级)窗口,或寻找第一个顶级窗口 GW_HWNDLAST 为一个源子窗口寻找最后一个兄弟(同级)窗口,或寻找最后一个顶级窗口 GW_HWNDNEXT 为源窗口寻找下一个兄弟窗口 GW_HWNDPREV 为源窗口寻找前一个兄弟窗口 GW_OWNER = 4 寻找窗口的所有者 */ /// <summary> /// 移动窗体 /// </summary> /// <param name="hwnd">对象句柄</param> /// <param name="x">x</param> /// <param name="y">y</param> /// <param name="nWidth">宽</param> /// <param name="nHeight">高</param> /// <param name="bRepaint">true</param> /// <returns></returns> [DllImport("user32.dll", EntryPoint = "MoveWindow")] public static extern int MoveWindow(IntPtr hwnd, int x, int y, int nWidth, int nHeight, bool bRepaint); /// <summary> /// 桌面窗口句柄 /// </summary> /// <returns></returns> [DllImport("user32.dll", EntryPoint = "GetDesktopWindow")] public static extern IntPtr GetDesktopWindow(); /// <summary> /// FindWindow /// </summary> /// <param name="lpClassName">类名||null</param> /// <param name="lpWindowName">标题名</param> /// <returns>顶级句柄(explorer.exe的句柄,一般是0)</returns> [DllImport("User32.dll", EntryPoint = "FindWindow")] public static extern IntPtr FindWindow(string lpClassName, string lpWindowName); /// <summary> /// 从窗口系统菜单上发送该消息,实现窗口的最大化,最小化,移动,还原,移动等操作 /// </summary> public const int WM_SysCommand = 0x0112; public const int SC_MOVE = 61456; public const int HTCAPTION = 2; public const int GWL_STYLE = (-16); public const int GWL_EXSTYLE = (-20); public const int LWA_ALPHA = 0x2; public const int LWA_COLORKEY = 0x1; public const uint WS_CAPTION = 0xC00000; private const int HWND_TOP = 0x0; private const int WM_COMMAND = 0x0112; private const int WM_QT_PAINT = 0xC2DC; private const int WM_PAINT = 0x000F; private const int WM_SIZE = 0x0005; private const int SWP_FRAMECHANGED = 0x0020; public enum ShowWindowStyles : short { SW_HIDE = 0, SW_SHOWNORMAL = 1, SW_NORMAL = 1, SW_SHOWMINIMIZED = 2, SW_SHOWMAXIMIZED = 3, SW_MAXIMIZE = 3, SW_SHOWNOACTIVATE = 4, SW_SHOW = 5, SW_MINIMIZE = 6, SW_SHOWMINNOACTIVE = 7, SW_SHOWNA = 8, SW_RESTORE = 9, SW_SHOWDEFAULT = 10, SW_FORCEMINIMIZE = 11, SW_MAX = 11 }