PDA

Click to See Complete Forum and Search --> : I am a man who dresses as a woman...


V(ery) Basic
May 2nd, 2000, 03:11 AM
...just joking.

Is there a way to get all the files in the task bar and their hWnds? Or their names so I can use FindWindow.

Any help would be useful.

Thanks,

Me

Stevie-O
May 2nd, 2000, 11:21 PM
To enumerate all the top-level windows in the system, you need to call EnumWindows, and filter out the various properties to get the ones that are just in the taskbar.

It just so happens I have such a function for a similar purpose.



' Stick this in a module.

Private EnumWindowsArray() As Long, wsMask As Long, wsStyles As Long, ewaCount As Long

Public Enum WindowStyleConstants
WS_OVERLAPPED = &H0
WS_POPUP = &H80000000
WS_CHILD = &H40000000
WS_MINIMIZE = &H20000000
WS_VISIBLE = &H10000000
WS_DISABLED = &H8000000
WS_CLIPSIBLINGS = &H4000000
WS_CLIPCHILDREN = &H2000000
WS_MAXIMIZE = &H1000000
WS_CAPTION = &HC00000 '/* WS_BORDER | WS_DLGFRAME */
WS_BORDER = &H800000
WS_DLGFRAME = &H400000
WS_VSCROLL = &H200000
WS_HSCROLL = &H100000
WS_SYSMENU = &H80000
WS_THICKFRAME = &H40000
WS_GROUP = &H20000
WS_TABSTOP = &H10000

WS_MINIMIZEBOX = &H20000
WS_MAXIMIZEBOX = &H10000

WS_TILED = WS_OVERLAPPED
WS_ICONIC = WS_MINIMIZE
WS_SIZEBOX = WS_THICKFRAME

'/*
' * Common Window Styles
' */
WS_OVERLAPPEDWINDOW = WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX
WS_TILEDWINDOW = WS_OVERLAPPEDWINDOW
WS_POPUPWINDOW = WS_POPUP Or WS_BORDER Or WS_SYSMENU
WS_CHILDWINDOW = WS_CHILD
End Enum


' *************************************
' * CALLBACK FUNCTION *
' *************************************

Private Function EnumWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
' Debug.Print "(" & GetWindowLong(hWnd, GWL_STYLE) & " & " & wsMask & ") = " & (GetWindowLong(hWnd, GWL_STYLE) And WS_VISIBLE) & " vs " & wsStyles
If (GetWindowLong(hWnd, GWL_STYLE) And wsMask) = wsStyles Then
ReDim Preserve EnumWindowsArray(0 To ewaCount)
EnumWindowsArray(ewaCount) = hWnd
ewaCount = ewaCount + 1
End If
EnumWindowsProc = 1 ' to cont. enumeration
End Function

Public Function EnumerateWindows(ByRef hWndArray() As Long, Optional ByVal WinStyleMask As WindowStyleConstants = 0, Optional ByVal WinStyleVal As WindowStyleConstants = 0) As Long
ReDim EnumWindowsArray(0)
ewaCount = 0
wsMask = WinStyleMask
wsStyles = WinStyleVal
EnumWindows AddressOf EnumWindowsProc, 0
hWndArray = EnumWindowsArray
EnumerateWindows = ewaCount
End Function

' ************

' Then call it like this:

Private Sub Command1_Click()
Dim hWnds() As Long, wndCount As Long
wndCount = EnumerateWindows(hWnds, WS_CAPTION Or WS_VISIBLE, WS_CAPTION Or WS_VISIBLE)
End Sub

' The WS_CAPTION or WS_VISIBLE usually nails it on the styles.

Razzle
May 6th, 2000, 05:07 AM
To enumerate all running processes:



ReDim RProcesses(0)
hSnapShot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)

If hSnapShot = 0 Then Exit Sub

uProcess.dwSize = Len(uProcess)
r = ProcessFirst(hSnapShot, uProcess)
i = 1
Do While r
ReDim Preserve RProcesses(UBound(RProcesses) + 1)
RProcesses(i) = uProcess
Form1.List1.AddItem uProcess.szExeFile
i = i + 1
r = ProcessNext(hSnapShot, uProcess)

Loop

Call CloseHandle(hSnapShot)

End Sub