求vb锁定鼠标代码!

要高手原创的,网上那种我试过,不成!简洁点最好!... 要高手原创的,网上那种我试过,不成!简洁点最好! 展开
 我来答
290996449
2007-10-10 · 超过31用户采纳过TA的回答
知道答主
回答量:80
采纳率:0%
帮助的人:0
展开全部
如果不把代码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
善海木1e
2007-10-10 · 超过52用户采纳过TA的回答
知道答主
回答量:244
采纳率:0%
帮助的人:198万
展开全部
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long

Private Sub Command1_Click()
Dim r As RECT

r.Left = 0
r.Top = 0
r.Right = 600
r.Bottom = 400
ClipCursor r '这4个限定范围自己改
End Sub

Private Sub Command2_Click()
ClipCursor ByVal 0& '取消限制区域
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
VB妮可
2007-10-10 · TA获得超过3333个赞
知道大有可为答主
回答量:2574
采纳率:0%
帮助的人:0
展开全部
需要补充吗?

只是程序范围内锁定,还是就算关了程序,还继续锁定? 需要同时锁定键盘吗?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式