Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access 2007 - Return Desktop Window names into listbox

Status
Not open for further replies.

1chicken

Programmer
Jun 11, 2003
20
0
0
US
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

 
You probably need to use EnumChildWindows.

There's some sample code here
 
I have tried enumChildWindows and it didn't return what I was expecting either. I just got it to work with this code.
Thanks so much for your response!

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)
x = GetWindowLong(Currwnd, GWL_STYLE)
y = IsWindowVisible(Currwnd)
Length = GetWindowTextLength(Currwnd)
TaskName = Space$(Length + 1)
Length = GetWindowText(Currwnd, TaskName, Length + 1)
TaskName = Left$(TaskName, Len(TaskName) - 1)

If Length > 0 And y = 1 And TaskName <> "Program Manager" Then
If TaskName <> Me.Caption Then
Me.List1.AddItem Currwnd & ", " & TaskName
End If
End If
Currwnd = GetWindow(Currwnd, GW_HWNDNEXT)
DoEvents
Wend
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top