コールバック関数を使用してウィンドウハンドルを取得し、そのハンドルを使用して、キャプション、Top,Left.Bottom,Rightを出力しています。
Private SubForm_Load()
CallEnumWindows(AddressOfEnumWndProc, 0)
End Sub
'----------------------------------------------------------
' Module
'----------------------------------------------------------
Public Declare FunctionEnumWindowsLib"user32" (ByVallpEnumFuncAs Long,ByVallParamAs Long) AsLong
Public Declare FunctionIsWindowVisibleLib"user32" (ByValhWndAs Long)As Long
Public Declare FunctionGetClassNameLib"user32"Alias"GetClassNameA" (ByValhWndAs Long,ByVallpClassName AsString,ByValnMaxCountAs Long)As Long
Public Declare FunctionGetWindowPlacementLib"user32" (ByValhWndAs Long, lpwndplAsWINDOWPLACEMENT)As Long
Public Declare FunctionGetWindowTextLib"user32"Alias"GetWindowTextA" (ByValhWndAs Long,ByVallpStringAs String,ByValcchAs Long)As Long
Public Declare FunctionGetWindowLib"user32" (ByValhWndAs Long,ByValwCmdAs Long)As Long
'GetWindowで使用する定数
Public ConstGW_OWNER = 4
'GetWindowPlacementで使用する構造体
Public TypePOINTAPI
xAs Long
yAs Long
End Type
Public TypeRECT
LeftAs Long
TopAs Long
RightAs Long
BottomAs Long
End Type
Public TypeWINDOWPLACEMENT
LengthAs Long
flagsAs Long
showCmdAs Long
ptMinPositionAsPOINTAPI
ptMaxPositionAsPOINTAPI
rcNormalPositionAsRECT
End Type
'コールバック関数
Public FunctionEnumWndProc(ByValhWndAs Long, lParamAs Long)As Boolean
DimstrWindowNameAs String* 128
DimstrClassNameAs String* 128
DimWPLAsWINDOWPLACEMENT
DimlngRetAsLong
strWindowName = ""
strClassName = ""
lngRet = GetWindowText(hWnd, strWindowName, Len(strWindowName))
CallGetClassName(hWnd, strClassName, Len(strClassName))
'EnumWindowsでは不可視のウィンドウ(IME等)も列挙されてしまうため、抽出します。
IfIsWindowVisible(hWnd)Then'可視状態か
IfGetWindow(hWnd, GW_OWNER) = 0Then'オーナーフォームか
IflngRet <> 0Then'キャプションを持っているか
IfLeft(strClassName, 7) <> "Progman"Then'シェルでないか
WPL.Length = Len(WPL)
CallGetWindowPlacement(hWnd, WPL)
Debug.Print"----------------------------------"
Debug.Print"hWnd = " & hWnd
Debug.Print"Window Name = " & strWindowName
Debug.Print"Class Name = " & strClassName
Debug.Print"Left = " & WPL.rcNormalPosition.Left
Debug.Print"Top = " & WPL.rcNormalPosition.Top
Debug.Print"Right = " & WPL.rcNormalPosition.Right
Debug.Print"Bottm = " & WPL.rcNormalPosition.Bottom
End If
End If
End If
End If
EnumWndProc =True
End Function
DownLoad vbtips078.lzh 2KB (VB6.0)