Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Declare Function PostMessage& Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Public Const EM_REPLACESEL = &HC2
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 Const WM_GETTEXT = &HD
Private Const WM_GETTEXTLENGTH = &HE
Public Const GW_HWNDNEXT = 2
Public Const GW_HWNDFIRST = 0
Public Const WM_SETTEXT = &HC
Public Const GW_CHILD = 5
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Const VK_RETURN = &HD
Public Const WM_COPYDATA = &H4A
Public Function txtBuff() As String
Dim fh As Long, SendhWnd As Long, Hkey As Long
Dim n As Integer, nn As Integer
Dim s As String
Dim winame As String
Dim huanchong As String
fh = FindWindow(vbNullString, "爸爸") '需改动
'txtBuff = fh
fh = GetWindow(fh, GW_CHILD) '子窗体的子窗体
fh = GetWindow(fh, GW_CHILD) '分支
fh = GetWindow(fh, GW_CHILD) '分支
fh = GetWindow(fh, GW_CHILD) '分支
fh = GetWindow(fh, GW_CHILD)
fh = GetWindow(fh, GW_CHILD) '分支
fh = GetWindow(fh, GW_CHILD)
Do While fh <> 0
nn = nn + 1
If nn = 2 Then
s = String(255, 0)
Call GetClassName(fh, s, 255)
s = Left(s, InStr(s, Chr(0)) - 1)
'Debug.Print s
Dim txtLendth As Long
txtLength = SendMessage(fh, WM_GETTEXTLENGTH, ByVal CLng(0), ByVal CLng(0)) + 1
txtBuff = Space(txtLength)
retVal = SendMessage(fh, WM_GETTEXT, ByVal txtLength, ByVal txtBuff)
txtBuff = Left(txtBuff, retVal)
' Hkey = SendMessage(fh, WM_SETTEXT, 0&, ByVal Txt) '替换了EM_REPLACESEL
' Hkey = SendMessage(fh, WM_KEYDOWN, VK_RETURN, MapVirtualKey(VK_RETURN, WM_KEYDOWN))
End If
fh = GetWindow(fh, GW_HWNDNEXT)
Loop
Exit Function '得到目的则退出循环
End Function