如何从Chrome浏览器28从另一个Windows应用程序的当前网址是什么? [英] How to get the current URL from Chrome 28 from another Windows application?
问题描述
改用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已经切换到新的渲染引擎(闪烁),不再需要使用Windows控件除了主窗口(Chrome_WidgetWin_1)和网页标签(Chrome_RenderWidgetHostHWND)。
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)应用当前打开的浏览器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,所以你可以使用它们来提取无论从镀铬的信息 - 包括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.
检查出的Inspect对象工具去探索什么样的信息,你可以访问 - 它看起来好像地址栏和内容都可用。
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设定类:
- 使用AutomationElement windowEl =的AutomationElement.FromHandle(new的IntPtr(HWND));作为一个起点,如果你知道树
- 然后尝试AutomationElement editEl =的 AutomationElement.FindFirst (TreeScope.Descendants,新PropertyCondition(AutomationElement.ControlTypeProperty,的 ControlType.Edit ))发现,有编辑的ControlType的第一要素。 FindFirst中做了深度优先搜索树,它看起来像它会在这种情况下工作的;
- '投'找到的元素到ValuePattern使用,如果你想走路一步一步自己可以使用TreeWalker类:ValuePattern VP =(ValuePattern)的editEl.GetCurrentPattern(ValuePatten.PatternId);
- 最后,使用字符串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(ValuePatten.PatternId);
- Finally, use string str = vp.Current.Value; to get the value of the edit.
这篇关于如何从Chrome浏览器28从另一个Windows应用程序的当前网址是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!