[英]How do I get a refernce to a dialog box of another program so that I can click a button
I have been successful in getting a reference to a running application in .net, and I have been able to use that reference to click buttons. 我已经成功获取了.net中正在运行的应用程序的引用,并且能够使用该引用来单击按钮。
This is code that gets the reference and uses it. 这是获取引用并使用它的代码。
string name = WindowsIdentity.GetCurrent().Name.Split('\\')[1];
testAssembly = Assembly.LoadFrom(FindFile("BuildWellnessFile.exe", "C:\\Users\\" + name + "\\AppData\\Local\\Apps\\2.0\\"));
Type t = testAssembly.GetType("BuildWellnessFile.Form1");
testForm = (Form)testAssembly.CreateInstance(t.FullName);
ThreadPool.QueueUserWorkItem(new WaitCallback(RunApp), testForm);
object[] p = { this, new EventArgs() };
InvokeMethod(testForm, "CountButton_Click", p);
This is supporting code 这是支持代码
Assembly testAssembly = null;
Form testForm = null;
static void RunApp(object state)
{
Application.Run((Form)state);
}
private void InvokeMethod(Form form, string methodName, params object[] parms)
{
EventHandler eh = (EventHandler)Delegate.CreateDelegate(typeof(EventHandler),form,methodName);
if (eh != null)
{
form.Invoke(eh, parms);
}
}
After this the InvokeMethod is used to click the button in the other application, a dialog box pops up. 之后,使用InvokeMethod单击另一个应用程序中的按钮,将弹出一个对话框。 I want to get a reference to that dialog box so that I can Press OK. 我想获得对该对话框的引用,以便可以按OK。
Please don't mention best practices about automating another application, I'm just asked to get things done. 请不要提及有关使另一个应用程序自动化的最佳实践,只是要求我完成工作。
UPDATE: Here is how the other application calls the dialog box 更新:这是其他应用程序调用对话框的方式
Interaction.MsgBox(" active cards in list created at: ", MsgBoxStyle.OkOnly, Nothing)
You will probably need to use P/Invoke to send BM_CLICK message to appropriate button in dialog box. 您可能需要使用P / Invoke将BM_CLICK消息发送到对话框中的相应按钮。 Some example how to do this in C# is at http://www.codeproject.com/KB/cs/WindowsAPIsFromCS.aspx 如何在C#中执行此操作的一些示例位于http://www.codeproject.com/KB/cs/WindowsAPIsFromCS.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.