This code will fill a listbox with the caption of each open "window". This includes all programs in the task bar and any windows within those programs

In a Module
VB Code:
  1. Private Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
  2. Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  3. Private Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
  4.  
  5. Private Const WM_GETTEXT = &HD
  6.  
  7. Private aCaptions() As String
  8. Private lCount As Long
  9.  
  10. Public Function GetAllCaptions() As Variant
  11.  
  12. lCount = 0
  13.  
  14. Call EnumWindows(AddressOf EnumWindowsProc, 0&)
  15.  
  16. If lCount Then ReDim Preserve aCaptions(lCount - 1)
  17.     GetAllCaptions = IIf(lCount, aCaptions, Array())
  18. End Function
  19.  
  20. Private Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
  21.  
  22. Dim sBuffer As String * 260
  23.  
  24. If IsWindowVisible(hwnd) Then
  25.     ReDim Preserve aCaptions(lCount)
  26.     aCaptions(lCount) = Left(sBuffer, SendMessage(hwnd, WM_GETTEXT, 260, ByVal sBuffer))
  27.     If Len(Trim(aCaptions(lCount))) Then lCount = lCount + 1
  28. End If
  29.  
  30. EnumWindowsProc = hwnd
  31.  
  32. End Function

In a form (with a List1 and a Command1)
VB Code:
  1. Private Sub Command1_Click()
  2.  
  3. Dim vCaps As Variant
  4. Dim lIndex As Long
  5.  
  6. vCaps = GetAllCaptions()
  7. List1.Clear
  8.  
  9. For lIndex = 0 To UBound(vCaps)
  10.     List1.AddItem vCaps(lIndex)
  11. Next
  12.  
  13. End Sub