如何得知Mouse已离开某物件(二)
来源:cww   叁考 王国荣先生的作法
上一回使用mouse Hook的方式来Check Mouse是否已离开某物件,详见
如何得知Mouse已离开某物件(Mouse Hook)但使用这个方法太麻
烦了,改用SetCapture 来使Mouse的Message转到某个Window之上,如此,不管Mouse移动
於何处,都会将Mouse Input Message传给某个Window,最後使用ReleaseCapture来取消这
个作用。

Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long

Private Sub Command1_Click()
 Command1.Tag = ""
End Sub

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Command1.Tag = "In" Then
	If X < 0 Or Y < 0 Or X > Command1.Width Or Y > Command1.Height Then
	    Command1.Tag = ""
	    ReleaseCapture
	    Command1.Caption = "离开"
	End If
    Else
	Command1.Tag = "In"
	SetCapture Command1.hwnd
	Command1.Caption = "进入"
    End If

End Sub