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函数不执行呀,大大帮我看看吧

解决方案 »

  1.   

    sendmessage好像什么反映也,没有呀,不知怎么回事呀,我是想编一个自动登录的东西呀,大家帮我看看吧
      

  2.   

    模拟鼠标单击,使用POSTMESSAGE发送按下与抬起消息,其间再延时一点....就OK了postmessage hwnd,wm_lbuttondown,0,0
    sleep 50
    postmessage hwnd,wm_lbuttonup,0,0
      

  3.   

    还是不行呀,sendmessage好像还是不执行呀,我感觉sendmessage/postmessage好像都不执行呀,我的电脑是vwindows2003,是不是这的问题,我用delphi都可以实现相同的功能,不知是怎么回事呀。
      

  4.   

    我要编一个vactiveX控件呀,太郁闷了,sendmessage老是没反映,大家都遇到这种情况了吗
      

  5.   

    终于解决了,是我的消息没有定义呀,
    Const WM_CLOSE = &H10
    Const BM_CLICK = &HF5
    Const WM_SETTEXT = &HC
    这样就可以了,谢谢大家了,大家以后注意这样的问题呀,给大家加分