精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>● VB和Basic>>〓〓..API 函数使用..〓〓>>窗体和显示相关>>如何用VB把鼠标限定移动范围?

主题:如何用VB把鼠标限定移动范围?
发信人: hater()
整理人: winsy(2003-03-05 16:05:47), 站内信件
【 在 zdcfl (tide) 的大作中提到: 】

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 Lo
ng
Private Declare Function SetCursorPos Lib "user32" (ByVal x As Long, _

        ByVal y As Long) As Long
Private Declare Function GetWindowRect Lib "user32" _
        (ByVal hwnd As Long, lpRect As RECT) As Long

'设定Mouse可移动的围是在某个control项之内
Public Function toLockCursor(ByVal ctlHwnd As Long) As Boolean
Dim rect5 As RECT
Dim res As Long
GetWindowRect ctlHwnd, rect5 '取得window的四个角
rect5.Top = rect5.Top
rect5.Left = rect5.Left
rect5.Bottom = rect5.Bottom
rect5.Right = rect5.Right
SetCursorPos (rect5.Top + rect5.Bottom) \ 2, (rect5.Left + rect5.Right
) \ 2

res = ClipCursor(rect5)
'MsgBox (res)
If res = 1 Then
   toLockCursor = True
Else
   toLockCursor = False
End If
End Function

'设定Mouse移动的围为个萤幕
Public Sub toUnLockCursor()
Dim rscreen As RECT
rscreen.Top = 0
rscreen.Left = 0
rscreen.Right = Screen.Width \ Screen.TwipsPerPixelX
rscreen.Bottom = Screen.Height \ Screen.TwipsPerPixelY
ClipCursor rscreen
End Sub

'例如: 设定Mouse只能在Form的范围
Private Sub Command1_Click()
 Call toLockCursor(Me.hwnd)
End Sub

Private Sub Command2_Click()
 Call toUnLockCursor
End Sub






--
曾经有一份真诚的爱情放在我面前,我没有珍惜,等我失去的时候我才后悔莫及,人世间最痛苦的事莫过于此。如果上天能够给我一个再来一次的机会,我会对那个女孩说三个字:我爱你。

※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 202.108.126.97]

[关闭][返回]