CodeItBetter Programming Another VB Programming Blog

How to get list of all windows

Posted on July 16, 2011
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'System & API - How to get list of all windows
'This uses a ListBox to display the running processes.
'Place the code in a module. This is necessary because a callback using
'the addressof operator is used in this code

'in a module
Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, _
    ByVal lpString As String, ByVal cch As Long) As Long
Public Const MAX_LEN = 260
 
Public Function EnumWinProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
    Dim lRet As Long
    Dim strBuffer As String
 
    If IsWindowVisible(hwnd) Then
        strBuffer = Space(MAX_LEN)
        lRet = GetWindowText(hwnd, strBuffer, Len(strBuffer))
        If lRet Then
            Form1.List1.AddItem Left(strBuffer & "  " & hwnd, lRet)
        End If
    End If
 
    EnumWinProc = 1
End Function
 
'on a form
Private Sub Command1_Click()
    Call EnumWindows(AddressOf EnumWinProc, 0)
End Sub
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.