Put this code in a form
Put this code in a standard basic module(not in form or in class module)Code:Public Function ListWindows() As Long Dim rc As Long Dim lParam As Long 'We're not concerned with a custom message at this time lParam = 0 'call the api ListWindows = EnumWindows(AddressOf EnumWindowsProc, lParam) End Function Private Sub Command1_Click() Call ListWindows End Sub
But this will return you a large number of handle's. If you need only those on the desktop, try "EnumDesktopWindows" instead.Code:Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean Debug.Print hwnd 'while this value is true it will keep on searching for open windows till it reaches 'the last window EnumWindowsProc = True End Function




Reply With Quote