Public Declare Function ClipCursor Lib "user32" Alias "ClipCursor" (lpRect As Any) As Long请问这个函数里面的Any类型怎么定义呀?如果我想定义一下名为anyName的变量为Any类型时,应该怎么办??

解决方案 »

  1.   

    Any是API专用类型,它只是告诉VB在传参时不用进行类型检查,至于具体传什么类型,要酌情再定,这个函数,lpRect参数,你传一个Rect类型即可。一般不是解决不了的问题,不建议API参数用Any声明。
      

  2.   

    如果我随便给个行不行?
    如:private strLp as string
        clipcursor(strLp)
        这样行吗??
    请给个例子我,我刚学VB的!谢谢了
      

  3.   

    Private Type RECT
        left As Long
        top As Long
        right As Long
        bottom As Long
    End Type
    Private Type POINT
        x As Long
        y As Long
    End Type
    Private Declare Sub ClipCursor Lib "user32" (lpRect As Any)
    Private Declare Sub GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT)
    Private Declare Sub ClientToScreen Lib "user32" (ByVal hWnd As Long, lpPoint As POINT)
    Private Declare Sub OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long)
    Private Sub Form_Load()
        Command1.Caption = "Limit Cursor Movement"
        Command2.Caption = "Release Limit"
    End Sub
    Private Sub Command1_Click()
        'Limits the Cursor movement to within the form.
        Dim client As RECT
        Dim upperleft As POINT
        'Get information about our wndow
        GetClientRect Me.hWnd, client
        upperleft.x = client.left
        upperleft.y = client.top
        ClientToScreen Me.hWnd, upperleft
        'move our rectangle
        OffsetRect client, upperleft.x, upperleft.y
        'limit the cursor movement
        ClipCursor client
    End Sub
    Private Sub Command2_Click()
        'Releases the cursor limits
        ClipCursor ByVal 0&
    End Sub
    Private Sub Form_Unload(Cancel As Integer)
        'Releases the cursor limits
        ClipCursor ByVal 0&
    End Sub
      

  4.   

    Any只是告诉VB在传参时不用进行类型检查,不是可以随便传的!
    使用什么类型,要具体情况具体分析。严格按API函数原型的要求去做。VB调用API时会检查参数类型是否与声明相符,不对时,会给出错误提示,不符声明要求的,它拒绝调用。
    而As Any之后,它相当于对VB说:“我有绝对把握不出错,这个参数用什么类型不用你管了!”,当然传错了,VB也不会管,责任自负!结果呢:呵呵,VB退出,罢工了^_^