| 
    
     |  | ▼UO3 さん: >▼亜矢 さん:
 >
 >結構ややこしいけど。
 >ネットから拾い集めて書いたコードです。
 >Sheet1 の A列にウィンドウハンドル、B列にクラスコード、C列のキャプションを列挙。
 >
 >Option Explicit
 >
 >Private Declare Function GetWindow Lib "USER32" _
 >  (ByVal hWnd As Long, ByVal wCmd As Long) As Long
 >Private Declare Function GetWindowText Lib "USER32" _
 >  Alias "GetWindowTextA" (ByVal hWnd As Long, _
 >  ByVal lpString As String, ByVal cch As Long) As Long
 >Private Declare Function IsWindowVisible Lib "USER32" _
 >  (ByVal hWnd As Long) As Long
 >Private Declare Function GetClassName Lib "USER32" _
 >  Alias "GetClassNameA" (ByVal hWnd As Long, _
 >  ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
 >
 >Private Const GW_HWNDNEXT = 2  '次のウィンドウハンドル取得
 >Private Const GW_HWNDFIRST = 0 'トップ位置ウィンドウハンドル取得
 >Private Const GW_OWNER = 4   'オーナーウィンドウハンドル取得
 >
 >Sub Sample()
 >  Dim myhWnd As Long
 >  Dim hWind As Long
 >  Dim rtn As Long
 >  Dim myClass As String * 128
 >  Dim myCaption As String * 128
 >  Dim i As Long
 >
 >  i = 1
 >  Sheets("Sheet1").Cells.ClearContents
 >
 >  myhWnd = Application.hWnd  '自分自身のハンドル
 >
 >  hWind = GetWindow(myhWnd, GW_HWNDFIRST)
 >  Do Until hWind = 0
 >    If IsWindowVisible(hWind) And GetWindow(hWind, GW_OWNER) = 0 Then 'タスクバーにあるもの
 >      myClass = ""
 >      Call GetClassName(hWind, myClass, Len(myClass))
 >      If Left$(myClass, 7) <> "Progman" Then
 >        myCaption = ""
 >        rtn = GetWindowText(hWind, myCaption, Len(myCaption))
 >        If rtn Then   'キャプションが "" でない場合
 >          With Sheets("Sheet1")
 >            .Cells(i, "A").Value = hWind   'ハンドル
 >            .Cells(i, "B").Value = myClass  'クラス名
 >            .Cells(i, "C").Value = myCaption  'キャプション
 >            i = i + 1
 >          End With
 >        End If
 >      End If
 >    End If
 >    hWind = GetWindow(hWind, GW_HWNDNEXT)
 >  Loop
 >
 >End Sub
 先日上記のコードをいただき一つの目的が達成しましたが、印刷プレビューとか他の子の取得が出来ないと思われますので、子のCaptionが取得できるような方法を
 教えて頂きたいと思います。
 よろしくお願いします。
 
 
 |  |