110,578
社区成员
发帖
与我相关
我的任务
分享
[DllImport("User32.dll", EntryPoint = "FindWindow")]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
int WM_CLICK = 0x00F5;
const int WM_LBUTTONDOWN = 0x0201;
const int WM_LBUTTONUP = 0x202;
const int MK_LBUTTON = 0x0010;
const int MK_RBUTTON = 0x0002;
-------------------------------------------------------------------------------
private void button6_Click(object sender, EventArgs e)
{
//这些用spy++可以看到
string lpszParentClass = null; //整个窗口的类名
string lpszParentWindow = "测试一下点击"; //窗口标题
string lpszClass_Submit = null; //需要查找的Button的类名
string lpszName_Submit = "button3"; //需要查找的Button的标题
IntPtr ParenthWnd = new IntPtr(0);
IntPtr SonHwnd = new IntPtr(0);
IntPtr SunHwnd = new IntPtr(0);
//查到窗体,得到整个窗体
ParenthWnd = FindWindow(lpszParentClass, lpszParentWindow);
MessageBox.Show(ParenthWnd.ToString());
//得到二级子窗体
SonHwnd = FindWindowEx(ParenthWnd, SonHwnd, lpszClass_Submit, lpszName_Submit);
MessageBox.Show(SonHwnd.ToString());
SendMessage(SonHwnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(3, 3));
SendMessage(SonHwnd, WM_LBUTTONUP, MK_LBUTTON, MAKELONG(3, 3));
}
求指导..