ycsim
Nov 11th, 1999, 06:47 AM
How do i retrieve the handles of all open windows??? Code samples appreciated.
------------------
YC Sim
Teenage Programmer
UIN 37903254
Aaron Young
Nov 11th, 1999, 09:55 AM
Try something like this:
In a Module..
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public sWnds() As String
Public Function EnumProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
Dim sString As String * 255
Call GetWindowText(hwnd, ByVal sString, 255)
If Left(sString, 1) <> Chr(0) Then
sWnds(UBound(sWnds)) = Left(sString, InStr(sString, Chr(0)) - 1)
ReDim Preserve sWnds(UBound(sWnds) + 1)
End If
EnumProc = hwnd
End Function
In the Form, with a Listbox and Command Button..
Private Sub Command1_Click()
Dim iWnd As Integer
ReDim sWnds(0)
Call EnumWindows(AddressOf EnumProc, 0&)
List1.Clear
For iWnd = 0 To UBound(sWnds) - 1
List1.AddItem sWnds(iWnd)
Next
End Sub
------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net