Example #1
0
        //メニューウィンドウの収集、メニューウィンドウにはTextがないので、これを利用している
        /// <summary>
        /// NextWindowを指定回数まで遡って、TextありのWindowが出るまですべて取得。Nextってのは基準になるウィンドウの下、Z軸(Zオーダー)で見たときの下にあるWindow。
        /// </summary>
        /// <param name="hWnd">基準になるウィンドウハンドル</param>
        /// <param name="loopCount">Nextを辿る回数の上限値</param>
        /// <returns>ウィンドウハンドル、RECT、Text</returns>
        private (List <IntPtr> ptrs, List <API.RECT> res, List <string> strs) GetNextWindowsWithNoneText(IntPtr hWnd, int loopCount)
        {
            List <IntPtr>   ptrs  = new();
            List <API.RECT> res   = new();
            List <string>   strs  = new();
            int             count = 0;

            IntPtr temp = hWnd;

            //NextWindowの収集
            do
            {
                if (temp == IntPtr.Zero)
                {
                    break;                     //Nextがなければ完了
                }
                string text = GetWindowText(temp);
                //TextがあるWindowなら完了
                if (text != "")
                {
                    break;
                }
                //Rectの幅や高さが0なら完了
                API.RECT r = GetWindowRect(temp);
                if (r.bottom - r.top == 0 || r.right - r.left == 0)
                {
                    break;
                }

                //リストに追加
                ptrs.Add(temp);
                res.Add(r);
                strs.Add(text);

                //下の階層(next)のWindow取得
                temp = API.GetWindow(temp, API.GETWINDOW_CMD.GW_HWNDNEXT);
                count++;
            } while (count < loopCount);

            return(ptrs, res, strs);
        }
Example #2
0
 private Rect MyConvertApiRectToRect(API.RECT rect)
 {
     return(new Rect(rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top));
 }