Results 1 to 6 of 6

Thread: Open Windows

  1. #1
    Guest
    Hi.

    Can anyone tell me how can i retreave the list of opened windows.Ex: when we press Crtl+Alt+Del we have that list, how can i get it on a ListBox control.

    numibesi

  2. #2
    Addicted Member
    Join Date
    Oct 1999
    Location
    chicago (hope)
    Posts
    146
    copy this to a module!

    then call the getVisibleWnd function.
    REMEMBER TO CHANGE THE main.list1 TO YOUR LISTBOX.....
    Code:
    Function getVisibleWnd()
    EnumWindows AddressOf xEnumWindowsProcVisible, 0
    End Function
    
    Public Static Function xEnumWindowsProcVisible(ByVal hwnd As Long, ByVal lParam As Long) As Long
      Dim slength As Long, Buffer As String  ' title bar text length and buffer
      Dim retval As Long  ' return value
    '  Static WndLst As String
      slength = GetWindowTextLength(hwnd) + 1  ' get length of title bar text
      If slength > 1 Then  ' if return value refers to non-empty string
        Buffer = Space(slength)  ' make room in the buffer
        retval = GetWindowText(hwnd, Buffer, slength)  ' get title bar text
      If IsWindowVisible(hwnd) = 1 And IsWindow(hwnd) Then main.List1.AddItem Buffer
      End If
      xEnumWindowsProcVisible = 1  ' return value of 1 means continue enumeration
    End Function

  3. #3
    Guest
    There is a program that will list all the apps and give you a choice to close them.

    App List and Kill

  4. #4
    Guest

    Unhappy Nop

    The first code doesn´t work, and the program that is on that link gives me the current running programs not the active windows.

  5. #5
    Guest
    This code is from HeSaidJoe, I think it's what your looking for.

    Code:
    Option Explicit
    
    Private Declare Function GetWindow Lib "user32" _
    (ByVal hwnd As Long, ByVal wCmd As Long) As Long
    Private Declare Function GetParent Lib "user32" _
    (ByVal hwnd As Long) As Long
    '
    Private Declare Function GetWindowTextLength Lib _
    "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    
    Private Declare Function GetWindowText Lib "user32" _
    Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal _
    lpString As String, ByVal cch As Long) As Long
    
    Const GW_HWNDFIRST = 0
    Const GW_HWNDNEXT = 2
    
    Public Sub LoadTaskList()
    Dim CurrWnd As Long
    Dim Length As Long
    Dim TaskName As String
    Dim Parent As Long
    
    Form1.List1.Clear
    CurrWnd = GetWindow(Form1.hwnd, GW_HWNDFIRST)
    
    While CurrWnd <> 0
    Parent = GetParent(CurrWnd)
    Length = GetWindowTextLength(CurrWnd)
    TaskName = Space$(Length + 1)
    Length = GetWindowText(CurrWnd, TaskName, Length + 1)
    TaskName = Left$(TaskName, Len(TaskName) - 1)
    
    If Length > 0 Then
    If TaskName <> Form1.Caption Then
    Form1.List1.AddItem TaskName
    End If
    End If
    CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)
    DoEvents
    
        Wend
        
    End Sub
    
    Private Sub Command1_Click()
        LoadTaskList
    End Sub

  6. #6
    Guest
    Code for a Module
    Code:
    Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
    
    Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
        Dim Length As Long
        Dim sName As String
        Static iCount As Integer
        
        iCount = iCount + 1
        Length = GetWindowTextLength(hwnd) + 1
        
        If Length > 1 Then
          sName = Space(Length)
          GetWindowText hwnd, sName, Length
          Form1.List1.AddItem Left(sName, Length - 1)
        End If
        
        EnumWindowsProc = 1
    End Function
    Code for a Form with a ListBox and CommandButton.
    Code:
    Private Sub Command1_Click()
        EnumWindows AddressOf EnumWindowsProc, 0
    End Sub

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