ウインドウを列挙する
ウインドウを列挙するサンプルです。
サンプルの実行画面

APIの宣言
[EnumWindow.bas]
'EnumWindows=>すべてのウインドウを列挙する '<引数> 'lpEnumFunc: コールバックプロシージャ 'lPalam: 常に0 '@戻り値@ ' 正常終了 -1 Public Declare Function EnumWindows Lib "USER32" (ByVal lpEnumFunc As Long, lPalam As Long) As Long 'GetWindowText=>ウインドウのタイトルバーの文字列を取得する '<引数> 'hWnd: ウインドウのハンドル 'lpString: 文字列が格納される変数 'cch: 文字列の文字数 '@戻り値@ ' 文字列のバイト数 Public Declare Function GetWindowText Lib "USER32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long 'IsWindowVisible=>ウインドウが表示されているか判別する '<引数> 'hWnd: ウインドウのハンドル '<戻り値> ' 表示されている場合 1 Public Declare Function IsWindowVisible Lib "USER32" (ByVal hWnd As Long) As Long '--------------------------------------- '■関数名 Rekkyo '■用途 ウインドウを列挙する '■引数 Hnadle:ウインドウのハンドル '--------------------------------------- Public Function Rekkyo(ByVal Handle As Long) As Boolean Dim Ret1 As Long Dim Leng As Long Dim Name As String 'Dim Ret2 as long 'バッファ確保 Name = String(255, Chr(0)) Leng = Len(Name) '名前を取得する Ret1 = GetWindowText(Handle, Name, Leng) '表示されているか判別 'Ret2 = IsWindowVisible(Handle) 'If Ret2 = 1 Then If Ret1 <> 0 Then Form1.List1.AddItem Name End If 'End If Rekkyo = True End Function
APIの呼び出し
[EnumWindow.frm]
Private Sub Command1_Click() Dim Ret As Long Ret = EnumWindows(AddressOf Rekkyo, 0) End Sub
ソースコード一式のダウンロード
vbapi_enumwindow.zip 1.93 KB (1,982 バイト)
このサンプルの動作環境について
このサンプルは 「Windows98」及び「Microsoft Visual Basic 5.0 Professional Edition」で確認しております。環境が異なる場合は正常に動作しない場合もございますのでご了承下さい。
スポンサーリンク
関連記事
前の記事: | 子ウインドウを列挙する |
次の記事: | ウインドウのタイトルバーを点滅させる |
公開日:2015年03月06日
記事NO:00417