vb怎样限制鼠标移动
展开全部
谨慎使用,切勿整人。
如果不把代码timer中的话,按下徽标键+D的话可以简单地取消区域限制。
Option Explicit
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Sub Form_DblClick()
End
End Sub
Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 500
End Sub
Private Sub Form_Unload(Cancel As Integer)
Cancel = 1
End Sub
'限制鼠标在当前窗体的区域,而且使当前的窗体始终在最最前面
Private Sub Timer1_Timer()
Dim ding As RECT
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 3
GetWindowRect Me.hwnd, ding
ClipCursor ding
End Sub
'限制鼠标在当前窗体的某个点上,这时可以把Timer1.Interval改小点。
Private Sub Timer1_Timer()
Dim m As Long, n As Long
m = 500
n = 500
SetCursorPos m, n
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 3
End Sub
如果不把代码timer中的话,按下徽标键+D的话可以简单地取消区域限制。
Option Explicit
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Sub Form_DblClick()
End
End Sub
Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 500
End Sub
Private Sub Form_Unload(Cancel As Integer)
Cancel = 1
End Sub
'限制鼠标在当前窗体的区域,而且使当前的窗体始终在最最前面
Private Sub Timer1_Timer()
Dim ding As RECT
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 3
GetWindowRect Me.hwnd, ding
ClipCursor ding
End Sub
'限制鼠标在当前窗体的某个点上,这时可以把Timer1.Interval改小点。
Private Sub Timer1_Timer()
Dim m As Long, n As Long
m = 500
n = 500
SetCursorPos m, n
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 3
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询