# Re: Re; Splash Window

Posted by Honey on November 14, 1998 at 12:57:43:

In Reply to: Re; Splash Window posted by David Wong on November 14, 1998 at 10:59:20:

可以使用API使滑鼠游标局限于表单中
宣告方式如下
Private Declare Function ClientToScreen Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function ClipCursor Lib "user32" (lpRect As RECT) As Long
若于模组中使用 得去掉Private

另外还得宣告一些型态
Private Type POINTAPI
X As Long
Y As Long
End Type

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
若于模组中使用 也得去掉Private

之后提供你一个SUB
Public Sub ClipTo(ToCtl As Object)

On Error Resume Next

Dim tmpRect As RECT
Dim pt As POINTAPI

With ToCtl

If TypeOf ToCtl Is Form Then
tmpRect.Left = (.Left \ Screen.TwipsPerPixelX)
tmpRect.Top = (.Top \ Screen.TwipsPerPixelY)
tmpRect.Right = (.Left + .Width) \ Screen.TwipsPerPixelX
tmpRect.Bottom = (.Top + .Height) \ Screen.TwipsPerPixelY
ElseIf TypeOf ToCtl Is Screen Then
tmpRect.Left = 0
tmpRect.Top = 0
tmpRect.Right = (.Width \ Screen.TwipsPerPixelX)
tmpRect.Bottom = (.Height \ Screen.TwipsPerPixelY)
Else
pt.X = 0
pt.Y = 0
Call ClientToScreen(.hWnd, pt)
tmpRect.Left = pt.X
tmpRect.Top = pt.Y
pt.X = .Width
pt.Y = .Height
Call ClientToScreen(.hWnd, pt)
tmpRect.Bottom = pt.Y
tmpRect.Right = pt.X
End If
Call ClipCursor(tmpRect)

End With

End Sub

之后 只要在FORM_LOAD() 中加入以下程式码
ClipTo Me
Me.Moveable = False
就可以限制滑鼠游标
另外 可别忘了在Form_Unload( ...)中加入
ClipTo Screen
否则 程式结束时 滑鼠还是会局限在那个范围喔

另外 如果表单移动过后 滑鼠便不受局限
所以我用Me.Moveable = False
使得表单不能移动
若你想让表单可移动 可去掉Me.Moveable = False
另外在Form_MouseMove()
加入ClipTo Me
若你不想将程序放入message window
也可以稍作修改 将Me改成message window的NAME

Follow Ups:

- Re; 十分好的方法 David Wong 22:26:33 11/17/98 (0)