예제 #1
0
        ///--------------------------------------------------------------------
        /// <summary>
        /// Start target button click listener.
        /// </summary>
        /// <param name="src">Object that raised the event.</param>
        /// <param name="e">Event arguments.</param>
        /// <remarks>
        /// Starts the target application, initializes the queue, and
        /// registers for events of interest.
        /// </remarks>
        ///--------------------------------------------------------------------
        private void btnStartTarget_Click(object src, EventArgs e)
        {
            targetApp = StartTargetApp();
            if (targetApp == null)
            {
                throw new ApplicationException(
                          "Unable to start target application.");
            }
            OutputFeedback(
                "Target started; start recording." + Environment.NewLine);

            RegisterTargetCloseEventListener();

            int clientLocationTop             = this.Top;
            int clientLocationRight           = this.Right + 100;
            TransformPattern transformPattern =
                targetApp.GetCurrentPattern(TransformPattern.Pattern)
                as TransformPattern;

            if (transformPattern != null)
            {
                transformPattern.Move(clientLocationRight, clientLocationTop);
            }

            SetControls(ControlState.TargetStarted);
        }
예제 #2
0
        /// <summary>
        /// Capture the window region of the specified size
        /// </summary>
        public Microsoft.Test.RenderingVerification.ImageAdapter CaptureWindow(double targetWidth, double targetHeight)
        {
            //Reposition Mouse to the origin
            Input.Input.MoveTo(new System.Windows.Point(0, 0));

            //Get window, move it to the origin
            AutomationElement windowElement = AutomationElement.FromHandle(hWndHost);
            WindowPattern     window        = windowElement.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern;

            window.SetWindowVisualState(WindowVisualState.Normal);
            TransformPattern transform = windowElement.GetCurrentPattern(TransformPattern.Pattern) as TransformPattern;

            transform.Move(0, 0);

            //we need to size the window (IE) to get the client area the correct size
            //Get the size of the target window
            AutomationElement clientElement = windowElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ClassNameProperty, "RootBrowserWindow"));
            Rect clientRect = (Rect)clientElement.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty);

            //Determine what the new size of the window should be to get the client area the correct size
            System.Windows.Rect ierect = (System.Windows.Rect)windowElement.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty);
            double w = (double)(ierect.Width + targetWidth - clientRect.Width);
            double h = (double)(ierect.Height + targetHeight - clientRect.Height);

            transform.Resize(w, h);

            // Wait for document to load and resize to occurs (assuming render would have occured)
            Thread.Sleep(3000);

            //Get bounds of content region, convert to Rectangle form, and capture to image adapter
            Rect ContentRect = (Rect)clientElement.GetCurrentPropertyValue(AutomationElement.BoundingRectangleProperty);

            System.Drawing.Rectangle captureRect = new Rectangle((int)ContentRect.X, (int)ContentRect.Y, (int)ContentRect.Width, (int)ContentRect.Height);
            return(new Microsoft.Test.RenderingVerification.ImageAdapter(captureRect));
        }
예제 #3
0
        public void ListSupportedPatterns()
        {
            AutomationElement automationElement = GetCurrentAutoElement();

            if (automationElement == null)
            {
                return;
            }
            object        objPattern;
            WindowPattern windowPattern = null;

            if (true == automationElement.TryGetCurrentPattern(WindowPattern.Pattern, out objPattern))
            {
                windowPattern = objPattern as WindowPattern;
            }
            logger.Info(this.Attributes.Name + " support windowPattern: " + (windowPattern != null).ToString());

            TransformPattern transformPattern = null;

            if (true == automationElement.TryGetCurrentPattern(TransformPattern.Pattern, out objPattern))
            {
                transformPattern = objPattern as TransformPattern;
            }
            logger.Info(this.Attributes.Name + " support TransformPattern: " + (transformPattern != null).ToString());

            InvokePattern invokePattern = null;

            if (true == automationElement.TryGetCurrentPattern(InvokePattern.Pattern, out objPattern))
            {
                invokePattern = objPattern as InvokePattern;
            }
            logger.Info(this.Attributes.Name + " support InvokePattern: " + (invokePattern != null).ToString());
        }
예제 #4
0
        public XmlConfigTransformDefinition(string definition)
        {
            if (definition.Contains("=>"))
            {
                Advanced = true;
                var separators = new[] { "=>" };
                var parts      = definition.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                TransformPattern = parts[0].Trim();
                SourcePattern    = parts[1].Trim();

                if (TransformPattern.StartsWith("*."))
                {
                    Wildcard         = true;
                    TransformPattern = TransformPattern.Remove(0, 2);
                }

                if (SourcePattern.StartsWith("*."))
                {
                    Wildcard      = true;
                    SourcePattern = SourcePattern.Remove(0, 2);
                }
            }
            else
            {
                TransformPattern = definition;
            }
        }
예제 #5
0
        public bool SetWidth(double width)
        {
            AutomationElement autoElement = GetCurrentAutoElement();

            if (autoElement == null)
            {
                return(false);
            }
            TransformPattern transformPattern = null;
            object           objPattern;

            if (true == autoElement.TryGetCurrentPattern(TransformPattern.Pattern, out objPattern))
            {
                transformPattern = objPattern as TransformPattern;
            }
            if (transformPattern != null)
            {
                Rect bound = autoElement.Current.BoundingRectangle;
                if (bound == null)
                {
                    return(false);
                }
                transformPattern.Resize(width, bound.Height);
                return(true);
            }
            // if not supported TransformPattern
            else
            {
            }
            return(false);
        }
예제 #6
0
        public void TransformPatternCachedTest()
        {
            using (AppHost host = new AppHost("notepad.exe", ""))
            {
                CacheRequest req = new CacheRequest();
                req.Add(TransformPattern.Pattern);
                req.Add(TransformPattern.CanMoveProperty);
                req.Add(TransformPattern.CanResizeProperty);
                req.Add(TransformPattern.CanRotateProperty);
                using (req.Activate())
                {
                    AutomationElement cachedEl = host.Element.GetUpdatedCache(req);

                    TransformPattern transformPattern = (TransformPattern)cachedEl.GetCachedPattern(TransformPattern.Pattern);
                    // Coded to expectations for an explorer window
                    Assert.IsTrue(transformPattern.Cached.CanMove);
                    Assert.IsTrue(transformPattern.Cached.CanResize);
                    Assert.IsFalse(transformPattern.Cached.CanRotate);

                    // Little move
                    transformPattern.Move(10, 10);

                    // Little resize
                    transformPattern.Resize(200, 200);
                }
            }
        }
예제 #7
0
        public bool SetLocation(double x, double y)
        {
            AutomationElement autoElement = GetCurrentAutoElement();

            if (autoElement == null)
            {
                return(false);
            }
            TransformPattern transformPattern = null;
            object           objPattern;

            if (true == autoElement.TryGetCurrentPattern(TransformPattern.Pattern, out objPattern))
            {
                transformPattern = objPattern as TransformPattern;
            }
            if (transformPattern != null)
            {
                Rect bound = autoElement.Current.BoundingRectangle;
                if (bound == null)
                {
                    return(false);
                }
                transformPattern.Move(x, y);
                return(true);
            }
            // if not supported TransformPattern
            else
            {
            }
            return(false);
        }
예제 #8
0
        public void NoClickablePointTest()
        {
            // Launch a notepad and position it
            using (AppHost host1 = new AppHost("notepad.exe", ""))
            {
                TransformPattern transformPattern1 = (TransformPattern)host1.Element.GetCurrentPattern(TransformPattern.Pattern);
                transformPattern1.Move(0, 0);
                transformPattern1.Resize(400, 300);

                System.Windows.Point pt1 = host1.Element.GetClickablePoint();

                // Launch a second notepad and position it on top
                using (AppHost host2 = new AppHost("notepad.exe", ""))
                {
                    TransformPattern transformPattern2 = (TransformPattern)host2.Element.GetCurrentPattern(TransformPattern.Pattern);
                    transformPattern2.Move(0, 0);
                    transformPattern2.Resize(400, 300);

                    // Now try it again for host1
                    try
                    {
                        System.Windows.Point pt1again = host1.Element.GetClickablePoint();
                        Assert.Fail("expected exception");
                    }
                    catch (NoClickablePointException)
                    {
                    }
                }
            }
        }
예제 #9
0
        /*
         * Creates the editor window.
         */
        public EditorWindow(BaseWindow editorWindow)
        {
            this.Window = editorWindow;

            // Create the patterns.
            this.FocusPattern = (WindowPattern)this.Window.Window.GetCurrentPattern(WindowPattern.Pattern);
            this.SizePattern  = (TransformPattern)this.Window.Window.GetCurrentPattern(TransformPattern.Pattern);
        }
예제 #10
0
파일: Pane.cs 프로젝트: ABEMBARKA/monoUI
        public void Rotate(double degree, bool log)
        {
            if (log)
            {
                procedureLogger.Action(string.Format("Rotate {0} {1} degree(s).", this.NameAndType, degree));
            }

            TransformPattern tp = (TransformPattern)element.GetCurrentPattern(TransformPattern.Pattern);

            tp.Rotate(degree);
        }
예제 #11
0
        public static bool TryGetTransformPattern(this AutomationElement element, out TransformPattern result)
        {
            if (element.TryGetCurrentPattern(System.Windows.Automation.TransformPattern.Pattern, out var pattern))
            {
                result = (TransformPattern)pattern;
                return(true);
            }

            result = null;
            return(false);
        }
예제 #12
0
        /// <summary>
        /// Resizes the control.
        /// </summary>
        /// <param name="control">The control to resize</param>
        /// <param name="width">desired width in pixels</param>
        /// <param name="height">the desired height in pixels</param>
        /// <returns>
        /// 0 if no problems encountered, -1 if InvalidOperationException is raised
        /// </returns>
        internal static int Resize(AutomationElement control, double width, double height)
        {
            TransformPattern pat = (TransformPattern)CommonUIAPatternHelpers.CheckPatternSupport(TransformPattern.Pattern, control);

            if (pat.Current.CanResize)
            {
                pat.Resize(width, height);
                return(0);
            }
            return(-1);
        }
예제 #13
0
        /// <summary>
        /// Moves the control to the specified location.
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <param name="x">The top left corner</param>
        /// <param name="y">The right</param>
        /// <returns>
        /// 0 if no problems encountered, -1 if InvalidOperationException is raised
        /// </returns>
        internal static int Move(AutomationElement control, double x, double y)
        {
            TransformPattern pat = (TransformPattern)CommonUIAPatternHelpers.CheckPatternSupport(TransformPattern.Pattern, control);

            if (pat.Current.CanMove)
            {
                pat.Move(x, y);
                return(0);
            }
            return(-1);
        }
예제 #14
0
        /// <summary>
        /// Rotates the specified control.
        /// </summary>
        /// <param name="control">The UI Automation element</param>
        /// <param name="degrees">The degrees to rotate. use a negative number to rotate counter-clockwise</param>
        /// <returns>
        /// 0 if no problems encountered, -1 if InvalidOperationException is raised
        /// </returns>
        internal static int Rotate(AutomationElement control, double degrees)
        {
            TransformPattern pat = (TransformPattern)CommonUIAPatternHelpers.CheckPatternSupport(TransformPattern.Pattern, control);

            if (pat.Current.CanRotate)
            {
                pat.Rotate(degrees);
                return(0);
            }
            return(-1);
        }
예제 #15
0
파일: Window.cs 프로젝트: ABEMBARKA/monoUI
        public void Resize(double width, double height, bool log)
        {
            if (log)
            {
                procedureLogger.Action(string.Format("Resize window to {0} width, {1} height.", width, height));
            }

            TransformPattern tp = (TransformPattern)element.GetCurrentPattern(TransformPattern.Pattern);

            tp.Resize(width, height);
        }
예제 #16
0
파일: Window.cs 프로젝트: ABEMBARKA/monoUI
        public void Move(double x, double y, bool log)
        {
            if (log)
            {
                procedureLogger.Action(string.Format("Move window to ({0}, {1}).", x, y));
            }

            TransformPattern tp = (TransformPattern)element.GetCurrentPattern(TransformPattern.Pattern);

            tp.Move(x, y);
        }
예제 #17
0
        private void TransformPatternController()
        {
            TransformPattern transformPattern = (TransformPattern)PatternObject;

            if (MethodType == 1)
            {
            }
            else if (MethodType == 2)
            {
            }
            else if (MethodType == 3)
            {
            }
        }
