Option Explicit

'
' Text1.MultiLine = True(複数行)
'      .ScrollBar = 3  (両方)  にしておくこと
'
Const ME_TITLE = "リストビューの文字列取得"

Private Sub Form_Load()
    
    Me.Caption = ME_TITLE
    Command1.Caption = "開始"
    Label1 = ""
    Text1 = ""
    
    SetWindowPos hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE '最前面に表示

End Sub


Private Sub Command1_Click()

    Dim LoopSw As Boolean
    Dim Rc As Long

    Dim hWndPoint As Long   'ポイント位置のウィンドウハンドル
    Dim hWndOld As Long     '過去のウィンドウハンドル
    Dim Pos As POINTAPI     'マウスポインタ座標
    Dim strClassName As String  'クラス名
    
    Dim lngRc As Long       'API返却値
    
    Command1.Enabled = False    'コマンドボタンを無効
    Me.Caption = "ESCで停止"
    
    GetAsyncKeyState (VK_ESCAPE)   'ダミー
    LoopSw = True
    Do
        lngRc = GetCursorPos(Pos)                   'マウスポインタ位置取得
        hWndPoint = WindowFromPoint(Pos.X, Pos.Y)   'ポインタ位置のウィンドウハンドル
        If hWndPoint <> hWndOld Then    'ウィンドウハンドルが変化?
            hWndOld = hWndPoint         'ウィンドウハンドル保存
            strClassName = MyGetClassName(hWndPoint)  'クラス名
            Label1.Caption = strClassName
            If InStr(strClassName, WC_LISTVIEW) > 0 Then
                Text1 = MyGetListViewItem(hWndPoint)
            Else
                Text1 = ""
            End If
        End If
        
        Sleep 10    '10ミリ秒待ち
        DoEvents
        
        Rc = GetAsyncKeyState(VK_ESCAPE) 'ESCキーが押されたか?
        If (Rc And 1) <> 0 Then LoopSw = False '押されている→ループオフ
        
    Loop While LoopSw
    
    Command1.Enabled = True     'コマンドボタンを有効
    Me.Caption = ME_TITLE

End Sub


Private Sub Form_Resize()
'
' フォームサイズ変更時の処理
'
    On Error Resume Next
    With Text1
        .Width = Me.ScaleWidth - .Left
        .Height = Me.ScaleHeight - .Top
    End With
    On Error GoTo 0

End Sub


Private Sub Form_Unload(Cancel As Integer)
    End
End Sub