private void Open_Selector(object sender, RoutedEventArgs e)
        {
            string SelectorString = ModelItem.GetValue <string>("Selector");
            int    maxresult      = 1;

            if (string.IsNullOrEmpty(SelectorString))
            {
                SelectorString = "[{Selector: 'Windows'}]";
            }
            var selector   = new Interfaces.Selector.Selector(SelectorString);
            var pluginname = selector.First().Selector;
            var selectors  = new Interfaces.Selector.SelectorWindow(pluginname, selector, maxresult);

            if (selectors.ShowDialog() == true)
            {
                ModelItem.Properties["Selector"].SetValue(new InArgument <string>()
                {
                    Expression = new Literal <string>(selectors.vm.json)
                });
            }
        }
Example #2
0
        private void Open_Selector(object sender, RoutedEventArgs e)
        {
            string SelectorString = ModelItem.GetValue <string>("Selector");
            int    maxresult      = 1;

            if (string.IsNullOrEmpty(SelectorString))
            {
                SelectorString = "[{Selector: 'Windows'}]";
            }
            var selector   = new Interfaces.Selector.Selector(SelectorString);
            var pluginname = selector.First().Selector;
            var selectors  = new Interfaces.Selector.SelectorWindow(pluginname, selector, maxresult);

            if (selectors.ShowDialog() == true)
            {
                ModelItem.Properties["Selector"].SetValue(new InArgument <string>()
                {
                    Expression = new Literal <string>(selectors.vm.json)
                });
                var Plugin = Interfaces.Plugins.recordPlugins.Where(x => x.Name == pluginname).First();
                var _base  = Plugin.GetElementsWithSelector(selector, null, 10);
                if (_base == null || _base.Length == 0)
                {
                    return;
                }
                var ele = _base[0];
                if (ele != null && !(ele is UIElement))
                {
                    var automation = AutomationUtil.getAutomation();
                    var p          = new System.Drawing.Point(ele.Rectangle.X + 10, ele.Rectangle.Y + 10);
                    if (p.X > 0 && p.Y > 0)
                    {
                        var _temp = automation.FromPoint(p);
                        if (_temp != null)
                        {
                            ele = new UIElement(_temp);
                        }
                    }
                }
                if (ele is UIElement ui)
                {
                    var window = ui.GetWindow();
                    if (window == null)
                    {
                        return;
                    }
                    if (!string.IsNullOrEmpty(window.Name))
                    {
                        ModelItem.Properties["DisplayName"].SetValue(window.Name);
                    }
                    if (window.Properties.BoundingRectangle.IsSupported)
                    {
                        var bound = window.BoundingRectangle;
                        ModelItem.Properties["X"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(bound.X)
                        });
                        ModelItem.Properties["Y"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(bound.Y)
                        });
                        ModelItem.Properties["Width"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(bound.Width)
                        });
                        ModelItem.Properties["Height"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(bound.Height)
                        });
                    }
                }
            }
        }
Example #3
0
        private void Open_Selector(object sender, RoutedEventArgs e)
        {
            string SelectorString = ModelItem.GetValue <string>("Selector");
            int    maxresult      = 1;

            if (string.IsNullOrEmpty(SelectorString))
            {
                SelectorString = "[{Selector: 'Windows'}]";
            }
            var selector   = new Interfaces.Selector.Selector(SelectorString);
            var pluginname = selector.First().Selector;
            var selectors  = new Interfaces.Selector.SelectorWindow(pluginname, selector, maxresult);

            // selectors.Owner = GenericTools.MainWindow;  -- Locks up and never returns ?
            if (selectors.ShowDialog() == true)
            {
                ModelItem.Properties["Selector"].SetValue(new InArgument <string>()
                {
                    Expression = new Literal <string>(selectors.vm.json)
                });
                var Plugin = Interfaces.Plugins.recordPlugins.Where(x => x.Name == pluginname).First();
                var _base  = Plugin.GetElementsWithSelector(selector, null, 10);
                if (_base == null || _base.Length == 0)
                {
                    return;
                }
                var ele = _base[0];
                if (ele != null && !(ele is UIElement))
                {
                    var automation = AutomationUtil.getAutomation();
                    var p          = new System.Drawing.Point(ele.Rectangle.X + 10, ele.Rectangle.Y + 10);
                    if (p.X > 0 && p.Y > 0)
                    {
                        var _temp = automation.FromPoint(p);
                        if (_temp != null)
                        {
                            ele = new UIElement(_temp);
                        }
                    }
                }
                if (ele is UIElement ui)
                {
                    var window = ui.GetWindow();
                    if (window == null)
                    {
                        return;
                    }
                    if (!string.IsNullOrEmpty(window.Name))
                    {
                        ModelItem.Properties["DisplayName"].SetValue(window.Name);
                    }
                    if (window.Properties.BoundingRectangle.IsSupported)
                    {
                        var bound      = window.BoundingRectangle;
                        var newbound   = new System.Drawing.Rectangle(bound.X, bound.Y, bound.Width, bound.Height);
                        var p          = new System.Drawing.Point(bound.X, bound.Y);
                        var allScreens = System.Windows.Forms.Screen.AllScreens.ToList();
                        int screen     = 0;
                        for (var i = 0; i < allScreens.Count; i++)
                        {
                            var work = allScreens[i].WorkingArea;
                            if (work.Contains(bound) || allScreens[i].WorkingArea.Contains(p))
                            {
                                screen     = i;
                                newbound.X = newbound.X - work.X;
                                newbound.Y = newbound.Y - work.Y;
                                break;
                            }
                        }
                        ModelItem.Properties["Screen"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(screen)
                        });
                        ModelItem.Properties["X"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(newbound.X)
                        });
                        ModelItem.Properties["Y"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(newbound.Y)
                        });
                        ModelItem.Properties["Width"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(newbound.Width)
                        });
                        ModelItem.Properties["Height"].SetValue(new InArgument <int>()
                        {
                            Expression = new Literal <int>(newbound.Height)
                        });
                    }
                }
            }
        }