简体   繁体   English

如何获得对另一个程序的对话框的引用,以便可以单击按钮

[英]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.

相关问题 在另一个框中单击时如何加载数据? - How can I load data when I click in another box? 如何获取 WSDL/描述以便可以在另一个项目中添加 WebReference? - How do I get the WSDL/description so that I can add WebReference in another project? 在对话框关闭或执行下一个操作之前,我必须单击多次……我该如何解决这个问题? - I have to click multiple times before the dialog box closes, or performs the next action…How do I fix this? 如何在c#中创建一个类,以便我可以单击1表单上的按钮来更新第二个表单上的数据? - How do I make a class in c# so I can click a button on 1 form to update data on a second form? 如何设置我的winform按钮,以便我可以单击按钮或按Enter键 - How can I set up my winform button so that I can either click the button or press enter 我需要处理打印预览应用程序对话框。 但我无法用 Selenium C# 做到这一点。 我该怎么做? 打印预览在另一个选项卡中打开 - I Need to handle Print Preview App Dialog Box. But I am not able to do that with Selenium C#. How can I do it? The Print Preview opens in another tab 如何在单击另一个表单中的按钮时运行Game1 - How do I run Game1 on click of a button in another form 我如何自定义 MessageBoxButtons.YesNo 以便如果他们单击“是”或“否”以显示带有信息的消息框 - How do I customize MessageBoxButtons.YesNo so that if they click on "Yes" or "No" to show a message box with information 我如何从另一个类调用按钮单击方法 - how can i call a button click method from another class 当我使用Process.Start()运行该程序时,如何强制另一个程序不显示任何对话框 - How can I force another program to not show any dialog when I run it with Process.Start()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM