匿名用户
1级
2019-01-07 回答
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Private Function GetWinText(ByVal hwnd As Long) As String
GetWinText = String(1024, Chr(0))
GetWindowText hwnd, GetWinText, Len(GetWinText)
GetWinText = Left$(GetWinText, InStr(GetWinText, Chr(0)) - 1)
End Function
Private Sub Command1_Click()
Dim i As Long, j As Long, s As String
i = GetWindow(hwnd, 0&)
Do Until i = 0
If IsWindowVisible(i) Then
s = Trim(GetWinText(i))
If instr(s,"Client Ver :") Then
'这时候i就是该程序的句柄,你可以在此发送按键消息了
'或者你也可以把这个i记录下来,然后在timer中向该窗口定时发送按键消息
exit sub
End If
End If
i = GetWindow(i, 2&)
Loop
End Sub