예제 #18
0
        private AutomationElement StartApp(string app)
        {
            if (File.Exists(app))
            {
                AutomationElement targetElement;

                // Start application.
                Process p = Process.Start(app);

                //// Give application a second to startup.
                Thread.Sleep(2000);

                targetElement = AutomationElement.FromHandle(p.MainWindowHandle);
                if (targetElement == null)
                {
                    return(null);
                }
                else
                {
                    AutomationEventHandler targetClosedHandler =
                        new AutomationEventHandler(onTargetClose);
                    Automation.AddAutomationEventHandler(
                        WindowPattern.WindowClosedEvent,
                        targetElement, TreeScope.Element, targetClosedHandler);

                    // Set size and position of target.
                    TransformPattern targetTransformPattern =
                        targetElement.GetCurrentPattern(TransformPattern.Pattern)
                        as TransformPattern;
                    if (targetTransformPattern == null)
                    {
                        return(null);
                    }
                    targetTransformPattern.Resize(550, 400);
                    targetTransformPattern.Move(
                        clientWindow.Left + clientWindow.Width + 25, clientWindow.Top);

                    Output("Target started.");

                    // Return the AutomationElement
                    return(targetElement);
                }
            }
            else
            {
                Output(app + " not found.");
                return(null);
            }
        }
        // </Snippet103>

        // <Snippet104>
        ///--------------------------------------------------------------------
        /// <summary>
        /// Calls the TransformPattern.Resize() method for an associated
        /// automation element.
        /// </summary>
        /// <param name="transformPattern">
        /// The TransformPattern control pattern obtained from
        /// an automation element.
        /// </param>
        /// <param name="width">
        /// The requested width of the automation element.
        /// </param>
        /// <param name="height">
        /// The requested height of the automation element.
        /// </param>
        ///--------------------------------------------------------------------
        private void ResizeElement(
            TransformPattern transformPattern, double width, double height)
        {
            try
            {
                if (transformPattern.Current.CanResize)
                {
                    transformPattern.Resize(width, height);
                }
            }
            catch (InvalidOperationException)
            {
                // object is not able to perform the requested action
                return;
            }
        }
        // </Snippet102>

        // <Snippet103>
        ///--------------------------------------------------------------------
        /// <summary>
        /// Calls the TransformPattern.Move() method for an associated
        /// automation element.
        /// </summary>
        /// <param name="transformPattern">
        /// The TransformPattern control pattern obtained from
        /// an automation element.
        /// </param>
        /// <param name="x">
        /// The number of screen pixels to move the automation element
        /// horizontally.
        /// </param>
        /// <param name="y">
        /// The number of screen pixels to move the automation element
        /// vertically.
        /// </param>
        ///--------------------------------------------------------------------
        private void MoveElement(
            TransformPattern transformPattern, double x, double y)
        {
            try
            {
                if (transformPattern.Current.CanMove)
                {
                    transformPattern.Move(x, y);
                }
            }
            catch (InvalidOperationException)
            {
                // object is not able to perform the requested action
                return;
            }
        }
        // </Snippet101>

        // <Snippet102>
        ///--------------------------------------------------------------------
        /// <summary>
        /// Calls the TransformPattern.Rotate() method for an associated
        /// automation element.
        /// </summary>
        /// <param name="transformPattern">
        /// The TransformPattern control pattern obtained from
        /// an automation element.
        /// </param>
        /// <param name="degrees">
        /// The amount of degrees to rotate the automation element.
        /// </param>
        ///--------------------------------------------------------------------
        private void RotateElement(
            TransformPattern transformPattern, double degrees)
        {
            try
            {
                if (transformPattern.Current.CanRotate)
                {
                    transformPattern.Rotate(degrees);
                }
            }
            catch (InvalidOperationException)
            {
                // object is not able to perform the requested action
                return;
            }
        }
