예제 #1
0
        private static string GetParentWindowsTitle(DesktopElement element)
        {
            var parent = element;

            while ((parent != null) && (parent.TypeId != 50032))
            {
                parent = parent.Parent as DesktopElement;
            }

            return parent == null ? string.Empty : parent.Name;
        }
예제 #2
0
        /// <summary>
        /// Update the parent for the provided element.
        /// </summary>
        private DesktopElement UpdateParent()
        {
            var parent = NativeElement.GetCachedParent() ?? NativeElement.GetCurrentParent();
            if ((parent == null) || (parent.CurrentProcessId != NativeElement.CurrentProcessId))
            {
                Parent = null;
                return this;
            }

            Parent = new DesktopElement(parent, Application, null);
            Debug.WriteLine("P: {0},{1},{2},{3}",
                Parent.Id,
                parent.CurrentName,
                parent.CurrentAutomationId,
                parent.CurrentFrameworkId);

            return this;
        }
예제 #3
0
        /// <summary>
        /// Gets all the direct children of an element.
        /// </summary>
        /// <param name="element"> The element to get the children of. </param>
        /// <returns> The list of children for the element. </returns>
        private static IEnumerable<IUIAutomationElement> GetChildren(DesktopElement element)
        {
            var automation = new CUIAutomation8Class();
            var walker = automation.CreateTreeWalker(automation.RawViewCondition);
            var child = walker.GetFirstChildElement(element.NativeElement);

            while (child != null)
            {
                yield return child;

                child = walker.GetNextSiblingElement(child);
            }
        }
예제 #4
0
        /// <summary>
        /// Creates an element from the automation element.
        /// </summary>
        /// <param name="element"> The element to create. </param>
        /// <param name="application"> The application parent for this element. </param>
        /// <param name="parent"> The parent of the element to create. </param>
        internal static DesktopElement Create(IUIAutomationElement element, Application application, DesktopElement parent)
        {
            var itemType = element.CurrentControlType;

            switch (itemType)
            {
                case UIA_ControlTypeIds.UIA_ButtonControlTypeId:
                    return new Button(element, application, parent);

                case UIA_ControlTypeIds.UIA_CalendarControlTypeId:
                    return new Calendar(element, application, parent);

                case UIA_ControlTypeIds.UIA_CheckBoxControlTypeId:
                    return new CheckBox(element, application, parent);

                case UIA_ControlTypeIds.UIA_ComboBoxControlTypeId:
                    return new ComboBox(element, application, parent);

                case UIA_ControlTypeIds.UIA_CustomControlTypeId:
                    return new Custom(element, application, parent);

                case UIA_ControlTypeIds.UIA_DataGridControlTypeId:
                    return new DataGrid(element, application, parent);

                case UIA_ControlTypeIds.UIA_DataItemControlTypeId:
                    return new DataItem(element, application, parent);

                case UIA_ControlTypeIds.UIA_DocumentControlTypeId:
                    return new Document(element, application, parent);

                case UIA_ControlTypeIds.UIA_EditControlTypeId:
                    return new Edit(element, application, parent);

                case UIA_ControlTypeIds.UIA_GroupControlTypeId:
                    return new Group(element, application, parent);

                case UIA_ControlTypeIds.UIA_HeaderControlTypeId:
                    return new Header(element, application, parent);

                case UIA_ControlTypeIds.UIA_HeaderItemControlTypeId:
                    return new HeaderItem(element, application, parent);

                case UIA_ControlTypeIds.UIA_HyperlinkControlTypeId:
                    return new Hyperlink(element, application, parent);

                case UIA_ControlTypeIds.UIA_ImageControlTypeId:
                    return new Image(element, application, parent);

                case UIA_ControlTypeIds.UIA_ListControlTypeId:
                    return new List(element, application, parent);

                case UIA_ControlTypeIds.UIA_ListItemControlTypeId:
                    return new ListItem(element, application, parent);

                case UIA_ControlTypeIds.UIA_MenuControlTypeId:
                    return new Menu(element, application, parent);

                case UIA_ControlTypeIds.UIA_MenuBarControlTypeId:
                    return new MenuBar(element, application, parent);

                case UIA_ControlTypeIds.UIA_MenuItemControlTypeId:
                    return new MenuItem(element, application, parent);

                case UIA_ControlTypeIds.UIA_PaneControlTypeId:
                    return new Pane(element, application, parent);

                case UIA_ControlTypeIds.UIA_ProgressBarControlTypeId:
                    return new ProgressBar(element, application, parent);

                case UIA_ControlTypeIds.UIA_RadioButtonControlTypeId:
                    return new RadioButton(element, application, parent);

                case UIA_ControlTypeIds.UIA_SeparatorControlTypeId:
                    return new Separator(element, application, parent);

                case UIA_ControlTypeIds.UIA_ScrollBarControlTypeId:
                    return new ScrollBar(element, application, parent);

                case UIA_ControlTypeIds.UIA_SemanticZoomControlTypeId:
                    return new SemanticZoom(element, application, parent);

                case UIA_ControlTypeIds.UIA_SliderControlTypeId:
                    return new Slider(element, application, parent);

                case UIA_ControlTypeIds.UIA_SpinnerControlTypeId:
                    return new Spinner(element, application, parent);

                case UIA_ControlTypeIds.UIA_SplitButtonControlTypeId:
                    return new SplitButton(element, application, parent);

                case UIA_ControlTypeIds.UIA_StatusBarControlTypeId:
                    return new StatusBar(element, application, parent);

                case UIA_ControlTypeIds.UIA_TabControlTypeId:
                    return new TabControl(element, application, parent);

                case UIA_ControlTypeIds.UIA_TabItemControlTypeId:
                    return new TabItem(element, application, parent);

                case UIA_ControlTypeIds.UIA_TableControlTypeId:
                    return new Table(element, application, parent);

                case UIA_ControlTypeIds.UIA_TextControlTypeId:
                    return new Text(element, application, parent);

                case UIA_ControlTypeIds.UIA_ThumbControlTypeId:
                    return new Thumb(element, application, parent);

                case UIA_ControlTypeIds.UIA_TitleBarControlTypeId:
                    return new TitleBar(element, application, parent);

                case UIA_ControlTypeIds.UIA_ToolBarControlTypeId:
                    return new ToolBar(element, application, parent);

                case UIA_ControlTypeIds.UIA_ToolTipControlTypeId:
                    return new ToolTip(element, application, parent);

                case UIA_ControlTypeIds.UIA_TreeControlTypeId:
                    return new Tree(element, application, parent);

                case UIA_ControlTypeIds.UIA_TreeItemControlTypeId:
                    return new TreeItem(element, application, parent);

                case UIA_ControlTypeIds.UIA_WindowControlTypeId:
                    return new Window(element, application, parent);

                default:
                    Debug.WriteLine("Need to add support for [" + itemType + "] element.");
                    return new DesktopElement(element, application, parent);
            }
        }