GetWindowText

機能
ウィンドウのキャプションを取得
Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" _
(ByVal hWnd As Long, ByVal lpString As String, ByVal nMaxCount As Long) As Long
Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" _
(ByVal hWnd As Integer, ByVal lpString As String, ByVal nMaxCount As Integer) As Integer

int GetWindowText(
HWND hWnd,
LPTSTR lpString,
int nMaxCount
);
引数
hWnd

ウィンドウのハンドル
lpString
(戻り値)テキストを受け取るるバッファ
nMaxCount
バッファのバイト数
戻り値
正常終了のとき  テキストのバイト数
エラーのとき  0
備考
ダウンロード(GetWindowText.lzh 1.61KB)

Private Sub Timer1_Timer()
Dim Pos As PointApi, hWnd As Long
Dim Temp As String, cch As Long

'マウスの位置を取得
Call GetCursorPos(Pos)

'ウィンドウのハンドルを取得
hWnd = WindowFromPoint(Pos.X, Pos.Y)

cch = GetWindowTextLength(hWnd)

cch = cch * 2
'バッファの作成
Temp = String(cch, Chr(0))

'ウィンドウのキャプション取得
Call GetWindowText(hWnd, Temp, Len(Temp))

Me.Text1.Text = MidB(Temp, 1, cch)
End Sub