Click to See Complete Forum and Search --> : Closing Windows
Illspirit
May 22nd, 2001, 04:18 PM
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.:(
Megatron
May 22nd, 2001, 04:24 PM
Add to a Module
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
To trigger it:
EnumWindows AddressOf EnumWindowsProc, 0
Megatron
May 22nd, 2001, 04:27 PM
Actually, that might close your own window. Try this instead:
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
Illspirit
May 22nd, 2001, 05:16 PM
when i use your second code, it still closes the app window, but leaves another window open:confused:
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.