调用其他应用程序按钮事件
问题:现已有一个EXE应用程序,无源码,那EXE程序有一个按钮,启动后需手动点击按钮,无法自动执行,现在需要另写一个EXE程序,去启动那个应用程序,并且执行应用程序按钮事件,实现程序自动运行。有高手呢处理么?
--------------------编程问答--------------------
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace Text
{
public class Program
{
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, UInt32 wParam, UInt32 lParam);
private const UInt32 WM_CLICK = 0xF5;
static void Main(string[] args)
{
Process myProcess = new Process();
myProcess.StartInfo.UseShellExecute = false;
myProcess.StartInfo.FileName = "calc.exe";
myProcess.StartInfo.CreateNoWindow = true;
myProcess.Start();
myProcess.WaitForExit(1000);
IntPtr hWind = myProcess.MainWindowHandle;
IntPtr hButton = FindWindowEx(hWind, IntPtr.Zero, "Button", "1");
SendMessage(hButton, WM_CLICK, 0, 0);
Console.ReadKey();
}
}
}
补充:.NET技术 , C#