private void btnHighlight_Click(object sender, EventArgs e) { try { UIAHighlight.HighlightThread_Spy((AutomationElement)treeObjects.SelectedNode.Tag); } catch { } }
public void PointToElements(Point point) { AutomationElementCollection aeCollection = null; AutomationElement menuAe = null; using (_generalCacheReq.Activate()) { _element = AutomationElement.FromPoint(point); UIAHighlight.HighlightThread_Spy(_element); if (_element.Current.ControlType == ControlType.MenuItem) { if (UIAUtility.ExpandMenuItem(_element) && _element.FindFirst(TreeScope.Children, _propertyMenuItemCondition) == null) { menuAe = RetrieveMenuElement(_element); } } if (menuAe == null) { if (_element.FindFirst(TreeScope.Children, Condition.TrueCondition) == null) { _element = TreeWalker.ControlViewWalker.GetParent(_element); } aeCollection = _element.FindAll(TreeScope.Children, Condition.TrueCondition); } else { aeCollection = menuAe.FindAll(TreeScope.Descendants, _menuCondition); } _ancestorElements.Clear(); _ancestorElements = UIAUtility.GetAutomationElementsLine(_element); _childElements.Clear(); _childElements = aeCollection.Cast <AutomationElement>().ToList(); } Console.WriteLine("childrenelement count {0}, ancestorelement count {1}", _childElements.Count, _ancestorElements.Count); if (null != afterPointToElementsEventHander) { ElementsBuilderEventArgs e = new ElementsBuilderEventArgs(this, _ancestorElements, _childElements, _element); afterPointToElementsEventHander(this, e); } }
private void ConstructElementsTree(AutomationElement clickedElement) { this.objectTree.Nodes.Clear(); if (clickedElement == null) { return; } UIAHighlight.HighlightThread_Spy(clickedElement); List <AutomationElement> elements = UIAUtility.GetAutomationElementsLine(clickedElement); TreeNodesFromAutomationElements(elements); if (_modeType == AddObjWndModeType.Normal) { ConstructLeftAndRightNode(objectTree, clickedElement); } this.objectTree.ExpandAll(); }
private void UpdateElementData(System.Windows.Point mousePoint, bool clicked) { _parentsList.Clear(); AutomationElement hoveredElement = null; //need to use the Async method to get the object Utility.AsyncCall(() => { try { hoveredElement = AutomationElement.FromPoint(mousePoint); if (hoveredElement != null) { _elementProperties = new ElementProperties(hoveredElement); } } catch (FileNotFoundException ex /*TODO fake exception, should be replaced with real one*/) { _Logger.WriteLog(ex.Message.ToString()); _Logger.WriteLog(ex.Source); _Logger.WriteLog(ex.TargetSite.ToString()); if (ex.InnerException != null) { _Logger.WriteLog(ex.InnerException.Message); } } }); if (hoveredElement != null & hoveredElement != _prevousElement) { _prevousElement = hoveredElement; HighlightRectangle hightlightRect = UIAHighlight.HighlightThread_Spy(hoveredElement, infinite: true); if (clicked || _alwaysOnTop) { if (clicked) { if (hightlightRect != null) { hightlightRect.Visible = false; Thread.Sleep(500); } } this.Invoke(new Action(() => { _leftElement = UIAUtility.GetPreviousElement(hoveredElement); _rightElement = UIAUtility.GetNextElement(hoveredElement); _parentsList = UIAUtility.GetAutomationElementsLine(hoveredElement); /* * AutomationElement rootElement = AutomationElement.RootElement; * while (parent != null) * { * if (!(parent.Current.NativeWindowHandle == rootElement.Current.NativeWindowHandle && rootElement.Current.Name == parent.Current.Name)) * { * parentsList.Add(parent); * } * parent = TreeWalker.ControlViewWalker.GetParent(parent); * } * * parentsList.Reverse(); */ this.treeObjects.Nodes.Clear(); TreeNodeCollection currentTreeNodeCollection = this.treeObjects.Nodes; TreeNode currentTreeNode = null; foreach (AutomationElement element in _parentsList) { currentTreeNode = currentTreeNodeCollection.Add(_parentsList.IndexOf(element).ToString(), element.Current.ControlType.ControlTypeToString() + ": " + element.Current.Name); currentTreeNode.Tag = element; currentTreeNodeCollection = currentTreeNode.Nodes; } if (_leftElement != null) { currentTreeNode = currentTreeNodeCollection.Add("left", "[Left Object]" + _leftElement.Current.ControlType.ControlTypeToString() + ": " + _leftElement.Current.Name); currentTreeNode.Tag = _leftElement; } currentTreeNode = currentTreeNodeCollection.Add("self", hoveredElement.Current.ControlType.ControlTypeToString() + ": " + hoveredElement.Current.Name); this.treeObjects.SelectedNode = currentTreeNode; currentTreeNode.Tag = hoveredElement; if (_rightElement != null) { currentTreeNode = currentTreeNodeCollection.Add("right", "[Right Object]" + _rightElement.Current.ControlType.ControlTypeToString() + ": " + _rightElement.Current.Name); currentTreeNode.Tag = _rightElement; } this.treeObjects.ExpandAll(); updatePropertyTable(hoveredElement); })); } } }