예제 #22
0
        public void TransformPatternTest()
        {
            // Launch a notepad and position it
            using (AppHost host = new AppHost("notepad.exe", ""))
            {
                TransformPattern transformPattern = (TransformPattern)host.Element.GetCurrentPattern(TransformPattern.Pattern);
                // Coded to expectations for an explorer window
                Assert.IsTrue(transformPattern.Current.CanMove);
                Assert.IsTrue(transformPattern.Current.CanResize);
                Assert.IsFalse(transformPattern.Current.CanRotate);

                // Little move
                transformPattern.Move(10, 10);

                // Little resize
                transformPattern.Resize(200, 200);
            }
        }
        // </Snippet100>

        // <Snippet101>
        ///--------------------------------------------------------------------
        /// <summary>
        /// Obtains a TransformPattern control pattern from
        /// an automation element.
        /// </summary>
        /// <param name="targetControl">
        /// The automation element of interest.
        /// </param>
        /// <returns>
        /// A TransformPattern object.
        /// </returns>
        ///--------------------------------------------------------------------
        private TransformPattern GetTransformPattern(
            AutomationElement targetControl)
        {
            TransformPattern transformPattern = null;

            try
            {
                transformPattern =
                    targetControl.GetCurrentPattern(TransformPattern.Pattern)
                    as TransformPattern;
            }
            catch (InvalidOperationException)
            {
                // object doesn't support the TransformPattern control pattern
                return(null);
            }

            return(transformPattern);
        }
예제 #24
0
        ///--------------------------------------------------------------------
        /// <summary>
        /// Start the UI Automation worker.
        /// </summary>
        ///--------------------------------------------------------------------
        internal void StartWork()
        {
            // Get UI Automation root element.
            rootElement = AutomationElement.RootElement;

            // Position the target relative to the client.
            double           clientLocationTop   = clientApp.Top;
            double           clientLocationRight = clientApp.Width + clientApp.Left + 100;
            TransformPattern transformPattern    =
                targetApp.GetCurrentPattern(TransformPattern.Pattern)
                as TransformPattern;

            if (transformPattern != null)
            {
                transformPattern.Move(clientLocationRight, clientLocationTop);
            }

            RegisterTargetClosedListener();

            // Get the target controls.
            CompileTargetControls();
        }
예제 #25
0
        public void TestPropChangeEvent()
        {
            using (AppHost host = new AppHost("notepad.exe", ""))
            {
                TransformPattern transformPattern = (TransformPattern)host.Element.GetCurrentPattern(TransformPattern.Pattern);

                PropertyChangeHandler handler = new PropertyChangeHandler();
                Automation.AddAutomationPropertyChangedEventHandler(
                    host.Element,
                    TreeScope.Element,
                    new AutomationPropertyChangedEventHandler(handler.HandleEvent),
                    AutomationElement.BoundingRectangleProperty);
                handler.Start();
                System.Threading.Thread.Sleep(100 /* ms */);
                transformPattern.Move(200, 200);
                Assert.IsTrue(handler.Confirm());
                Assert.IsNotNull(handler.EventSource);
                Assert.AreEqual(host.Element, handler.EventSource);
                Automation.RemoveAutomationPropertyChangedEventHandler(
                    host.Element,
                    new AutomationPropertyChangedEventHandler(handler.HandleEvent));
            }
        }
예제 #26
0
        public static void WindowResize(AutomationElement window, System.Windows.Point pos)
        {
            TransformPattern pattern = window.GetCurrentPattern(TransformPattern.Pattern) as TransformPattern;

            pattern.Resize(pos.X, pos.Y);
        }
예제 #27
0
        ///--------------------------------------------------------------------
        /// <summary>
        /// Handles the click event for the Start App button.
        /// </summary>
        /// <param name="sender">The object that raised the event.</param>
        /// <param name="e">Event arguments.</param>
        ///--------------------------------------------------------------------
        private void btnStartApp_Click(object sender, RoutedEventArgs e)
        {
            targetWindow = StartTargetApp(filePath);

            if (targetWindow == null)
            {
                return;
            }

            Feedback("Target started.");

            double           clientLocationTop   = Client.Top;
            double           clientLocationRight = Client.Left + Client.Width + 100;
            TransformPattern transformPattern    =
                targetWindow.GetCurrentPattern(TransformPattern.Pattern)
                as TransformPattern;

            if (transformPattern != null)
            {
                transformPattern.Move(clientLocationRight, clientLocationTop);
            }

            // Get required control patterns
            //
            // Once you have an instance of an AutomationElement for the target
            // obtain a WindowPattern object to handle the WindowClosed event.
            try
            {
                WindowPattern windowPattern =
                    targetWindow.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern;
            }
            catch (InvalidOperationException)
            {
                Feedback("Object does not support the Window Pattern");
                return;
            }

            // Register for an Event
            //
            // The WindowPattern allows you to programmatically
            // manipulate a window.
            // It also exposes a window closed event.
            // The following code shows an example of listening
            // for the WindowClosed event.
            //
            // To intercept the WindowClosed event for our target application
            // you define an AutomationEventHandler delegate.
            AutomationEventHandler targetClosedHandler =
                new AutomationEventHandler(OnTargetClosed);

            // Use AddAutomationEventHandler() to add this event handler.
            // When listening for a WindowClosed event you must either scope
            // the event to the automation element as done here, or cast
            // the AutomationEventArgs in the handler to WindowClosedEventArgs
            // and compare the RuntimeId of the automation element that raised
            // the WindowClosed event to the automation element in the
            // class member data.
            Automation.AddAutomationEventHandler(
                WindowPattern.WindowClosedEvent,
                targetWindow,
                TreeScope.Element,
                targetClosedHandler);

            SetClientControlProperties(false, true);

            // Get our collection of interesting controls.
            textControls = FindTextControlsInTarget();
        }
