Results 1 to 2 of 2

Thread: Determine all open windows

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 1999
    Location
    Singapore
    Posts
    116

    Post

    How do i retrieve the handles of all open windows??? Code samples appreciated.

    ------------------
    YC Sim
    Teenage Programmer
    UIN 37903254


  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Try something like this:

    In a Module..
    Code:
    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..
    Code:
    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
    [email protected]
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width