VB挂机锁问题

来源:百度知道 编辑:UC知道 时间:2024/06/17 11:44:58
请问如何将鼠标停留在From1窗体里面,text2.text密码不正确的话,鼠标一直在From1窗体里面

①鼠标位置设置函数,下述参数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所造成的鼠标移动