Results 1 to 2 of 2

Thread: Getting a list of running windows?

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 1999
    Location
    Singapore
    Posts
    32

    Post

    Hi,
    How can I get a name list of windows running on a system?
    Thanks.

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

    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
    aarony@redwingsoftware.com
    adyoung@win.bright.net

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