1
我正在创建一个控制台应用程序,该应用程序应该调用VB应用程序MyProj.exe并触发同一按钮单击事件。单击.NET中的Visual Basic应用程序中的按钮
截至目前,我能够运行VB项目的可执行文件,但我想从控制台应用程序中触发某些按钮单击事件。
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.FileName = @"C:\New\MyProj.exe";
System.Diagnostics.Process.Start(startInfo);
我有以下链接尝试 - 这是不是为我工作 http://www.codeproject.com/Articles/14519/Using-Windows-APIs-from-C-again
- 在hwndChild执行每条语句后即将为“零”
//Get a handle for the "5" button
hwndChild = FindWindowEx((IntPtr)hwnd,IntPtr.Zero,"Button","5");
//send BN_CLICKED message
SendMessage((int)hwndChild,BN_CLICKED,0,IntPtr.Zero);
//Get a handle for the "+" button
hwndChild = FindWindowEx((IntPtr)hwnd,IntPtr.Zero,"Button","*");
//send BN_CLICKED message
SendMessage((int)hwndChild,BN_CLICKED,0,IntPtr.Zero);
//Get a handle for the "2" button
hwndChild = FindWindowEx((IntPtr)hwnd,IntPtr.Zero,"Button","2");
//send BN_CLICKED message
SendMessage((int)hwndChild,BN_CLICKED,0,IntPtr.Zero);
//Get a handle for the "=" button
hwndChild = FindWindowEx((IntPtr)hwnd,IntPtr.Zero,"Button","=");
//send BN_CLICKED message
SendMessage((int)hwndChild,BN_CLICKED,0,IntPtr.Zero);
太感谢很多codecaster - 但我会需要一点帮助
#define AMP_PAUSE 40046
HWND hwnd = FindWindow("Winamp v1.x", 0);
if(hwnd) SendMessage(hwnd, WM_COMMAND, AMP_PAUSE, 0);
button1是按钮的ID; Call_Method()是我们点击button1时调用的过程。
你能请帮助如何编写C#上面的代码
我检查了该实用程序 - 但我无法弄清楚如何调用按钮单击事件我vb.exe - 我也希望它在后台。 – 2014-11-03 11:31:30
请显示您使用的实际代码。 “不为我工作”不够清楚,不能重新提出你的问题。使用SendMessage API是实现这一点的方法。 – CodeCaster 2014-11-03 13:40:26
我已经下载了相同的代码,当我跑它 - 计算器打开,但与“0”的值。所以这意味着有按钮事件ared不会被解雇。每次hwndChild的值为“0” – 2014-11-03 14:55:48