如何从另一个Windows应用程序获取Chrome 28中的当前URL? [英] How to get the current URL from Chrome 28 from another Windows application?

查看:842
本文介绍了如何从另一个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 课程集:

  • 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