|
-
Mar 1st, 2002, 07:18 PM
#1
Thread Starter
Hyperactive Member
Close All Open Windows
There are times when I have to many things open that my desktop gets cluttered. Is there a way to close everything that is open?
-
Mar 1st, 2002, 07:21 PM
#2
Hyperactive Member
1. Log off, log back in.
2. Minimize All Windows, they're still there but no clutter.
W#Ć€V€® W¦|| ߀ W¦|| ߀, ÄÑÐ †#€®€ ¦§ ÑÖ†#¦Ñ6 ¥Öµ ©ÄÑ ÐÖ ÄßÖµ† ¦†, §Ö §¦† ßÄ©K, ®€|ÄX ÄÑÐ |€† ¦† #ÄÞÞ€Ñ.
(Whatever will be will be, and there is nothing you can do about it, so sit back, relax and let it happen.)
-
Mar 1st, 2002, 07:23 PM
#3
Thread Starter
Hyperactive Member
Thanks TiPeRa, but I'm looking for something a bit more "instant".
I don't want to have to log off. I just want to close everything.
-
Mar 1st, 2002, 07:26 PM
#4
I have a question.
How do you want to do this?
Are you looking for something intrinsic in Windows to do this for you, or do you want to write a VB program to do this for you?
If your direction is your own program, where would that be?
-
Mar 1st, 2002, 07:32 PM
#5
Thread Starter
Hyperactive Member
Well...wouldn't it be nice if you had something that you could just click on and it would do it?
-
Mar 1st, 2002, 07:47 PM
#6
Frenzied Member
Use the Enum Window API function to get a list of all windows. Then you're probably only going to want to close windows that are visible, so use the IsWindowVisible API function against each HWND in the callback. THEEEEEEEEEEN if the window IS visible, send it a WM_CLOSE message via SendMessage.
-
Mar 1st, 2002, 07:47 PM
#7
Part One
I have to give you this in two parts, because there is a 10,000 character limit on individual posts (I know because I've exceeded it before). First: Start a new project, and paste this into the declarations section of Form1
VB Code:
Private Declare Function Shell_NotifyIcon Lib "shell32" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, pnid As NOTIFYICONDATA) As Boolean
Private Type NOTIFYICONDATA
cbSize As Long
hWnd As Long
uId As Long
uFlags As Long
ucallbackMessage As Long
hIcon As Long
szTip As String * 64
End Type
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Const WM_MOUSEMOVE = &H200
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Const WM_RBUTTONDBLCLK = &H206
Private Const WM_RBUTTONDOWN = &H204
Private Const WM_RBUTTONUP = &H205
Private SysTray As NOTIFYICONDATA
Private Sub StartInSysTray()
SysTray.cbSize = Len(SysTray)
SysTray.hwnd = Picture1.hwnd
SysTray.uId = 1&
SysTray.uFlags = NIF_ICON Or NIF_TIP Or NIF_MESSAGE
SysTray.ucallbackMessage = WM_MOUSEMOVE
SysTray.hIcon = Me.Icon
SysTray.szTip = "&R&e&s&t&a&r&t" & Chr$(0)
Shell_NotifyIcon NIM_ADD, SysTray
Me.Hide
App.TaskVisible = False
End Sub
Private Sub Form_Load()
StartInSysTray
End Sub
Private Sub Form_Unload(Cancel As Integer)
SysTray.cbSize = Len(SysTray)
SysTray.hwnd = Picture1.hwnd
SysTray.uId = 1&
Shell_NotifyIcon NIM_DELETE, SysTray
End Sub
'Add A Picture Control To The Form. Set its visible property to False
Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Static rec As Boolean, msg As Long
Dim RetVal As String
Dim returnstring
Dim retvalue
msg = X / Screen.TwipsPerPixelX
If rec = False Then
rec = True
Select Case msg
'here are the various mouse events that you can use once
'you application is in the system tray. select the event of your
'choice and put CloseExceptUs there. (CloseExceptUs is a
'routine that I will post momentarily. It also needs to go on
'this form.)
Case WM_LBUTTONDOWN
Case WM_LBUTTONDBLCLK
Case WM_LBUTTONUP
Case WM_RBUTTONUP
End Select
rec = False
End If
End Sub
-
Mar 1st, 2002, 07:54 PM
#8
Part Two (Say: Thank You Nucleus)
VB Code:
Public Declare Function SendMessageTimeout Lib "user32" Alias "SendMessageTimeoutA" (ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long, ByVal fuFlags As Long, ByVal uTimeout As Long, lpdwResult As Long) As Long
Public Const SMTO_BLOCK = &H1
Public Const SMTO_ABORTIFHUNG = &H2
Public Const SC_CLOSE = &HF060&
Public Const WM_SYSCOMMAND = &H112
Public Const WM_NULL = &H0
Public Declare Function IsWindowVisible& Lib "user32" (ByVal hwnd As Long)
Public Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Const PROCESS_ALL_ACCESS = &H1F0FFF
Public Declare Function TerminateProcess& Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long)
Public Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Public m_hTaskBar As Long
Public m_hDeskTopIcons As Long
Public Sub CloseExceptUs()
';->';->';->';->';->';->';->';->';->';->';->';->';->';->
' Author: Nucleus *
' Location: VB World Forum *
' Purpose: Close all applications except this one *
';->';->';->';->';->';->';->';->';->';->';->';->';->';->
m_hDeskTopIcons = FindWindowEx(0&, 0&, "Progman", vbNullString)
m_hTaskBar = FindWindowEx(0&, 0&, "Shell_TrayWnd", vbNullString)
EnumWindows AddressOf EnumWindowsProc, 0&
End Sub
Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim lThreadID As Long
Dim lPid As Long
Dim lHp As Long
'
' If the window is not desktop icons or taskabar
'
If hwnd <> m_hTaskBar And hwnd <> m_hDeskTopIcons Then
'
' Get ThreadID and Process Id from hwnd
'
lThreadID = GetWindowThreadProcessId(hwnd, lPid)
'
' If the ThreadId is not from this application
'
If lThreadID <> App.ThreadID Then
'
' Check if the window is visible
'
If IsWindowVisible(hwnd) Then
'
' Tell the window to close gently, give it a timeout in case it does not respond
'
SendMessageTimeout hwnd, WM_SYSCOMMAND, SC_CLOSE, 0, 0, 500, 0
'
' If the window doesn't close via gently persuasion, bring out the nipple screws to force it to close
'
If IsWindow(hwnd) Then
lHp = OpenProcess(PROCESS_ALL_ACCESS, 0&, lPid)
TerminateProcess lHp&, 0&
CloseHandle lHp
End If
'
End If
'
End If
'
End If
EnumWindowsProc = 1
End Function
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|