主题:关于查找桌面所有窗口的标题
使用下面的过程在运行的时候总是不行,弹出窗口“没有发现可活动的窗口”
Sub FindTitle()
'查找桌面上的所有窗口标题
Dim currwnd As Long, i As Integer, a As Integer, b As Integer, s As String
Dim Length As Long, listitem As String
List2.Clear
currwnd = GetWindow(hwnd, GW_HWNDFIRST)
While currwnd <> 0
Length = GetWindowTextLength(currwnd)
listitem = Space$(Length + 1)
Length = GetWindowText(currwnd, listitem, Length + 1)
If Length > 0 Then
List2.AddItem listitem$
End If
currwnd = GetWindow(currwnd, GW_HWNDNEXT)
If List2.ListCount > 0 Then
List2.Text = List2.List(0)
List2.ListIndex = 0
Else
MsgBox "没有发现可活动的窗口", 16
Exit Sub
End If
Wend
End Sub
是不是因为运行的时候那个窗口是VB的子窗口?但是把
currwnd = GetWindow(hwnd, GW_HWNDFIRST)
变成
currwnd = GetWindow(hwnd, GW_OWNER)
currwnd = GetWindow(currwnd, GW_HWNDFIRST)
仍然一样。
Sub FindTitle()
'查找桌面上的所有窗口标题
Dim currwnd As Long, i As Integer, a As Integer, b As Integer, s As String
Dim Length As Long, listitem As String
List2.Clear
currwnd = GetWindow(hwnd, GW_HWNDFIRST)
While currwnd <> 0
Length = GetWindowTextLength(currwnd)
listitem = Space$(Length + 1)
Length = GetWindowText(currwnd, listitem, Length + 1)
If Length > 0 Then
List2.AddItem listitem$
End If
currwnd = GetWindow(currwnd, GW_HWNDNEXT)
If List2.ListCount > 0 Then
List2.Text = List2.List(0)
List2.ListIndex = 0
Else
MsgBox "没有发现可活动的窗口", 16
Exit Sub
End If
Wend
End Sub
是不是因为运行的时候那个窗口是VB的子窗口?但是把
currwnd = GetWindow(hwnd, GW_HWNDFIRST)
变成
currwnd = GetWindow(hwnd, GW_OWNER)
currwnd = GetWindow(currwnd, GW_HWNDFIRST)
仍然一样。