模块1内容如下:
Option Explicit
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Any, 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, "Microsoft 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, 5) = "Edit" Then '判断是否为IE地址栏子窗口
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)
Form1.List1.AddItem GetWinText
End Function请问我如何往IE的地址栏窗口写入www.163.com并回车呢
Option Explicit
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Any, 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, "Microsoft 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, 5) = "Edit" Then '判断是否为IE地址栏子窗口
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)
Form1.List1.AddItem GetWinText
End Function请问我如何往IE的地址栏窗口写入www.163.com并回车呢
发送消息给IE地址栏,让其修改内容为www.163.com
再发送回车消息给IE地址栏以上三步你哪一步无法实现?