using System.Runtime.InteropServices;
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, uint hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hwnd, uint wMsg, int wParam, int lParam);
const uint BM_CLICK = 0xF5;
IntPtr msgHandle = FindWindow(null, "Form1");
if (msgHandle != IntPtr.Zero)
{
//找到Button
IntPtr btnHandle = FindWindowEx(msgHandle, 0, "Button", "确定");
if (btnHandle != IntPtr.Zero)
{
SendMessage(btnHandle, BM_CLICK, 0, 0);
}
}
[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, uint hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hwnd, uint wMsg, int wParam, int lParam);
const uint BM_CLICK = 0xF5;
IntPtr msgHandle = FindWindow(null, "Form1");
if (msgHandle != IntPtr.Zero)
{
//找到Button
IntPtr btnHandle = FindWindowEx(msgHandle, 0, "Button", "确定");
if (btnHandle != IntPtr.Zero)
{
SendMessage(btnHandle, BM_CLICK, 0, 0);
}
}