如何从Chrome浏览器28从另一个Windows应用程序的当前网址是什么? [英] How to get the current URL from Chrome 28 from another Windows application?

查看:1510
本文介绍了如何从Chrome浏览器28从另一个Windows应用程序的当前网址是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

改用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设定类:

  • 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屋!

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