使用 .NET 核心识别 Winform 应用程序显示的 MessageBox 窗口类型 [英] Identify type of MessageBox window shown by Winform app using .NET core

查看:27
本文介绍了使用 .NET 核心识别 Winform 应用程序显示的 MessageBox 窗口类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 .NET 核心工作服务 应用程序,该应用程序将监控少数 winforms 应用程序.这些winforms 应用程序很少需要任何人工干预,它们唯一需要的时候是当它们显示下面演示的一些子窗口对话框时.目标是使用此 .NET 核心工作器服务消除这些罕见的人工交互.

I'm working on a .NET core worker service application that would monitor few winforms applications. These winforms applications rarely need any human intervention and the only times they need that is when they show some child window dialogs which are demonstrated below. The goal is to eliminate these rare human interactions using this .NET core worker service.

<头>
应用主应用程序窗口
someApp.exe

<头>
子窗口子窗口示例图像我需要采取的行动
信息窗口操作 1:我只需要单击确定"按钮即可继续我的生活.我将以编程方式执行此操作.
错误窗口操作 2:我需要重新启动 someApp.exe.同样,我将以编程方式执行此操作.
Child Window Child Window Example Image Action that I need to take
Information Window Action 1: I just need to click that Ok button and get on with my life. I'll be doing this programmatically.
Error Window Action 2: I need to restart someApp.exe. Again, I'll be doing this programmatically.

现在我可以像这样抓取主窗口和随后的子窗口:

Now I can grab the main window and the subsequent child windows like this:

var process = Process.GetProcesses().FirstOrDefault(p => p.ProcessName == "someApp");
// Get the main window of the process we're interested in:
AutomationElement appMainWindow = AutomationElement.FromHandle(process.MainWindowHandle);
// Now the child windows:
var childElements = appMainWindow.FindAll(TreeScope.Children, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Window));
if (childElements.Count > 0)
{
    foreach (AutomationElement childElement in childElements)
    {
        //How do I check if this childElement is an information window or an error window so that I can take my appropriate action?
    }
}

到目前为止我所做的:

var controlType = childElement.Current.ControlType.LocalizedControlType;

这没有帮助,因为它在两种情况下都显示 window.

This is not helpful because it says window for both of the cases.

所以我的问题是:

我如何检查这个 childElement 是信息 MessageBox 还是错误 MessageBox,以便我可以采取适当的行动?

How do I check if this childElement is information MessageBox or error MessageBox so that I can take my appropriate action?

谢谢!

推荐答案

您可以使用诸如 Snoop此列表UIA 验证、UISpy 和根据发现的差异进行检查.

You can see windows UIA elements structure and properties using tools like Snoop, this list, UIA Verify, UISpy, and do checks based on found differences.

这篇关于使用 .NET 核心识别 Winform 应用程序显示的 MessageBox 窗口类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