
获取IE8 地址栏和搜索栏字符
窗体中添加一个List控件 一个按钮
'窗体代码:
Private Sub Command1_Click()
List1Clear
EnumWindows AddressOf enumproc, 0
End Sub
'模块:
'module1bas 文件
'---------------
Option Explicit
'相关 api 函数声明
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
' '枚举窗口列表中的所有父窗口(顶级和被所有窗口)
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long '取得指定窗口的司法题
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long '为指定的窗口取得类名
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long '取得窗口句柄
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long '发送消息
Const gw_child = 5
Const gw_hwndnext = 2
Const wm_gettext = &HD
Const wm_gettextlength = &HE
'遍查主窗口
Public Function enumproc(ByVal app_hwnd As Long, ByVal lParam As Long) As Boolean
Dim buf As String 1024
Dim length As Long
Dim title As String
length = GetWindowText(app_hwnd, buf, Len(buf))
title = Left$(buf, length)
'判断是否为 ie 浏览器窗口
If InStr(title, "Internet Explorer") Then
Call getziwin(app_hwnd)
End If
enumproc = 1
End Function
'遍查子窗口
Public Function getziwin(window_hwnd As Long) As String
Dim buf As String
Dim buflen As Long
Dim child_hwnd As Long
Dim children() As Long
Dim num_children As Integer
Dim i As Integer
buflen = 256
buf = Space$(buflen - 1)
buflen = GetClassName(window_hwnd, buf, buflen)
buf = Left$(buf, buflen) '取得子窗口的类名
If Right(buf, 4) = "Edit" Then '判断是否为地址栏子窗口
getziwin = getwintext(window_hwnd)
Exit Function
End If
num_children = 0
child_hwnd = GetWindow(window_hwnd, gw_child) '取得第 1 个子窗口的句柄
Do While child_hwnd <> 0 '如果有子窗口
num_children = num_children + 1
ReDim Preserve children(1 To num_children)
children(num_children) = child_hwnd
child_hwnd = GetWindow(child_hwnd, gw_hwndnext) '取得下一个兄弟窗口的句柄
Loop
For i = 1 To num_children
Call getziwin(children(i))
Next i
End Function
Public Function getwintext(window_hwnd As Long) As String '取得子窗口的值
Dim txtlen As Long
Dim txt As String
'通过 sendmessage 发送 wm_gettext 取得 ie 地址栏的值
getwintext = ""
If window_hwnd = 0 Then Exit Function
txtlen = SendMessage(window_hwnd, wm_gettextlength, 0, 0)
If txtlen = 0 Then Exit Function
txtlen = txtlen + 1
txt = Space$(txtlen)
txtlen = SendMessage(window_hwnd, wm_gettext, txtlen, ByVal txt)
getwintext = Left$(txt, txtlen)
Form1List1AddItem getwintext
End Function
浏览器地址栏消失了怎么办_百度经验:
>
以上就是关于VB如何获得浏览器地址栏全部内容。全部的内容,包括:VB如何获得浏览器地址栏全部内容。、浏览器地址栏在哪里、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)