マウスホーバーとマウスリーブ(U)          <TOP>


マウスホーバー(コントロール上にマウスがある状態)と、マウスリーブ(マウスがコントロール上から離れた状態)のテスト

GetCapture マウス入力を受け持っているハンドルを取得

SetCapture 指定のウィンドウにマウスキャプチャを設定

ReleaseCapture マウスのキャプチャを解放

 

 

'================================================================
'= マウスホーバーとマウスリーブ(U)
'=    (SetCapture2.bas)
'================================================================
#include "Windows.bi"

' マウス入力を受け持っているハンドルを取得
Declare Function Api_GetCapture& Lib "user32" Alias "GetCapture" ()

' 指定のウィンドウにマウスキャプチャを設定
Declare Function Api_SetCapture& Lib "user32" Alias "SetCapture" (ByVal hWnd&)

' マウスのキャプチャを解放
Declare Function Api_ReleaseCapture& Lib "user32" Alias "ReleaseCapture" ()

Var Shared Picture1 As Object

Picture1.Attach GetDlgItem("Picture1")

'================================================================
'=
'================================================================
Declare Sub Picture1_MouseMove edecl (ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Sub Picture1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    Var Ret As Long

    If Api_GetCapture() = Picture1.GethWnd Then
        If (X < 0) Or (X > Picture1.GetWidth) Or (Y < 0) Or (Y > Picture1.GetHeight) Then
            Ret = Api_ReleaseCapture
            Picture1.SetBackColor RGB(255, 255, 255)
            Picture1.Cls
        End If
    Else
        Picture1.SetBackColor RGB(255, 255, 0)
        Ret = Api_SetCapture(Picture1.GethWnd)
        Picture1.Cls
    End If
End Sub

'================================================================
'=
'================================================================
Declare Sub Picture1_MouseUp edecl (ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Sub Picture1_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
	Var Ret As Long

    If Api_GetCapture() <> Picture1.GethWnd Then Ret = Api_SetCapture(Picture1.GethWnd)
End Sub

'================================================================
'=
'================================================================
While 1
    WaitEvent
Wend
Stop
End