用循环就可以了,先来看一下findwindowex的说明:
【VB声明】
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
所以,你只要这样就可以了:
dim subhwnd as long
subhwnd=finwindowex(mhwnd,0,"窗口类名",vbnullstring)
do while subhwnd>0
subhwnd=finwindowex(mhwnd,subhwnd,"窗口类名",vbnullstring)
loop
VB声明
Declare Function EnumChildWindows Lib "user32" Alias "EnumChildWindows" (ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
说明
为指定的父窗口枚举子窗口
返回值
Long,非零表示成功,零表示失败
参数表
参数 类型及说明
hWndParent Long,欲枚举子窗口的父窗口的句柄
lpEnumFunc Long,为每个子窗口调用的函数的指针。用AddressOf运算符获得函数在一个标准模块中的地址
lParam Long,在枚举期间,传递给dwcbkd32.ocx定制控件之EnumWindows事件的值。这个值的含义是由程序员规定的。(原文:Value that is passed to the EnumWindows event of the dwcbkd32.ocx custom control during enumeration. The meaning of this value is defined by the programmer.)
注解
在vb4下要求dwcbkd32.ocx定制控件。子窗口下属的子窗口也可由这个函数枚举
Public Function WndEnumChildProc(ByVal hwnd As Long, ByVal lParam As ListView) As Long
Dim bRet As Long
Dim myStr As String * 50
bRet = GetClassName(hwnd, myStr, 50)
'if you want the text for only Edit class then use the if statement:
'If (Left(myStr, 4) = "Edit") Then
'lParam.Sorted = False
With lParam.ListItems
.Add.Text = Str(hwnd)
.Item(ICount).SubItems(1) = myStr
.Item(ICount).SubItems(2) = GetText(hwnd)
If SendMessage(hwnd, EM_GETPASSWORDCHAR, 0, 0) = 0 Then
.Item(ICount).SubItems(3) = "No"
Else
.Item(ICount).SubItems(3) = "Yes"
End If
End With
ICount = ICount + 1
'lParam.Sorted = True
'End If
WndEnumChildProc = 1
End Function
Function GetText(iHwnd As Long) As String
Dim Textlen As Long
Dim Text As String
Textlen = SendMessage(iHwnd, WM_GETTEXTLENGTH, 0, 0)
If Textlen = 0 Then
GetText = ">No text for this class<"
Exit Function
End If
Textlen = Textlen + 1
Text = Space(Textlen)
Textlen = SendMessage(iHwnd, WM_GETTEXT, Textlen, ByVal Text)
'The 'ByVal' keyword is necessary or you'll get an invalid page fault
'and the app crashes, and takes VB with it.
GetText = Left(Text, Textlen)
End Function
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public Function Cname(ByVal ChWnd As Long) As String
Cname = Space(85)
GetClassName ChWnd, Cname, Len(Cname)
End Function
====================
用到的API自己加吧!