VB6获取Chrome地址栏的URL信息
上篇写到了获取IE8浏览器URL的一般方法,那这篇就写下chrome的URL怎么获取。事实上,早期的chrome版本可以通过跟IE8差不多方式获取到URL信息。但是,现在chrome的控件都是DirectUI画出来的,所有就没有一般意义上hwnd可以取。网上搜索了下,大多数都倾向于使用MSAA(Microsoft Active Accessibility)这种途径来实现。感兴趣的同学可以搜索下MSAA,这是一个很有用的技术(因为不懂,我也就不多说了)。
基于MSAA思想,windows下的UI程序都可以提供一种可供遍历访问的接口。而界面上各个控件都处于类似于树的逻辑结构中,这使得第三方自动化控制成为了可能。而MSAA是以COM形式存在,使用时只需要在“引用”中添加即可,非常方便。
可能初次接触MSAA的同学还不能很好理解,关于UI结构的说明。但仔细思考下,本文这样的遍历和上篇根据hwnd的遍历其实原理上是差不多的。
实现代码如下:
'使用IAccessible接口之前,请先引用Accessibility(oleacc.dll)
'代码参考了很多网上代码,多数原作者无从考究,在此也就不列出了(请见谅)
'@Advanced Miscrosoft Visual Basci 6.0
'code by lichmama from cnblogs.com
Private Type UUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4() As Byte
End Type Private Declare Function AccessibleObjectFromWindow Lib "oleacc" (ByVal hwnd As Long, _
ByVal dwObjectID As Long, _
ByRef riid As UUID, _
ByRef ppvObject As Any) As Long Private Declare Function AccessibleChildren Lib "oleacc" (ByVal paccContainer As IAccessible, _
ByVal iChildStart As Long, _
ByVal cChildren As Long, _
rgvarChildren As Variant, _
pcObtained As Long) As Long '其实这一部分对整个程序来说没什么作用,在此列出仅仅方便别人查阅
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long Private Enum NVADIRConstants
NAVDIR_MIN =
NAVDIR_UP =
NAVDIR_DOWN =
NAVDIR_LEFT =
NAVDIR_RIGHT =
NAVDIR_NEXT =
NAVDIR_PREVIOUS =
NAVIDR_FIRSTCHILD =
NAVDIR_LASTCHILD =
NAVDIR_MAX =
End Enum 'IAccessible Object Types
Private Const CHILDID_SELF As Long = &
Private Const ROLE_SYSTEM_TITLEBAR As Long = &H1&
Private Const ROLE_SYSTEM_MENUBAR As Long = &H2&
Private Const ROLE_SYSTEM_SCROLLBAR As Long = &H3&
Private Const ROLE_SYSTEM_GRIP As Long = &H4&
Private Const ROLE_SYSTEM_SOUND As Long = &H5&
Private Const ROLE_SYSTEM_CURSOR As Long = &H6&
Private Const ROLE_SYSTEM_CARET As Long = &H7&
Private Const ROLE_SYSTEM_ALERT As Long = &H8&
Private Const ROLE_SYSTEM_WINDOW As Long = &H9&
Private Const ROLE_SYSTEM_CLIENT As Long = &HA&
Private Const ROLE_SYSTEM_MENUPOPUP As Long = &HB&
Private Const ROLE_SYSTEM_MENUITEM As Long = &HC&
Private Const ROLE_SYSTEM_TOOLTIP As Long = &HD&
Private Const ROLE_SYSTEM_APPLICATION As Long = &HE&
Private Const ROLE_SYSTEM_DOCUMENT As Long = &HF&
Private Const ROLE_SYSTEM_PANE As Long = &H10&
Private Const ROLE_SYSTEM_CHART As Long = &H11&
Private Const ROLE_SYSTEM_DIALOG As Long = &H12&
Private Const ROLE_SYSTEM_BORDER As Long = &H13&
Private Const ROLE_SYSTEM_GROUPING As Long = &H14&
Private Const ROLE_SYSTEM_SEPARATOR As Long = &H15&
Private Const ROLE_SYSTEM_TOOLBAR As Long = &H16&
Private Const ROLE_SYSTEM_STATUSBAR As Long = &H17&
Private Const ROLE_SYSTEM_TABLE As Long = &H18&
Private Const ROLE_SYSTEM_COLUMNHEADER As Long = &H19&
Private Const ROLE_SYSTEM_ROWHEADER As Long = &H1A&
Private Const ROLE_SYSTEM_COLUMN As Long = &H1B&
Private Const ROLE_SYSTEM_ROW As Long = &H1C&
Private Const ROLE_SYSTEM_CELL As Long = &H1D&
Private Const ROLE_SYSTEM_LINK As Long = &H1E&
Private Const ROLE_SYSTEM_HELPBALLOON As Long = &H1F&
Private Const ROLE_SYSTEM_CHARACTER As Long = &H20&
Private Const ROLE_SYSTEM_LIST As Long = &H21&
Private Const ROLE_SYSTEM_LISTITEM As Long = &H22&
Private Const ROLE_SYSTEM_OUTLINE As Long = &H23&
Private Const ROLE_SYSTEM_OUTLINEITEM As Long = &H24&
Private Const ROLE_SYSTEM_PAGETAB As Long = &H25&
Private Const ROLE_SYSTEM_PROPERTYPAGE As Long = &H26&
Private Const ROLE_SYSTEM_INDICATOR As Long = &H27&
Private Const ROLE_SYSTEM_GRAPHIC As Long = &H28&
Private Const ROLE_SYSTEM_STATICTEXT As Long = &H29&
Private Const ROLE_SYSTEM_TEXT As Long = &H2A&
Private Const ROLE_SYSTEM_PUSHBUTTON As Long = &H2B&
Private Const ROLE_SYSTEM_CHECKBUTTON As Long = &H2C&
Private Const ROLE_SYSTEM_RADIOBUTTON As Long = &H2D&
Private Const ROLE_SYSTEM_COMBOBOX As Long = &H2E&
Private Const ROLE_SYSTEM_DROPLIST As Long = &H2F&
Private Const ROLE_SYSTEM_PROGRESSBAR As Long = &H30&
Private Const ROLE_SYSTEM_DIAL As Long = &H31&
Private Const ROLE_SYSTEM_HOTKEYFIELD As Long = &H32&
Private Const ROLE_SYSTEM_SLIDER As Long = &H33&
Private Const ROLE_SYSTEM_SPINBUTTON As Long = &H34&
Private Const ROLE_SYSTEM_DIAGRAM As Long = &H35&
Private Const ROLE_SYSTEM_ANIMATION As Long = &H36&
Private Const ROLE_SYSTEM_EQUATION As Long = &H37&
Private Const ROLE_SYSTEM_BUTTONDROPDOWN As Long = &H38&
Private Const ROLE_SYSTEM_BUTTONMENU As Long = &H39&
Private Const ROLE_SYSTEM_BUTTONDROPDOWNGRID As Long = &H3A&
Private Const ROLE_SYSTEM_WHITESPACE As Long = &H3B&
Private Const ROLE_SYSTEM_PAGETABLIST As Long = &H3C&
Private Const ROLE_SYSTEM_CLOCK As Long = &H3D&
Private IID_IAccessible As UUID
Private Declare Function GetTickCount Lib "kernel32" () As Long Private Sub Form_Initialize()
With IID_IAccessible
.Data1 = &H618736E0
.Data2 = &H3C3D
.Data3 = &H11CF
.Data4() = &H81
.Data4() = &HC
.Data4() = &H0
.Data4() = &HAA
.Data4() = &H0
.Data4() = &H38
.Data4() = &H9B
.Data4() = &H71
End With
End Sub 'using like: GetChromeUrl(FindWindow("Chrome_WidgetWin_1", vbNullString))
Private Function GetChromeUrl(ByVal hwnd As Long) As String
Dim objAcc As IAccessible Call AccessibleObjectFromWindow(hwnd, &, IID_IAccessible, objAcc)
If objAcc Is Nothing Then
Debug.Print "access failed"
Exit Function
End If GetChromeUrl = ViewAcc(objAcc)
End Function Private Function ViewAcc(ByVal objAcc As IAccessible) As String
On Error Resume Next
If objAcc.accName(CHILDID_SELF) = "地址和搜索栏" Then
ViewAcc = "http://" & objAcc.accValue(CHILDID_SELF)
Exit Function
ElseIf objAcc.accChildCount = Then
Exit Function
End If Dim kids() As Variant
Dim kidscount As Long
Dim realcount As Long kidscount = objAcc.accChildCount
ReDim kids(kidscount - ) As Variant
Call AccessibleChildren(objAcc, &, kidscount, kids(), realcount)
For i = To realcount -
If TypeName(kids(i)) = "IAccessible" Then
ViewAcc = ViewAcc(kids(i))
If ViewAcc <> "" Then Exit For
End If
Next
End Function
运行下看看效果:
Private Sub Command1_Click()
For i = To
o = GetTickCount()
Debug.Print GetChromeUrl(FindWindow("Chrome_WidgetWin_1", vbNullString))
Debug.Print GetTickCount() - o & "ms"
Next
End Sub
看来这递归的效率有点低
http://www.cnblogs.com/lichmama/p/.html
453ms
http://www.cnblogs.com/lichmama/p/.html
422ms
http://www.cnblogs.com/lichmama/p/.html
391ms
http://www.cnblogs.com/lichmama/p/.html
406ms
http://www.cnblogs.com/lichmama/p/.html
406ms
http://www.cnblogs.com/lichmama/p/.html
391ms
http://www.cnblogs.com/lichmama/p/.html
406ms
http://www.cnblogs.com/lichmama/p/.html
406ms
http://www.cnblogs.com/lichmama/p/.html
407ms
http://www.cnblogs.com/lichmama/p/.html
390ms
VB6获取Chrome地址栏的URL信息的更多相关文章
- VB6获取IE8的地址栏的URL信息
这是个老梗了,也没什么技术含量.因为自从接触Linux之后,Windows上我所知道的那一点api基本上都忘光了.所以这样的博文可以当做是备忘,说不定有天还能用的到. Windows上想要获取浏览器的 ...
- 6 获取请求头和URL信息
@app.route("/req",methods=['GET','POST'])def req(): print(request.headers) #请求头的信息全部在这里面 p ...
- ASP.NET获取请求的url信息汇总
ASP.NET获取请求的url信息汇总 最近做项目需要处理一个用代码获取当前网站的域名或ip信息的问题,于是尝试了ASP.NET中各种获取url信息的方法,在此总结一下: 在Global.asax文件 ...
- 一个用php实现的获取URL信息的类
获取URL信息的类 使用这个类,你能获得URL的如下信息: - Host - Path - Statuscode (eg. 404,200, ...) - HTTP Version - Ser ...
- JS分页 + 获取MVC地址栏URL路径的最后参数
@{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport&quo ...
- jQuery 获取 URL信息
jQuery获取URL信息有很多方法,但是使用这个插件就非常爽了. 托管地址在:http://github.com/allmarkedup/jQuery-URL-Parser // http: //l ...
- 获取当前页面的URL信息
以前在做网站的时候,经常会遇到当前页的分类高亮显示,以便让用户了解当前处于哪个页面.之前一直是在每个不同页面写方法.工程量大,也不便于修改.一直在想有什么简便的方法实现.后来在网上查到可以用获取当前U ...
- Javascrip获取页面URL信息
使用Javascript可以方便获得页面的参数信息,常用的几种如下: 设置或获取对象指定的文件名或路径 window.location.pathname 设置或获取整个 URL 为字符串 wind ...
- js获取当前页面url信息
<html> <head> <meta charset="utf-8" /> <title></title> <s ...
随机推荐
- struts2.1.6教程十一、注解配置
在此先略去注解配置的实例,具体可以参看官方提供的文档.其实在熟悉struts及相关的一些内容后,再来看文档是比较容易理解得.只是要注意使用注解Annotition时: (1)要多导入一个jar包:st ...
- 【T-SQL性能优化】01.TempDB的使用和性能问题
以前总是追求新东西,发现基础才是最重要的,今年主要的目标是精通SQL查询和SQL性能优化. 本系列[T-SQL基础]主要是针对T-SQL基础的总结. [T-SQL基础]01.单表查询-几道sql查询题 ...
- 一天搞定CSS: 浮动(float)与inline-block的区别--11
浮动: 使元素脱离文档流,按照指定的方向发生移动,遇到父级的边界或者相邻的浮动元素就会停下来. inline-block: inline-block是指行内块元素,它具有行内元素和块元素两者的特点,可 ...
- CTE递归 MAXRECURSION 遇到的问题
在使用Sql Server的时候,当需要递归的时候很多时候就会想到使用CTE.但是当递归层数比较多,超过了100层,或者是一个递归死循环的时候.执行就会爆递归次数已到,最多100的错误. 当面对第一种 ...
- js for循环 等腰三角形demo
<script> for(var i=1;i<10;i++){ for(var j=1;j<10-i;j++){document.write(" ")} f ...
- Eclipse中SVN设置文件为ignore后重新添加至版本控制
先前把需要版本控制的文件夹ignore了,用了很长时间找解决方法,结果发现竟如此简单,对eclipse的功能不熟悉啊. 方法如下: 在Window->Show View -> Naviga ...
- JS/jQ常用宽高及应用
关于js的宽高,随便一搜就是一大堆.这个一大堆对我来说可不是什么好事,看的头都大了.所以今天就总结了一些比较会常用的,并说明一下应用场景. 先来扯一下documentElement和body的微妙关系 ...
- C++11 单例类实现
单例类: (1) 单例类保证全局只有一个唯一的实例对象. (2) 单例类保证只有唯一的接口获取这唯一实例. 非线程安全的单例类举例: class CSingleton { public: ~CSing ...
- python 最佳实践与资源汇总
python 最佳实践 (部分) 一. 结构化工程 文件 功能 README.rst readme LICENSE 许可证 setup.py 打包和发布管理 requirements.txt 开发依赖 ...
- jersery+jetty嵌入式restful的框架开发
随着微服务的流程,越来越多的后台服务采用了restful api风格的开放API,jersery+jetty嵌入式变成了一个很好的选择, 我自己写了一个简单的框架,https://github.com ...