ウィンドウのキャプションを取得
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