我正在尝试使用 .NET UIAutomation OR White 框架查找所有桌面窗口。
我试过 :
1.)
AutomationElement rootElement = AutomationElement.RootElement;
var winCollection = rootElement.FindAll(TreeScope.Subtree, Condition.TrueCondition);
2.)
Desktop.Instance.Windows();
两者都抛出 ArgumentException。
请让我知道是否有其他方法可以做到这一点...
更新/回答:Desktop.Instance.Windows();工作正常,除了它在使用 VS2010 调试代码时抛出异常。
最佳答案
使用 TreeScope.Children
如果您想访问桌面的直接子元素应该可以工作::
AutomationElement rootElement = AutomationElement.RootElement;
var winCollection = rootElement.FindAll(TreeScope.Children, Condition.TrueCondition);
foreach (AutomationElement element in winCollection)
Console.WriteLine(element.Current.Name);
关于white-framework - 使用 UIAutomation .NET 在桌面上查找所有窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10191265/