Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As LongPublic Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As LongPublic Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As LongPublic Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As LongPublic Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As LongPublic Declare Function GetWindowText Lib " user32 "Alias" GetWindowTextA "(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongPublic Declare Function SendMessage Lib" user32 "Alias" SendMessageA "(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long LParam as any) As long
Public Const SW_SHOW = 5Public Const SW_RESTORE = 9Public Const GW_OWNER = 4Public Const GWL_HWNDPARENT = (-8) Public Const GWL_EXSTYLE = (-20) Public Const WS_EX_TOOLWINDOW = & H80Public Const WS_EX_APPWINDOW = & H40000Public Const LB_ADDSTRING = & H180Public Const LB_SETITEMDATA = & H19APublic Const EWX_FORCE = 4Public Const EWX_LOGOFF = 0PUBLIC Const EWX_REBOOT = 2PUBLIC Const EWX_SHUTDOWN = 1const Max_Path & = 260Private const sw_hide = 0Private const wm_close = & h10public hhwnd as long
Public Function WhichWindowsCallback (Byval Hwnd As Long, Byval LParam As Long) As long Dim Lreturn As Long Dim LexStyle As Long Dim Bnoowner as Boolean Dim SwindowText As String
If hwnd <> Form1.hwnd Then If IsWindowVisible (hwnd) Then If GetParent (hwnd) = 0 Then bNoOwner = (GetWindow (hwnd, GW_OWNER) = 0) lExStyle = GetWindowLong (hwnd, GWL_EXSTYLE) If (((lExStyle And WS_EX_TOOLWINDOW) = 0) AND BNOOWNER) OR _ ((LexStyle and WS_EX_APPWINDOW) and not bnoowner) THENER
SwindowText = Space $ (256) Lreturn = getWindowText (HWND, SWINDOTEXT, LEN (SWINDOWTEXT) IF LRETURN THEN
sWindowText = Left $ (sWindowText, lReturn) lReturn = SendMessage (lParam, LB_ADDSTRING, 0, ByVal sWindowText) Call SendMessage (lParam, LB_SETITEMDATA, lReturn, ByVal hwnd) End If End If End If End If End If HHWnd = hwnd WhichWindowsCallBack = TrueEnd Function
Public Function fEnumWindows (lst As ListBox) As Long With lst .Clear Call EnumWindows (AddressOf WhichWindowsCallBack, .hwnd) fEnumWindows = .ListCount End WithEnd FunctionPrivate Sub Form_Load () Call fEnumWindows (List1) End Sub