/// <summary> /// 在指定句柄窗口内按下鼠标,不等待消息处理完成立即返回 /// </summary> /// <param name="hWnd">窗口句柄</param> /// <param name="pt">相对于窗口的点</param> public static void PostMouseDown(IntPtr hWnd, Point pt) { IntPtr lParam = Util.MAKELPARAM(pt.X, pt.Y); UnsafeNativeMethods.PostMessage(hWnd, NativeMethods.WM_MOUSEMOVE, IntPtr.Zero, lParam); UnsafeNativeMethods.PostMessage(hWnd, NativeMethods.WM_LBUTTONDOWN, IntPtr.Zero, lParam); }
/// <summary> /// 跨进程,向指定窗口发送指定消息,立即返回 /// </summary> /// <param name="hWnd">窗口句柄</param> /// <param name="msg">消息</param> /// <param name="wParam">wParam</param> /// <param name="lParam">lParam</param> public static void PostMessage(IntPtr hWnd, int msg, int wParam, int lParam) { if (hWnd == IntPtr.Zero) { return; } UnsafeNativeMethods.PostMessage(hWnd, msg, (IntPtr)wParam, (IntPtr)lParam); }
/// <summary> /// 跨进程,向指定窗口发送指定消息,立即返回 /// </summary> /// <param name="lpWindowName">窗口标题</param> /// <param name="msg">消息</param> /// <param name="wParam">wParm</param> /// <param name="lParam">lParm</param> public static void PostMessage(string lpWindowName, int msg, int wParam, int lParam) { IntPtr hWnd = UnsafeNativeMethods.FindWindow(null, lpWindowName); if (hWnd == IntPtr.Zero) { return; } UnsafeNativeMethods.PostMessage(hWnd, msg, (IntPtr)wParam, (IntPtr)lParam); }
/// <summary> /// 向指定标题的窗口发送WM_CLOSE消息 /// </summary> /// <param name="lpWindowName">窗口标题</param> public static void CloseWindow(string lpWindowName) { IntPtr hWnd = UnsafeNativeMethods.FindWindow(null, lpWindowName); if (hWnd == IntPtr.Zero) { return; } UnsafeNativeMethods.PostMessage(hWnd, NativeMethods.WM_CLOSE, IntPtr.Zero, IntPtr.Zero); }