[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr PostMessage(IntPtr hwnd, int wMsg, IntPtr wParam, IntPtr lParam);
private void callAppBTN_Click(object sender, EventArgs e)
{
IntPtr hwnd_win;
IntPtr hwnd_button;
hwnd_win = FindWindow(null, "Call Extern App");
hwnd_button = FindWindowEx(hwnd_win, new IntPtr(0), null, "Test");
const int BM_CLICK = 0x00F5; //0x0201;
Message button_msg = Message.Create(hwnd_button, BM_CLICK, new IntPtr(0), new IntPtr(0));
PostMessage(button_msg.HWnd, button_msg.Msg, button_msg.WParam, button_msg.LParam);
}
private void tstBTN_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello Windows!");
}
C#自动点击外部Process按钮
最新推荐文章于 2024-10-23 17:22:03 发布