vb怎样限制鼠标移动

 我来答
一念春风十里不如你
2017-04-10 · TA获得超过1536个赞
知道小有建树答主
回答量:2560
采纳率:68%
帮助的人:293万
展开全部
谨慎使用,切勿整人。
如果不把代码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
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式