How do i close all of the active windows??? I have the code to minimise them, but ive been having problems getting it to close them.:(
Printable View
How do i close all of the active windows??? I have the code to minimise them, but ive been having problems getting it to close them.:(
Add to a Module
To trigger it:Code:Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_CLOSE = &H10
Private Const WM_QUIT = &H12
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
PostMessage hwnd, WM_CLOSE, 0, 0
PostMessage hwnd, WM_QUIT, 0, 0
EnumWindowsProc = 1
End Function
Code:EnumWindows AddressOf EnumWindowsProc, 0
Actually, that might close your own window. Try this instead:
Code:Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_CLOSE = &H10
Private Const WM_QUIT = &H12
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
If hwnd <> Form1.hWnd then
PostMessage hwnd, WM_CLOSE, 0, 0
PostMessage hwnd, WM_QUIT, 0, 0
EnumWindowsProc = 1
End If
End Function
when i use your second code, it still closes the app window, but leaves another window open:confused: