sendMessage/postmessage 代码不执行
Private Declare Function WinExec Lib "kernel32 " (ByVal lpCmdLine As String, ByVal nCmdShow As Long) As Long
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)
Private Declare Function PostMessage& Lib "user32 " Alias "PostMessageA " (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
Private Declare Sub Sleep Lib "kernel32 " (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
Dim aa As Long
Dim ParentHandle As Long
Dim bottonHandle As Long
Dim usernanmeHandle As Long
Dim passwordHandle As Long
Dim serverpathHandle As Long
Dim p As Long
Dim u As Long
Dim s As Long
Dim ss As Integer
Dim aabb As String
aa = WinExec( "D:\OLE-TECH\SmarGroup4.5\Bin\StartUp.exe ", 0)
Sleep (1000)
ParentHandle = FindWindow( "ThunderRT6FormDC ", "登录 ")
'Call SendMessage(parenhandle, WM_CLOSE, 0, 0)
If ParentHandle <> 0 Then
'MsgBox (ParentHandle)
bottonHandle = FindWindowEx(ParentHandle, 0, "ThunderRT6CommandButton ", "确定 ")
'MsgBox (bottonHandle)
If bottonHandle <> 0 Then
'MsgBox (bottonHandle)
serverpathHandle = FindWindowEx(ParentHandle, bottonHandle, "ThunderRT6TextBox ", Nil)
'MsgBox (serverpathHandle)
If serverpathHandle <> 0 Then
passwordHandle = FindWindowEx(ParentHandle, serverpathHandle, "ThunderRT6TextBox ", Nil)
If passwordHandle <> 0 Then
Call SendMessage(passwordHandle, WM_SETTEXT, 0, ByVal CStr( "aaa "))
usernamehandle = FindWindowEx(ParentHandle, passwordHandle, "ThunderRT6TextBox ", Nil)
'MsgBox (usernamehandle)
If usernamehandle <> 0 Then
Call SendMessage(usernamehandle, WM_SETTEXT, 0, "bbb ")
MsgBox (u)
s = SendMessage(bottonHandle, BM_CLICK, 0, 0)
End If
End If
End If
End If
End If
End Sub
代码中好像sendmessage函数不执行呀,大大帮我看看吧
[解决办法]
模拟鼠标单击,使用POSTMESSAGE发送按下与抬起消息,其间再延时一点....就OK了
postmessage hwnd,wm_lbuttondown,0,0
sleep 50
postmessage hwnd,wm_lbuttonup,0,0
[解决办法]
单步调试一下,看看哪里有问题