Beispiel #1
0
        private async void ProcessLimit_Click(object sender, RoutedEventArgs e)
        {
            var Processname = ModelItem.GetValue <string>("Processname");
            var p           = System.Diagnostics.Process.GetProcessesByName(Processname).FirstOrDefault();

            if (p == null)
            {
                return;
            }

            var allChildWindows = new WindowHandleInfo(p.MainWindowHandle).GetAllChildHandles();

            allChildWindows.Add(p.MainWindowHandle);
            var       template   = new Rectangle(0, 0, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height);
            Rectangle windowrect = Rectangle.Empty;

            foreach (var window in allChildWindows)
            {
                WindowHandleInfo.RECT rct;
                if (!WindowHandleInfo.GetWindowRect(new HandleRef(this, window), out rct))
                {
                    continue;
                }
                var _rect = new Rectangle(rct.Left, rct.Top, rct.Right - rct.Left + 1, rct.Bottom - rct.Top + 1);
                if (_rect.Width < template.Width && _rect.Height < template.Height)
                {
                    continue;
                }
                if ((_rect.X > 0 || (_rect.X + _rect.Width) > 0) &&
                    (_rect.Y > 0 || (_rect.Y + _rect.Height) > 0))
                {
                    windowrect = _rect;
                    continue;
                }
            }

            Interfaces.GenericTools.minimize(Interfaces.GenericTools.mainWindow);
            var rect = await getrectangle.GetitAsync();

            var limit = new System.Drawing.Rectangle(rect.X - (int)windowrect.X, rect.Y - (int)windowrect.Y, rect.Width, rect.Height);

            ModelItem.Properties["Limit"].SetValue(new System.Activities.InArgument <System.Drawing.Rectangle>(limit));
            Interfaces.GenericTools.restore();
            NotifyPropertyChanged("Limit");
        }
Beispiel #2
0
        private bool findMatch()
        {
            try
            {
                //var results = new List<Rectangle>();
                if (!running)
                {
                    return(false);
                }
                try
                {
                    var with = template.Width;
                }
                catch (Exception)
                {
                    running = false;
                    //waitHandle.Set();
                }
                if (string.IsNullOrEmpty(Processname))
                {
                    var desktop = Interfaces.Image.Util.Screenshot();
                    GC.KeepAlive(template);
                    var results = Matches.FindMatches(desktop, template, threshold, 10, CompareGray);
                    if (results.Count() > 0)
                    {
                        this.results = results;
                        return(true);
                    }
                }
                else
                {
                    var ps = System.Diagnostics.Process.GetProcessesByName(Processname);
                    foreach (var p in ps)
                    {
                        var rects           = new List <Rectangle>();
                        var allChildWindows = new WindowHandleInfo(p.MainWindowHandle).GetAllChildHandles();
                        allChildWindows.Add(p.MainWindowHandle);
                        foreach (var window in allChildWindows)
                        {
                            WindowHandleInfo.RECT rct;
                            if (!WindowHandleInfo.GetWindowRect(new HandleRef(this, window), out rct))
                            {
                                continue;
                            }
                            var rect = new Rectangle(rct.Left, rct.Top, rct.Right - rct.Left + 1, rct.Bottom - rct.Top + 1);
                            if (!limit.IsEmpty)
                            {
                                rect = new Rectangle(rect.X + limit.X, rect.Y + limit.Y, limit.Width, limit.Height);
                            }
                            if (rect.Width < template.Width || rect.Height < template.Height)
                            {
                                continue;
                            }
                            if ((rect.X > 0 || (rect.X + rect.Width) > 0) &&
                                (rect.Y > 0 || (rect.Y + rect.Height) > 0))
                            {
                                rects.Add(rect);
                            }
                        }
                        foreach (var rect in rects.ToList())
                        {
                            foreach (var subrect in rects.ToList())
                            {
                                if (rect.Contains(subrect) && !rect.Equals(subrect))
                                {
                                    rects.Remove(subrect);
                                }
                            }
                        }
                        foreach (var rect in rects)
                        {
                            // System.Diagnostics.Trace.WriteLine("**** Match within window at " + rect.ToString());
                            var desktop = Interfaces.Image.Util.Screenshot(rect);
                            try
                            {
                                var results = Matches.FindMatches(desktop, template, threshold, 10, CompareGray);
                                if (results.Count() > 0)
                                {
                                    var finalresult = new List <Rectangle>();
                                    for (var i = 0; i < results.Length; i++)
                                    {
                                        results[i].X += rect.X;
                                        results[i].Y += rect.Y;
                                    }

                                    this.results = results;
                                    //this.result = results[0];
                                    // this.result = new Rectangle(rect.X + results[0].X, rect.Y + results[0].Y, results[0].Width, results[0].Height);

                                    //if (!limit.IsEmpty)
                                    //{
                                    //    this.result = new Rectangle((int)w.BoundingRectangle.X + limit.X + results[0].X, (int)w.BoundingRectangle.Y + limit.Y + results[0].Y, results[0].Width, results[0].Height);
                                    //}
                                    return(true);
                                }
                            }
                            catch (Exception ex)
                            {
                                System.Diagnostics.Trace.WriteLine(ex.ToString());
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Interfaces.Log.Error(ex.ToString());
            }
            return(false);
        }