Option Compare Database Option Explicit 'WindowのClassName取得 Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long 'DiskTopWindowのWindowハンドルを取得 Declare Function GetDesktopWindow Lib "user32" () As Long '指定の方法でWindowハンドルを取得 Const GW_CHILD = 5 'hWndが親WindowのときZオーダーのトップ位置の子Window Const GW_HWNDNEXT = 2 'hWndで指定したWindowの次のWindow Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long 'Windowのデータを取得 Const GWL_STYLE = -16 Const WS_VISIBLE = &H10000000 Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long 'WindowのCaption取得 Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long 'リストボックス AppListの1行ワーク Public Type wrkAppList strCaption As String strClass As String hwnd As Long End Type Const cMaxLen = 128 Private Function LsGetClassName(hwnd As Long) Dim lpClassName As String, intLen As Integer If hwnd = 0 Then Exit Function lpClassName = Space(cMaxLen) intLen = GetClassName(hwnd, lpClassName, cMaxLen) LsGetClassName = Left$(lpClassName, intLen) End Function Function LsGetCaption(hwnd As Long) Dim lpString As String, intLen As Integer If hwnd = 0 Then Exit Function lpString = Space(cMaxLen) intLen = GetWindowText(hwnd, lpString, cMaxLen) LsGetCaption = Left(lpString, intLen) End Function Function MakeAppList(wkApLst() As wrkAppList, ByVal bVisibleWin As Boolean) As Integer Dim hwnd As Long, strCaption As String, c As Integer, lngWindowLong As Long hwnd = GetDesktopWindow() hwnd = GetWindow(hwnd, GW_CHILD) Do Until hwnd = 0 strCaption = LsGetCaption(hwnd) If Len(strCaption) > 0 Then lngWindowLong = GetWindowLong(hwnd, GWL_STYLE) If bVisibleWin Imp (WS_VISIBLE And lngWindowLong) Then ReDim Preserve wkApLst(0 To c) wkApLst(c).strCaption = strCaption wkApLst(c).strClass = LsGetClassName(hwnd) wkApLst(c).hwnd = hwnd c = c + 1 End If End If hwnd = GetWindow(hwnd, GW_HWNDNEXT) Loop MakeAppList = c End Function