Home > How-To Library > System & API
How to get list of all windows
**************************************************************** * © 2007 CodeItBetter http://www.codeitbetter.com * * This notice MUST stay intact for legal use * **************************************************************** '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
If you would like to submit your code here please us. Do not forget to mention your name. We are always thankful to each and everyone of you who submitted their code here.