请问我以下枚举所有窗口的函数在那出问题了,怎么List2就是空的呢.究竟怎么回事啊?(所有的api函数已经申明过了)Sub FindAllApps()
Dim hwcurr As Long
Dim handleparent As Long
Dim intLen As Long
Dim strTitle As String
'列表清空
List2.Clear
'获得子窗口的父窗口句柄
handleparent = GetParent(Me.hwnd)
'获得第一个窗口的句柄
hwcurr = GetWindow(handleparent, GW_HWNDFIRST)
'循环,找出主窗口列表中所有的窗口
Do While hwcurr
If hwcurr <> handleparent And TaskWindow(hwcurr) Then
'获得该窗口的标题长度及标题
intLen = GetWindowTextLength(hwcurr) + 1
strTitle = Space$(intLen)
intLen = GetWindowText(hwcurr, strTitle, intLen)
If intLen > 0 Then
List2.AddItem strTitle
End If
End If
'获得下一个窗口的句柄
hwcurr = GetWindow(hwcurr, GW_HWNDNEXT)
Loop
End SubFunction TaskWindow(hwcurr As Long) As Long
Dim lngStyle As Long
'获取窗口风格,并判断是否符合要求
lngStyle = GetWindowLong(hwcurr, GWL_STYLE)
If (lngStyle And IsTask) = IsTask Then
TaskWindow = True
End If
End Function
Dim hwcurr As Long
Dim handleparent As Long
Dim intLen As Long
Dim strTitle As String
'列表清空
List2.Clear
'获得子窗口的父窗口句柄
handleparent = GetParent(Me.hwnd)
'获得第一个窗口的句柄
hwcurr = GetWindow(handleparent, GW_HWNDFIRST)
'循环,找出主窗口列表中所有的窗口
Do While hwcurr
If hwcurr <> handleparent And TaskWindow(hwcurr) Then
'获得该窗口的标题长度及标题
intLen = GetWindowTextLength(hwcurr) + 1
strTitle = Space$(intLen)
intLen = GetWindowText(hwcurr, strTitle, intLen)
If intLen > 0 Then
List2.AddItem strTitle
End If
End If
'获得下一个窗口的句柄
hwcurr = GetWindow(hwcurr, GW_HWNDNEXT)
Loop
End SubFunction TaskWindow(hwcurr As Long) As Long
Dim lngStyle As Long
'获取窗口风格,并判断是否符合要求
lngStyle = GetWindowLong(hwcurr, GWL_STYLE)
If (lngStyle And IsTask) = IsTask Then
TaskWindow = True
End If
End Function
do
Myhwnd = GetParent(子窗体句柄)
if myhwnd then handleparent = Myhwnd
Loop until Myhwnd=0
实际调试的时候handleparent不等于me.hwnd的,我看过的。 但是hwcurr = GetWindow(handleparent, GW_HWNDFIRST)这句得到的hwcurr倒是等于handleparent
handleparent = GetParent(Me.hwnd)获取的不是最外层的,建议使用FindWindow来获取最外层的窗口句柄handleparent,然后用hwcurr = GetWindow(handleparent, GW_CHILD )获取第一个子窗口。