vb将鼠标锁定在一个窗口范围内

搜索获得一个指定的窗口,然后将鼠标锁定在窗口的范围内。... 搜索获得一个指定的窗口,然后将鼠标锁定在窗口的范围内。 展开
 我来答
狄烁
2008-05-20 · TA获得超过185个赞
知道小有建树答主
回答量:133
采纳率:0%
帮助的人:0
展开全部
'画两个按钮,使用如下代码
Option Explicit

Private Type RECT
left As Long
top As Long
right As Long
bottom As Long
End Type
Private Type POINT
x As Long
y As Long
End Type
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Sub ClipCursor Lib "user32" (lpRect As Any)
Private Declare Sub GetClientRect Lib "user32" (ByVal hWnd As Long, lpRect As RECT)
Private Declare Sub ClientToScreen Lib "user32" (ByVal hWnd As Long, lpPoint As POINT)
Private Declare Sub OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long)
Private Sub Form_Load()
Command1.Caption = "限制"
Command2.Caption = "解除"
End Sub
Private Sub Command1_Click()
Dim client As RECT
Dim upperleft As POINT
Dim hWnd As Long
'查找标题为“form1”的窗口
hWnd = FindWindow(vbNullString, "Form1")
GetClientRect hWnd, client
upperleft.x = client.left
upperleft.y = client.top
ClientToScreen hWnd, upperleft
OffsetRect client, upperleft.x, upperleft.y
ClipCursor client
End Sub
Private Sub Command2_Click()
ClipCursor ByVal 0&
End Sub
Private Sub Form_Unload(Cancel As Integer)
ClipCursor ByVal 0&
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式