110,580
社区成员
发帖
与我相关
我的任务
分享
[DllImport("User32.dll", EntryPoint = "SendMessage")]
private static extern int SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam);
const int WM_GETTEXT = 0x000D;
const int WM_SETTEXT = 0x000C;
const int WM_CLICK = 0x00F5;
private void button1_Click(object sender, EventArgs e)
{
// ...
SendMessage(hWnd6, WM_SETTEXT, (IntPtr)0, "abcdef");
SendMessage(hWnd7, WM_SETTEXT, (IntPtr)0, "123456");
}
[DllImport("user32.dll", EntryPoint = "FindWindow")]
private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
private void button1_Click(object sender, EventArgs e)
{
IntPtr hWnd1 = FindWindow(null, "主窗口标题");
SetForegroundWindow(hWnd1);
IntPtr hWnd2 = FindWindowEx(hWnd1, IntPtr.Zero, null, "控件文本"); // 用法1
IntPtr hWnd3 = FindWindowEx(hWnd1, IntPtr.Zero, "控件类名", null); // 用法2
}