如何编程获得屏幕上任意时刻 鼠标光标的类型?比如屏幕的任意位置鼠标的手型,正常型,漏斗型等。

解决方案 »

  1.   

    '这是一个简单的控制光标移动的程序,按开始演示按钮,光标就会向Command1按钮
    '移动,然后向Command1发送按下鼠标左键的消息
    '
    '               作者        陈锐
    '               E-Main      [email protected]
    '                           [email protected]
    '               Web         http://vbtips.yeah.net
    Private Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End TypePrivate Type POINTAPI
            X As Long
            Y As Long
    End TypeConst WM_LBUTTONUP = &H202Private Declare Function GetWindowRect Lib "user32" _
            (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Declare Function SetCursorPos Lib "user32" _
            (ByVal X As Long, ByVal Y As Long) As Long
    Private Declare Function GetCursorPos Lib "user32" _
            (lpPoint As POINTAPI) 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) As LongDim PoDist As POINTAPI
    Dim PoSrc As POINTAPI
    Dim Nx As Integer
    Dim Ny As Integer
    Dim MoveCount As Integer
    Dim PoMid As POINTAPIPrivate Sub Command1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        MsgBox ("你按下了Command1键")
        Timer1.Enabled = False
    End SubPrivate Sub Command2_Click()
        Dim ConRect As RECT    '获得Command1在屏幕上的坐标
        GetWindowRect Command1.hwnd, ConRect
        '获得要移动到的位置的光标的坐标
        PoDist.X = ConRect.Left: PoDist.Y = ConRect.Top
        '获得当前光标的坐标
        GetCursorPos PoSrc
        
        Timer1.Enabled = True
        Nx = PoDist.X - PoSrc.X: Ny = PoDist.Y - PoSrc.Y
        '设置光标平滑移动的步数(这里是10步)
        Nx = Nx \ 10: Ny = Ny \ 10
        PoMid = PoSrc
    End SubPrivate Sub Timer1_Timer()
        PoMid.X = PoMid.X + Nx: PoMid.Y = PoMid.Y + Ny
        SetCursorPos PoMid.X, PoMid.Y
        MoveCount = MoveCount + 1
        If MoveCount > 10 Then
            Timer1.Enabled = False
            SendMessage Command1.hwnd, WM_LBUTTONUP, 10, 10
        End If
    End Sub如果要获取形状,就获承鼠标位置处图像,然后分析图像吧
      

  2.   

    下面的方法可以将当前的Icon绘制出来:Public Declare Function GetCursor Lib "user32" () As Long
    Public Declare Function CopyIcon Lib "user32" (ByVal hIcon As Long) As Long
    Public Declare Function DrawIcon Lib "user32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal hIcon As Long) As LongPrivate Sub Command1_Click()
        Dim x As Long
        Dim h As Long
        
        x = GetCursor
        Debug.Print x
        h = CopyIcon(x)
        Debug.Print h
        
        DrawIcon Me.hdc, 10, 10, h
    End Sub
      

  3.   

    任意时刻不可能,但在定时到来时可以,先取得光标位置(一个API就可以),再取得该位置的HWND,再用GETCLASSLONG取该HWND的光标句柄,如果是系统光标你用SELECT CASE就能知道形状,前面有兄弟已经说到从文件加载的问题了,那样的话你只会得到一个LONG型数据,不会知道形状的。
    这个问题有什么实际意义吗?用来熟悉几个API还可以,没什么应用价值吧,一眼就能看见形状还要麻烦愚笨的程序做什么?^_^