Private Declare Function ShowCursor Lib "user32" (ByVal bShow As Long) As LongPrivate Sub Command1_Click() '隐藏光标 ShowCursor False
End SubPrivate Sub Command2_Click() '显示光标 ShowCursor True End Sub
对上的代码完全正确。虽然看不到mouse指针,但mouse还起作用
补充一个锁定鼠标得代码 Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long Private Declare Function ClipCursorbynum& Lib "user32" Alias "ClipCursor" (ByVal lpRect As Long) Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As rect) As Long Private Type rect left As Long top As Long right As Long bottom As Long End Type Dim cc As rect Private Sub Command1_Click() '***************锁定鼠标到指定位置*********** GetWindowRect Form1.hwnd, cc ClipCursor cc '******************************************** End SubPrivate Sub Command2_Click() ClipCursorbynum 0 '释放鼠标 End Sub
'隐藏光标
ShowCursor False
End SubPrivate Sub Command2_Click()
'显示光标
ShowCursor True
End Sub
Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long
Private Declare Function ClipCursorbynum& Lib "user32" Alias "ClipCursor" (ByVal lpRect As Long)
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As rect) As Long
Private Type rect
left As Long
top As Long
right As Long
bottom As Long
End Type
Dim cc As rect
Private Sub Command1_Click()
'***************锁定鼠标到指定位置***********
GetWindowRect Form1.hwnd, cc
ClipCursor cc
'********************************************
End SubPrivate Sub Command2_Click()
ClipCursorbynum 0 '释放鼠标
End Sub