VB如何判断鼠标移动方向?

解决方案 »

  1.   

    http://download.csdn.net/detail/veron_04/3629729
      

  2.   

    要看移动方向,至少要在非同一时间内取两个不同的坐标.然后先取的坐标为基准,与后取的坐标的XY相减.结果为正,于X则说明是向左运动,于Y则是向上运动.结果为负,自己推得出来了吧:)
      

  3.   

    MYJIAN的思路好,看有谁贴好点的代码出来参考一下。
      

  4.   


    Option Explicit
    Private Type POINTAPI
            x As Long
            y As Long
    End Type
    Dim OldXY As POINTAPI
    Dim NowXY As POINTAPI
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Sub Form_Load()
        Dim lngP As Long
        Timer1.Interval = 100
        lngP = GetCursorPos(OldXY)
        lngP = GetCursorPos(NowXY)
    End SubPrivate Sub Timer1_Timer()
        Dim lngP As Long
        Dim strP As String
        lngP = GetCursorPos(NowXY)
        If OldXY.x - NowXY.x > 0 Then
            strP = "向左平移;"
        ElseIf OldXY.x - NowXY.x = 0 Then
            
        Else
            strP = "向右平移;"
        End If
        If OldXY.y - NowXY.y > 0 Then
            strP = strP & "向上移动;"
        ElseIf OldXY.y - NowXY.y = 0 Then
            
        Else
            strP = strP & "向下移动;"
        End If
        If strP <> "" Then Me.Caption = strP
        lngP = GetCursorPos(OldXY)
    End Sub