想使鼠标自动移动到指定一点(另一个程序的标题栏),然后点击左键SetCursorPos 5, 5
Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, GetMessageExtraInfo)
Call mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, GetMessageExtraInfo)鼠标可以移动到指定点,但不自动点击左键。因为另一程序的窗口并没有变成当前窗口。

解决方案 »

  1.   

    Private Sub LeftClick(ByVal x As Integer, ByVal y As Integer)
        Dim lParam As Long
        Dim LongInt As Long
         
        LongInt = 65536
        
        lParam = LongInt *  y + x    SendMessage Hwnd, WM_LBUTTONDOWN, 0&, lParam
        SendMessage Hwnd, WM_LBUTTONUP, 0&, lParam
    End Sub
      

  2.   

    试试楼上的,不行的话去vbgood看看,一定有你需要的
    http://www.sijiqing.com/vbgood/code/index.asp?glz=鼠标
      

  3.   

    flyingscv(zlj) 的方法可行,这是通常的做法
      

  4.   

    参考,应该对你有帮助:
    http://vbclass.y365.com/jishu/yaokong.htm
      

  5.   

    Private Sub cmdClick_Click()
    Const NUM_MOVES = 3000
    Dim pt As POINTAPI
    Dim cur_x As Single
    Dim cur_y As Single
    Dim dest_x As Single
    Dim dest_y As Single
    Dim dx As Single
    Dim dy As Single
    Dim i As Integer    ' Things are easier working in pixels.
        ScaleMode = vbPixels
        picClicker.ScaleMode = vbPixels    ' mouse_event moves in a coordinate system where
        ' (0, 0) is in the upper left corner and
        ' (65535,65535) is in the lower right corner.    ' Get the current mouse coordinates and convert
        ' them into this new system.
        GetCursorPos pt
        cur_x = pt.X * 65535 / ScaleX(Screen.Width, vbTwips, _
            vbPixels)
        cur_y = pt.Y * 65535 / ScaleY(Screen.Height, vbTwips, _
            vbPixels)    ' Convert the coordinates of the center of the
        ' picClicker PictureBox into this new system.
        pt.X = picClicker.ScaleWidth / 2
        pt.Y = picClicker.ScaleHeight / 2
        ClientToScreen picClicker.hwnd, pt
        dest_x = pt.X * 65535 / ScaleX(Screen.Width, vbTwips, _
            vbPixels)
        dest_y = pt.Y * 65535 / ScaleY(Screen.Height, vbTwips, _
            vbPixels)    ' Move the mouse.
        dx = (dest_x - cur_x) / NUM_MOVES
        dy = (dest_y - cur_y) / NUM_MOVES
        For i = 1 To NUM_MOVES - 1
            cur_x = cur_x + dx
            cur_y = cur_y + dy
            mouse_event _
                MOUSEEVENTF_ABSOLUTE + _
                MOUSEEVENTF_MOVE, _
                cur_x, cur_y, 0, 0
            DoEvents
        Next i    ' Move the mouse to its final destination and click it.
        mouse_event _
            MOUSEEVENTF_ABSOLUTE + _
            MOUSEEVENTF_MOVE + _
            MOUSEEVENTF_LEFTDOWN + _
            MOUSEEVENTF_LEFTUP, _
            dest_x, dest_y, 0, 0
    End Sub
      

  6.   

    我想请问一下“Private Sub LeftClick(ByVal x As Integer, ByVal y As Integer)”中的x,y是什么意思?另外,用    Dim j as Long
    Dim P As POINTAPI
    j=WindowFromPoint(P.x, P.y)
    SendMessage j, WM_LBUTTONDOWN, 0,0
    SendMessage j, WM_LBUTTONUP, 0,0当鼠标移动到本程序窗体内某一控件有效(如移动到command控件上),但当鼠标移动到本程序窗体外,另一程序窗体中则无效,另一程序的窗体并没有变成当前窗体。
      

  7.   

    //另一程序窗体中则无效,另一程序的窗体并没有变成当前窗体想把另一程序的窗体变成当前窗体的话,没不要这么麻烦,用findwindow获得窗口句柄后,用SetForegroundWindow将窗口设为前台窗口就可以
      

  8.   

    //SendMessage Hwnd, WM_LBUTTONDOWN, 0&, lParam
    SendMessage Hwnd, WM_LBUTTONUP, 0&, lParam方向肯定没有问题
    你要用findwindow找到窗体句柄后,再用findwindowex找到按钮句柄,然后发送消息
      

  9.   

    麻烦问一下:lParam 参数是什么意思
      

  10.   

    SendMessage Hwnd, WM_LBUTTONDOWN, 0&, lParam
    SendMessage Hwnd, WM_LBUTTONUP, 0&, lParam
    的确可以,不知前天是怎么搞的,就是不行,昨天一试就像大家所说的,可以了!
    不说那么多了,给分了。