|
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal nMaxCount As Long) As Long
Sub SetAddressBarText(ByVal address As String)
Dim hwnd As Long
hwnd = FindWindow("CabinetWClass", vbNullString) ' 查找文件资源管理器窗口句柄
If hwnd <> 0 Then
Dim buffer As String * 255
Dim length As Long
length = GetWindowText(hwnd, buffer, Len(buffer)) ' 获取地址栏标题内容
If length > 0 Then
Dim result As Long
result = SendMessage(hwnd, &HC, 0, ByVal address) ' 发送 WM_SETTEXT 消息设置地址栏文本
If result = 1 Then
MsgBox "设置地址栏文本成功!"
Else
MsgBox "设置地址栏文本失败!"
End If
Else
MsgBox "获取地址栏标题失败!"
End If
Else
MsgBox "找不到文件资源管理器窗口!"
End If
End Sub |
|