- [System.Runtime.InteropServices.DllImport("User32.dll")]
- public static extern int SendMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
- [System.Runtime.InteropServices.DllImport("User32.dll")]
- public static extern IntPtr FindWindow(string strClassName, string strWindowName);
- private const int WM_LBUTTONDOWN = 0x201;
- private const int WM_LBUTTONUP = 0x202;
- IntPtr ptr = FindWindow(null, "指定窗体名");
- Form1 f1 = (Form1)Control.FromHandle(ptr); //转为指定窗体实例
- //模拟 点击指定窗体 按钮button1
- SendMessage(f1.button1.Handle, WM_LBUTTONDOWN, 0, 0);
- SendMessage(f1.button1.Handle, WM_LBUTTONUP, 0, 0);