'Getting all windows
Public Const MAX_PATH = 260 Public Const SW_HIDE = 0 Public Const SW_SHOW = 5 Public Const SW_MAXIMIZE = 3 Public Const SW_MINIMIZE = 6 Public Const SW_NORMAL = 1 Public Const SW_RESTORE = 9 Public Const WM_CLOSE = &H10 Public Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Integer, _ ByVal lParam As Long) As Long Public Declare Function ShowWindow Lib "user32" _ (ByVal hwnd As Long, _ ByVal nCmdShow As Long) As Long 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 GetClassName Lib "user32" _ Alias "GetClassNameA" _ (ByVal hwnd As Long, _ ByVal lpClassName As String, _ ByVal nMaxCount 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 EnumWindowProc = 1 'To keep EnumWindows from 'continuing it's loop, have 'your function return 1. End Function Public Function EnumWindowProc(ByVal hwnd As Long, _ ByVal lParam As Long) As Long Dim sTitle As String Dim sClass As String Dim sLoc As String sTitle = Space$(MAX_PATH) sClass = Space$(MAX_PATH) sLoc = Space$(MAX_PATH) 'sClass Call GetClassName(hwnd, sClass, MAX_PATH) 'and sTitle Call GetWindowText(hwnd, sTitle, MAX_PATH) 'You can place the function in any event 'Call function like this: Call EnumWindows(AddressOf EnumWindowProc, &H0) are given their values through these functions You now have a handle, caption, and class name. If you wanted to minimize all windows you could do the following: ShowWindow hwnd, SW_MINIMIZE In Windows it is not this simple though. There are many programs not meant to behidden like tooltips and OLE programs. You can implement the IsWindowVisible function to check if it is supposed to be minimized: 'If IsWindowVisible(hwnd) Then 'ShowWindow hwnd, SW_MINIMIZE 'End if You can change the SW_MINIMZE to any other constant to make it maximize, restore to normal, or any other combo. To close the windows you can do this: 'If IsWindowVisible(hwnd) Then 'SendMessage hwnd, WM_CLOSE, 0, 0 'End if You can also change captions and many other things knowing the handle. The one thing I have come across is getting the path of an application. This is not possible through VB but can be achieved through DLLs. I have come across a very good one crea ted by Jürgen Thümmler <thue@gmx.de>. Assumes: All explanation is in the module with the base function. Use the following to call get windows: Call EnumWindows(AddressOf EnumWindowProc, &H0) |