vb中控制鼠标在程序的范围内
3个回答
展开全部
Public Declare Function ClipCursor Lib "user32 " (ByRef lpRect As rect) As Integer
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
If keyData = (Keys.Alt Or Keys.F4) Then
Return True
Else
Return MyBase.ProcessCmdKey(msg, keyData)
End If
End Function
Public Structure rect
Dim left As Integer
Dim top As Integer
Dim right As Integer
Dim bottom As Integer
End Structure
mouse.left = 0
mouse.top = 0
mouse.right = Screen.PrimaryScreen.Bounds.Right
mouse.bottom = Screen.PrimaryScreen.Bounds.Bottom
ClipCursor(mouse)
想要完整版的再联系我,我以前做过这方面的程序,很简单,就是要熟悉API。
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
If keyData = (Keys.Alt Or Keys.F4) Then
Return True
Else
Return MyBase.ProcessCmdKey(msg, keyData)
End If
End Function
Public Structure rect
Dim left As Integer
Dim top As Integer
Dim right As Integer
Dim bottom As Integer
End Structure
mouse.left = 0
mouse.top = 0
mouse.right = Screen.PrimaryScreen.Bounds.Right
mouse.bottom = Screen.PrimaryScreen.Bounds.Bottom
ClipCursor(mouse)
想要完整版的再联系我,我以前做过这方面的程序,很简单,就是要熟悉API。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
具体代码已经找不到了 ,你可以搜索下API函数ClipCursor用法,基本上就是这个函数
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
=================
Option Explicit
Private Const lBorder As Long = 4 '边框大小,经测试,至少为4才能不出现用户点击窗体边缘导致失效。
Dim R As RECT
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 RECT) As Long
'lpRect-鼠标光标限制到的矩形
Private Declare Function ClipCursorByNum Lib "user32" Alias "ClipCursor" (lpRect As Long) As Long
'lpRect-传0,取消鼠标光标限制
Private Declare Function SetRect Lib "user32" (lpRect As RECT, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Sub Form_Load() '窗体载入后,鼠标只能在窗体范围内移动
SetRect R, Left / Screen.TwipsPerPixelX + lBorder, Top / Screen.TwipsPerPixelY + lBorder, (Left + Width) / Screen.TwipsPerPixelX - lBorder, (Top + Height) / Screen.TwipsPerPixelY - lBorder
ClipCursor R
End Sub
Private Sub Form_Unload(Cancel As Integer) '窗体退出时,取消鼠标光标限制范围
ClipCursorByNum 0
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询