|
测试了office2010的另存为对话框,edit控件句柄可以根据窗口层次用FindWindow和FindWindowEx找到,用spy++可以查看窗口层次
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_CHAR = &H102
Private Const WM_COMMAND = &H111
Sub DD()
Dim hEdit As Long '文本框句柄
Dim hwnd As Long '对话框句柄
SendString hEdit, FileFullName
SendMessage hwnd, WM_COMMAND, 1, 0
End Sub
Function SendChar(hwnd As Long, char As Long)
SendChar = PostMessage(hwnd, WM_CHAR, char, 0)
End Function
Function SendString(hwnd As Long, str As String)
Dim arr() As Byte
arr = StrConv(str, vbFromUnicode)
For i = LBound(arr) To UBound(arr)
SendString = SendChar(hwnd, CLng(arr(i)))
Next
End Function
|
|