本文介绍了如何从另一个Windows应用程序获取Chrome 28中的当前URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

直到Chrome V27,您可以枚举Chrome子窗口控件进入编辑字段,并从中读取字符串值以获取当前打开的URL。

Up to Chrome V27 you could enumerate Chrome child window controls to get to the edit field and read the string value from there to get the current opened URL.

不幸的是Chrome 28已经切换到新的渲染引擎(Blink),除了主窗口(Chrome_WidgetWin_1)和网页标签(Chrome_RenderWidgetHostHWND)之外,还没有使用Windows控件。

Unfortunately Chrome 28 has switched to the new rendering Engine (Blink) and does not use Windows controls anymore besides the main window (Chrome_WidgetWin_1) and the web page tab (Chrome_RenderWidgetHostHWND).

如果有人可以指出从另一个(Win32)应用程序获取当前打开的Chrome URL的另一种方法,我将不胜感激。

I would be grateful if someone could point to an alternative method of getting the currently opened Chrome URL from another (Win32) application.

推荐答案

Chrome支持Windows辅助功能API,因此您可以使用这些API来从Chrome(包括broswer栏)以及网页中提取信息。将这个API看作更抽象的枚举窗口控件。

Chrome supports the Windows accessibility APIs, so you can use those to extract information both from the chrome - including the broswer bar - and also from web pages. Think of this API as a more abstract version of enumerating window controls.

查看工具来探索可以访问的信息 - 它看起来好像地址栏并且内容可用。

Check out the Inspect Objects tool to explore what information you can get access to - it does look as though the address bar and contents are available.

您可以使用课程集:


  • 使用AutomationElement windowEl = ;作为起点,如果你知道树的HWND

  • 然后尝试AutomationElement editEl = (TreeScope.Descendants,new PropertyCondition(AutomationElement.ControlTypeProperty,))来找到具有EditType的第一个元素。 FindFirst对树进行深度优先搜索,在这种情况下,它将会起作用;可以使用TreeWalker类,如果你想自己一步一步走。

  • 使用以下方式将发现的元素转换为ValuePattern:ValuePattern vp =(ValuePattern);

  • 最后,使用string str = vp.Current.Value;获取编辑的价值。

  • use AutomationElement windowEl = AutomationElement.FromHandle(new IntPtr(hwnd)); as a starting point if you know the HWND of the tree
  • then try AutomationElement editEl = AutomationElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit)) to find the first element that has ControlType of Edit. FindFirst does a depth-first search of the tree, which looks like it will work in this case; can use the TreeWalker classes if you want to walk step-by-step yourself.
  • 'cast' the found element to a ValuePattern using: ValuePattern vp = (ValuePattern) editEl.GetCurrentPattern(ValuePattern.Pattern);
  • Finally, use string str = vp.Current.Value; to get the value of the edit.

这篇关于如何从另一个Windows应用程序获取Chrome 28中的当前URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 07:19