如果我随便给个行不行? 如:private strLp as string clipcursor(strLp) 这样行吗?? 请给个例子我,我刚学VB的!谢谢了
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
如:private strLp as string
clipcursor(strLp)
这样行吗??
请给个例子我,我刚学VB的!谢谢了
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
使用什么类型,要具体情况具体分析。严格按API函数原型的要求去做。VB调用API时会检查参数类型是否与声明相符,不对时,会给出错误提示,不符声明要求的,它拒绝调用。
而As Any之后,它相当于对VB说:“我有绝对把握不出错,这个参数用什么类型不用你管了!”,当然传错了,VB也不会管,责任自负!结果呢:呵呵,VB退出,罢工了^_^