vb如何编写挂机锁
发布网友
发布时间:2024-09-30 06:31
我来回答
共1个回答
热心网友
时间:2024-12-02 13:56
①鼠标位置设置函数,下述参数a_RestrictObject是*对象,可以是窗体,也可以是窗体上的任意控件。
Public Sub SetRestrict(ByRef a_RestrictObject As Object)
Dim r As RECT
On Error Resume Next
GetWindowRect (a_RestrictObject.hwnd), r
If Err.Number = 0 Then
Call ClipCursor(lpRect)
End If
End Sub
②鼠标位置解除函数,即接触对鼠标位置的*
Public Sub RemoveRestrict()
Dim lResult As Long
Dim RT_ScreenArea As RECT
With RT_ScreenArea
.Top = 0
.Left = 0
.Bottom = Screen.Height \ Screen.TwipsPerPixelX
.Right = Screen.Width \ Screen.TwipsPerPixelY
End With
lResult = ClipCursor(RT_ScreenArea)
End Sub
③函数1,2所用到的API。
Public Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Public Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long
④注意点,上述函数1,不要随意使用,使用后,要用函数2解除,如不接触,
函数1所造成的鼠标移动范围可触及到系统Windows。所以函数1,2要共同使用。