예제 #28
0
 public void Move(int x, int y)
 {
     TransformPattern?.Move(x, y);
 }
예제 #29
0
        public void PatternController(AutomationPattern pat, AutomationElement selectedItem, ListView listView2)
        {
            if (pat == ScrollPattern.Pattern)
            {
                ScrollPattern scrollPattern = selectedItem.GetCurrentPattern(ScrollPattern.Pattern) as ScrollPattern;

                ListViewItem lvi = new ListViewItem();
                lvi.Content = "Scroll - not implemented";
                lvi.Tag     = new PatternInfo(1, 1, selectedItem, scrollPattern);
                listView2.Items.Add(lvi);
            }
            else if (pat == DockPattern.Pattern)
            {
                DockPattern dockPattern = selectedItem.GetCurrentPattern(DockPattern.Pattern) as DockPattern;

                ListViewItem lvi = new ListViewItem();
                lvi.Content = "SetDockPosition - not implemented";
                lvi.Tag     = new PatternInfo(2, 1, selectedItem, dockPattern);
                listView2.Items.Add(lvi);
            }
            else if (pat == ExpandCollapsePattern.Pattern)
            {
                ExpandCollapsePattern expandCollapsePattern = selectedItem.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;

                ListViewItem lvi1 = new ListViewItem();
                lvi1.Content = "Expand";
                lvi1.Tag     = new PatternInfo(3, 1, selectedItem, expandCollapsePattern);
                listView2.Items.Add(lvi1);

                ListViewItem lvi2 = new ListViewItem();
                lvi2.Content = "Collapse";
                lvi2.Tag     = new PatternInfo(3, 2, selectedItem, expandCollapsePattern);
                listView2.Items.Add(lvi2);
            }
            else if (pat == GridPattern.Pattern)
            {
                GridPattern gridPattern = selectedItem.GetCurrentPattern(GridPattern.Pattern) as GridPattern;

                ListViewItem lvi = new ListViewItem();
                lvi.Content = "GetItem - not implemented";
                lvi.Tag     = new PatternInfo(4, 1, selectedItem, gridPattern);
                listView2.Items.Add(lvi);
            }
            else if (pat == GridItemPattern.Pattern)
            {
            }
            else if (pat == InvokePattern.Pattern)
            {
                InvokePattern invokePattern = selectedItem.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern;

                ListViewItem lvi = new ListViewItem();
                lvi.Content = "Invoke";
                lvi.Tag     = new PatternInfo(6, 1, selectedItem, invokePattern);
                listView2.Items.Add(lvi);
            }
            else if (pat == ItemContainerPattern.Pattern)
            {
            }
            else if (pat == MultipleViewPattern.Pattern)
            {
            }
            else if (pat == RangeValuePattern.Pattern)
            {
                RangeValuePattern rangeValuePattern = selectedItem.GetCurrentPattern(RangeValuePattern.Pattern) as RangeValuePattern;

                ListViewItem lvi = new ListViewItem();
                lvi.Content = "SetValue - not implemented";
                lvi.Tag     = new PatternInfo(9, 1, selectedItem, rangeValuePattern);
                listView2.Items.Add(lvi);
            }
            else if (pat == ScrollItemPattern.Pattern)
            {
            }
            else if (pat == SelectionItemPattern.Pattern)
            {
            }
            else if (pat == SelectionPattern.Pattern)
            {
            }
            else if (pat == SynchronizedInputPattern.Pattern)
            {
            }
            else if (pat == TextPattern.Pattern)
            {
            }
            else if (pat == TogglePattern.Pattern)
            {
                TogglePattern togglePattern = selectedItem.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern;

                ListViewItem lvi = new ListViewItem();
                lvi.Content = "Toggle";
                lvi.Tag     = new PatternInfo(15, 1, selectedItem, togglePattern);
                listView2.Items.Add(lvi);
            }
            else if (pat == TransformPattern.Pattern)
            {
                TransformPattern transformPattern = selectedItem.GetCurrentPattern(TransformPattern.Pattern) as TransformPattern;

                ListViewItem lvi = new ListViewItem();
                lvi.Content = "Move - not implemented";
                lvi.Tag     = new PatternInfo(16, 1, selectedItem, transformPattern);
                listView2.Items.Add(lvi);

                ListViewItem lvi2 = new ListViewItem();
                lvi2.Content = "Resize - not implemented";
                lvi2.Tag     = new PatternInfo(16, 2, selectedItem, transformPattern);
                listView2.Items.Add(lvi2);

                ListViewItem lvi3 = new ListViewItem();
                lvi3.Content = "Rotate - not implemented";
                lvi3.Tag     = new PatternInfo(16, 3, selectedItem, transformPattern);
                listView2.Items.Add(lvi3);
            }
            else if (pat == ValuePattern.Pattern)
            {
                ValuePattern valuePattern = selectedItem.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;

                ListViewItem lvi = new ListViewItem();
                lvi.Content = "setValue";
                lvi.Tag     = new PatternInfo(17, 1, selectedItem, valuePattern);
                listView2.Items.Add(lvi);
            }
            else if (pat == VirtualizedItemPattern.Pattern)
            {
            }
            else if (pat == WindowPattern.Pattern)
            {
                WindowPattern windowPattern = selectedItem.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern;

                ListViewItem lvi = new ListViewItem();
                lvi.Content = "SetWindowVisualState - not implemented";
                lvi.Tag     = new PatternInfo(19, 1, selectedItem, windowPattern);
                listView2.Items.Add(lvi);
            }
            else
            {
                listView2.Items.Add("else");
            }
        }
