C# как найти URL из браузера, используя AccessibleObjectFromPoint
Привет! Я провел некоторое исследование и выяснил, как получить URL-адрес браузера с помощью AccessibleObjectFromPoint или, таким образом, вы можете получить доступ к любому элементу пользовательского интерфейса, поэтому, пожалуйста, скажите мне, что не так в моем коде
ОШИБКА:- **** ПОЛУЧЕНИЕ 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;
}
}