private void EnumarateChildren(IUIAutomationElement element) { Console.WriteLine("{0}", element.CurrentName.Trim()); IUIAutomationCacheRequest cacheRequest = _automation.CreateCacheRequest(); cacheRequest.AddProperty(System.Windows.Automation.AutomationElement.NameProperty.Id); cacheRequest.AddProperty(System.Windows.Automation.AutomationElement.ControlTypeProperty.Id); cacheRequest.TreeScope = TreeScope.TreeScope_Element | TreeScope.TreeScope_Children | TreeScope.TreeScope_Subtree; IUIAutomationCondition cond; cond = _automation.CreatePropertyConditionEx( System.Windows.Automation.AutomationElement.ControlTypeProperty.Id, System.Windows.Automation.ControlType.Window.Id, PropertyConditionFlags.PropertyConditionFlags_IgnoreCase); IUIAutomationElementArray elementList = element.FindAllBuildCache(TreeScope.TreeScope_Children, cond, cacheRequest); if (elementList == null) { return; } for (int i = 0; i < elementList.Length; i++) { EnumarateChildren(elementList.GetElement(i)); } }
public void ProcessHandlerDiagsTest() { var automation = new CUIAutomation(); var root = automation.GetRootElement(); var elements = root.FindAll(TreeScope.TreeScope_Children, automation.CreateTrueCondition()); for (var i = 0; i < elements.Length; i++) { var element = elements.GetElement(i); Debug.Print(element.CurrentClassName + ";" + element.CurrentName + ";" + element.CurrentProcessId + ";" + element.CurrentFrameworkId + ";" + element.CurrentNativeWindowHandle); } Debug.Print("---"); var frameElements = root.FindAll(TreeScope.TreeScope_Children, automation.CreatePropertyConditionEx( UIA_PropertyIds.UIA_ClassNamePropertyId, "ApplicationFrameWindow", PropertyConditionFlags.PropertyConditionFlags_IgnoreCase)); if (frameElements.Length == 0) { Debug.Print("No UWP apps"); return; } for (var i = 0; i < frameElements.Length; i++) { var frameElement = frameElements.GetElement(i); var subElements = frameElement.FindAll(TreeScope.TreeScope_Children, automation.CreateTrueCondition()); for (var j = 0; j < subElements.Length; j++) { var subElement = subElements.GetElement(j); Debug.Print(subElement.CurrentClassName + ";" + subElement.CurrentName + ";" + subElement.CurrentProcessId + ";" + subElement.CurrentFrameworkId + ";" + subElement.CurrentNativeWindowHandle); } Debug.Print("--"); } }