예제 #30
0
        // <Snippet1301>
        /// <summary>
        /// The Startup handler.
        /// </summary>
        /// <param name="e">The event arguments</param>
        protected override void OnStartup(StartupEventArgs e)
        {
            // Start the WindowMove client.
            CreateWindow();

            try
            {
                // Obtain an AutomationElement from the target window handle.
                targetWindow = StartTargetApp(targetApplication);

                // Does the automation element exist?
                if (targetWindow == null)
                {
                    Feedback("No target.");
                    return;
                }
                Feedback("Found target.");

                // find current location of our window
                targetLocation = targetWindow.Current.BoundingRectangle.Location;

                // Obtain required control patterns from our automation element
                windowPattern = GetControlPattern(targetWindow,
                                                  WindowPattern.Pattern) as WindowPattern;

                if (windowPattern == null)
                {
                    return;
                }

                // Make sure our window is usable.
                // WaitForInputIdle will return before the specified time
                // if the window is ready.
                if (false == windowPattern.WaitForInputIdle(10000))
                {
                    Feedback("Object not responding in a timely manner.");
                    return;
                }
                Feedback("Window ready for user interaction");

                // Register for required events
                RegisterForEvents(
                    targetWindow, WindowPattern.Pattern, TreeScope.Element);

                // Obtain required control patterns from our automation element
                transformPattern =
                    GetControlPattern(targetWindow, TransformPattern.Pattern)
                    as TransformPattern;

                if (transformPattern == null)
                {
                    return;
                }

                // Is the TransformPattern object moveable?
                if (transformPattern.Current.CanMove)
                {
                    // Enable our WindowMove fields
                    xCoordinate.IsEnabled = true;
                    yCoordinate.IsEnabled = true;
                    moveTarget.IsEnabled  = true;

                    // Move element
                    transformPattern.Move(0, 0);
                }
                else
                {
                    Feedback("Wndow is not moveable.");
                }
            }
            catch (ElementNotAvailableException)
            {
                Feedback("Client window no longer available.");
                return;
            }
            catch (InvalidOperationException)
            {
                Feedback("Client window cannot be moved.");
                return;
            }
            catch (Exception exc)
            {
                Feedback(exc.ToString());
            }
        }