| 
    
     |  | ▼亜矢 さん: 
 一応、上でつぶやいた力技コードです。
 はなはだ、ダサイコードだと思いますが・・・
 
 Option Explicit
 
 'トップレベルのウィンドウの抽出
 Private Declare Function EnumWindows Lib "USER32" _
 (ByVal lpEnumFunc As Long, ByVal lParam 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 GetClassName Lib "user32.dll" _
 Alias "GetClassNameA" _
 (ByVal hWnd As Long, _
 ByVal lpClassName As String, _
 ByVal nMaxCount As Long) As Long
 'スレッドIDとプロセスIDを取得する(665)
 Private Declare Function GetWindowThreadProcessId Lib "USER32" _
 (ByVal hWnd As Long, lpdwProcessId As Long) As Long
 '==========================================================================
 
 Dim myThread As Long
 Dim myCaption As String
 
 Sub Test()
 Dim hWnd As Long
 Dim rtn As Boolean
 
 hWnd = ThisWorkbook.Application.hWnd
 myThread = GetWindowThreadProcessId(hWnd, ByVal 0&)
 rtn = EnumWindows(AddressOf GetProc, 0&)
 MsgBox myCaption
 End Sub
 
 'コールバック
 Public Function GetProc(ByVal hWnd As Long, iParam As Long) As Boolean
 Dim myCap As String * 128
 Dim ret As Long
 Dim myBuff As String * 128
 Dim myClass As String
 Dim lngRtn As Long
 
 If GetWindowThreadProcessId(hWnd, ByVal 0&) = myThread Then
 myCap = ""
 ret = GetWindowText(hWnd, myCap, Len(myCap))
 lngRtn = GetClassName(hWnd, _
 myBuff, _
 Len(myBuff))
 myClass = Left(myBuff, lngRtn)
 If myClass = "ThunderDFrame" Then myCaption = myCap
 End If
 
 GetProc = True
 
 End Function
 
 |  |