Пример #1
0
        private IEnumerable <IntPtr> FindElementsInPokerStarsLobby(string className, string title, bool isVisible, Size size, double sizeAccuracy, Rectangle areaToSearch, double areaToSearchAccuracy, List <Bmp> bmps, double bmpsMatchAccuracy, double bmpsColorAccuracy)
        {
            List <IntPtr> possibleComponents       = new List <IntPtr>();
            Bmp           bmpWindowPokerStarsLobby = GetBmpWindowPokerStarsLobby();

            foreach (IntPtr handle in WinApi.FindAllChildWindowByClass(_handleWindowPokerStarsLobby, className).Where(o => WinApi.IsWindowVisible(o) == isVisible))
            {
                string rawTitle = WinApi.GetWindowTextRaw(handle);
                if ((string.IsNullOrEmpty(title) && string.IsNullOrEmpty(rawTitle)) || (!string.IsNullOrEmpty(title) && rawTitle.Equals(title)))
                {
                    Rectangle r = WinApi.GetClientRectangleRelativeTo(handle, _handleWindowPokerStarsLobby);
                    if (Math.Abs(size.Width - r.Width) <= size.Width - size.Width * sizeAccuracy && Math.Abs(size.Height - r.Height) <= size.Height - size.Height * sizeAccuracy)
                    {
                        if (areaToSearch.Left - (bmpWindowPokerStarsLobby.Width - bmpWindowPokerStarsLobby.Width * areaToSearchAccuracy) <= r.Left &&
                            areaToSearch.Top - (bmpWindowPokerStarsLobby.Height - bmpWindowPokerStarsLobby.Height * areaToSearchAccuracy) <= r.Top &&
                            areaToSearch.Right + (bmpWindowPokerStarsLobby.Width - bmpWindowPokerStarsLobby.Width * areaToSearchAccuracy) >= r.Right &&
                            areaToSearch.Bottom + (bmpWindowPokerStarsLobby.Height - bmpWindowPokerStarsLobby.Height * areaToSearchAccuracy) >= r.Bottom)
                        {
                            Bmp cutBmp = bmpWindowPokerStarsLobby.CutRectangle(r);
                            foreach (Bmp bmp in bmps)
                            {
                                Point point = FindBmp(cutBmp, bmp, bmpsMatchAccuracy, bmpsColorAccuracy);
                                if (point.X == 0 && point.Y == 0)
                                {
                                    possibleComponents.Add(handle);
                                }
                            }
                        }
                    }
                }
            }

            return(possibleComponents.Distinct());
        }