1

嗨,我做了一些研究,找到了使用 AccessibleObjectFromPoint 获取浏览器 URL 的方法,或者通过这个你可以访问任何 UI 元素,所以请告诉我我的代码有什么问题

错误:- **** 每次都获取 ChildID = 0 不知道为什么 *******

Process[] processes = Process.GetProcessesByName("chrome");

            foreach (Process p in processes)
            {
                IntPtr windowHandle = p.MainWindowHandle;

                 Rectangle rect = new Rectangle();
                 GetWindowRect(windowHandle, out rect);
                 //System.Windows.Forms.MessageBox.Show("Top = " + rect.Top + "left = " + rect.Left + "width = " + rect.Width + "height = " + rect.Height + "X = " + rect.X + "Y = " + rect.Y + "Right = " + rect.Right + "Bottom = " + rect.Bottom);

                 System.Drawing.Point pt = new System.Drawing.Point();
                 if (rect.Width > 20 && rect.Height > 20)
                 {
                     pt.X = rect.Left + ((rect.Right - rect.Left) / 4); // point in the middle 
                     pt.Y = rect.Top + 30; // and a little bit lower (URL edit field)

                     int try_again_cnt = 0;
                 try_again:
                     pt.Y += 4;
                     if (try_again_cnt++ > 6)
                         return;

                     object varChildID;
                     IAccessible accObj;

                     IntPtr success = AccessibleObjectFromPoint(pt, out accObj, out varChildID);
                     int ChildID = (int)varChildID;
**** GETTING ChildID 0 EVERY TIME DONT KNOW WHY *******
                     if (ChildID != 0)
                     {
                         string s = accObj.get_accValue(varChildID);
                         System.Windows.MessageBox.Show(s);
                     }
                     else
                     {
                         goto try_again;
                     }

                 }
4

0 回答 0