Type RECT Left As Long Top As Long Right As Long Bottom As LongEnd TypeDeclare Function ClipCursor Lib "user32" (lpRect As Any) As LongDeclare Function ShowCursor Lib "user32" (ByVal bShow As Long) As LongDeclare Function SetCursorPos Lib "user32" (ByVal x As Long, _ ByVal y As Long) As LongDeclare Function GetWindowRect Lib "user32" Alias "GetWindowRect" _ (ByVal hwnd As Long, lpRect As RECT) As Long'设定Mouse可移动的围是在某个control项之内Public Function toLockCursor(ByVal ctlHwnd As Long) As BooleanDim rect5 As RECTDim res As LongGetWindowRect ctlHwnd, rect5 '取得window的四个角rect5.Top = rect5.Toprect5.Left = rect5.Leftrect5.Bottom = rect5.Bottomrect5.Right = rect5.RightSetCursorPos (rect5.Top + rect5.Bottom) 2, (rect5.Left + rect5.Right) 2res = ClipCursor(rect5)If res = 1 Then toLockCursor = TrueElse toLockCursor = FalseEnd IfEnd Function'设定Mouse移动的围为个萤幕Public Sub toUnLockCursor()Dim rscreen As RECTrscreen.Top = 0rscreen.Left = 0rscreen.Right = Screen.Width Screen.TwipsPerPixelXrscreen.Bottom = Screen.Height Screen.TwipsPerPixelYClipCursor rscreenEnd Sub例如:设定Mouse只能在Form的范围Private Sub Command1.Click()Call toLockCursor(Me.hWnd)End SubPrivate Sub Command2.Click()Call toUnLockCursor()End Sub
设定Mouse 在某个固定范围
下面这个设定Mouse 在某个固定范围教程由图老师小编精心推荐选出,过程简单易学超容易上手,喜欢就要赶紧get起来哦!