Exemple #1
0
        /// <summary>
        /// Fills TreeView with focused control as root
        /// </summary>
        /// <param name="control">The UI Automation control.</param>
        public void LoadGraph(AutomationElement control)
        {
            if (control == null || _focusedApplicationHandle == IntPtr.Zero)
            {
                return;
            }

            try
            {
                _focusedElement = control;

                AutomationElement rootElement = AutomationElement.FromHandle(_focusedApplicationHandle);

                TvGraph.BeginUpdate();
                AddGraphNode(rootElement);

                /* show the node representing the selected control */
                TvGraph.SelectedNode = _selectedNode;
                TvGraph.TopNode      = _selectedNode;
                TvGraph.EndUpdate();
            }
            catch (ElementNotAvailableException)
            {
                MessageBox.Show(Resources.WindowNotAvail, Resources.Invalid_Window, MessageBoxButtons.OK, MessageBoxIcon.Error);
                Close();
                return;
            }
        }
Exemple #2
0
        /// <summary>
        /// Adds the graph node.
        /// </summary>
        /// <param name="rootElement">The root element.</param>
        private void AddGraphNode(AutomationElement rootElement)
        {
            if (rootElement == null)
            {
                return;
            }

            string showString = rootElement.Current.LocalizedControlType + " [ " + rootElement.Current.AutomationId + " ]";

            GraphNode tn = new GraphNode(rootElement)
            {
                Text       = showString,
                Tag        = rootElement.Current.NativeWindowHandle,
                ImageIndex = 2
            };

            WalkControlElements(rootElement, tn);
            TvGraph.Nodes.Add(tn);
            TvGraph.ExpandAll();
        }