I am using a command button to populate a list of open windows on the desktop. The code works very well.
The problem is that I get a bunch of junk like IME, system tray, etc. I just want the names of the windows that appear on the taskbar.
Here is my code:
Sub LoadTaskList()
Dim Currwnd As Long
Dim Length As Long
Dim TaskName As String
Dim Parent As Long
Dim i As Integer
Dim hwnd As Long
Dim hwndStart As Long
Dim sClass As String
For i = List1.ListCount - 1 To 0 Step -1
Me.List1.RemoveItem i
Next
hwndStart = GetDesktopWindow()
Currwnd = GetWindow(hwndStart, GW_CHILD)
While Currwnd <> 0
'Parent = GetParent(hwndStart)
Length = GetWindowTextLength(Currwnd)
TaskName = Space$(Length + 1)
Length = GetWindowText(Currwnd, TaskName, Length + 1)
TaskName = Left$(TaskName, Len(TaskName) - 1)
If Length > 0 Then
If TaskName <> Me.Caption Then
Me.List1.AddItem TaskName
End If
End If
Currwnd = GetWindow(Currwnd, GW_HWNDNEXT)
DoEvents
Wend
End Sub
The problem is that I get a bunch of junk like IME, system tray, etc. I just want the names of the windows that appear on the taskbar.
Here is my code:
Sub LoadTaskList()
Dim Currwnd As Long
Dim Length As Long
Dim TaskName As String
Dim Parent As Long
Dim i As Integer
Dim hwnd As Long
Dim hwndStart As Long
Dim sClass As String
For i = List1.ListCount - 1 To 0 Step -1
Me.List1.RemoveItem i
Next
hwndStart = GetDesktopWindow()
Currwnd = GetWindow(hwndStart, GW_CHILD)
While Currwnd <> 0
'Parent = GetParent(hwndStart)
Length = GetWindowTextLength(Currwnd)
TaskName = Space$(Length + 1)
Length = GetWindowText(Currwnd, TaskName, Length + 1)
TaskName = Left$(TaskName, Len(TaskName) - 1)
If Length > 0 Then
If TaskName <> Me.Caption Then
Me.List1.AddItem TaskName
End If
End If
Currwnd = GetWindow(Currwnd, GW_HWNDNEXT)
DoEvents
Wend
End Sub