How To Minimize All Open Windows
This code example will minimize all your open windows simulating the "Show Desktop" quick launch button shortcut next to the Start windows menu button.
VB Code:
Option Explicit
'Copyright © 2005 by RobDog888 (VB/Office Guru™). All Rights reserved.
'
'Distribution: You can freely use this code in your own
' applications provided that this copyright
' is left unchanged, but you may not reproduce
' or publish this code on any web site, online
' service, or distribute as source on any
' media without express permission.
'
'Add a command button to your form and copy/paste this code
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, _
ByVal dwExtraInfo As Long)
Const VK_STARTKEY = &H5B
Const VK_M = 77
Const KEYEVENTF_KEYUP = &H2
Private Sub Command1_Click()
'WinKey down
keybd_event VK_STARTKEY, 0, 0, 0
'M key down
keybd_event VK_M, 0, 0, 0
'M key up
keybd_event VK_M, 0, KEYEVENTF_KEYUP, 0
'WinKey up
keybd_event VK_STARTKEY, 0, KEYEVENTF_KEYUP, 0
End Sub
Re: How To Minimize All Open Windows
You should have a way to contact you if you want someone to ask for permission to reproduce it.
Re: How To Minimize All Open Windows
Yes, that might be a good idea. For now they can just send me a PM as I am always on the Forums. :)
Re: How To Minimize All Open Windows
Randy's lets you use about 6 different actions.
http://vbnet.mvps.org/code/screen/keybd_event.htm
but I see he doesn't include any contact info, either.
Gary Beenes site does it in less code, without any keypress
http://www.garybeene.com/code/visual%20basic158.htm
no disclaimers, either
Re: How To Minimize All Open Windows
Alternate Ideas :D
(PS: If anyone finds a way to call the Shell32.IShellDispatch4.ToggleDesktop() method from VB6, please let me know. :wave:) - Resolved
Re: How To Minimize All Open Windows
Thank u rob for sharing this nice code. Is there away not to minimize the form that has the button for this code? I be happy if u show me how not to minimize the form iteself.Thanks
Re: How To Minimize All Open Windows
You mean minimize all windows but one?
Re: How To Minimize All Open Windows
Quote:
Originally Posted by RobDog888
You mean minimize all windows but one?
yes. minimize all but not the one that holds the button and this code .
Re: How To Minimize All Open Windows
If its your own form/window then you can easily just add Me.WindowState = vbMaximized.
Re: How To Minimize All Open Windows
Just a note,
Rob, when you minimize windows using th "Show Desktop" (any) method, the Form_Resize event doesn't fire.
So your idea,
VB Code:
MinimizeAll
Me.WindowState= vbNormal
looks like it is the best method without subclassing. :thumb:
Re: How To Minimize All Open Windows
Quote:
Originally Posted by RobDog888
If its your own form/window then you can easily just add Me.WindowState = vbMaximized.
i do not want to maximize the form itself. I do not want it to get placed in task bar! I tried that method it made the form itself bix and placed it in task bar!
Re: How To Minimize All Open Windows
Quote:
Originally Posted by tony007
i do not want to maximize the form itself. I do not want it to get placed in task bar!
By setting the form's ShowInTaskBar property to false ? :confused:
Re: How To Minimize All Open Windows
Quote:
Originally Posted by iPrank
By setting the form's ShowInTaskBar property to false ? :confused:
Is there a way not to maximize it just leave same size?Thanks
Re: How To Minimize All Open Windows
No it doesnt but you can subclass your form and trap the window message.
Re: How To Minimize All Open Windows
Quote:
Originally Posted by tony007
Is there a way not to maximize it just leave same size?Thanks
Just use the Me.WindowState = vbNormal but you will need to do like I just posted in order to trap the event.
Re: How To Minimize All Open Windows
Quote:
Originally Posted by RobDog888
Just use the Me.WindowState = vbNormal but you will need to do like I just posted in order to trap the event.
Many thanks to u . It worked well . Is there a way to put all the windows to some sort of system tray instead of task bar?
VB Code:
Private Sub Command1_Click()
'WinKey down
keybd_event VK_STARTKEY, 0, 0, 0
'M key down
keybd_event VK_M, 0, 0, 0
'M key up
keybd_event VK_M, 0, KEYEVENTF_KEYUP, 0
'WinKey up
keybd_event VK_STARTKEY, 0, KEYEVENTF_KEYUP, 0
[B] 'do not minimiz form itself
Me.WindowState = vbMaximized
Me.WindowState = vbNormal[/B]
End Sub
Re: How To Minimize All Open Windows
No AFAIK because you would have to manipulate all windows/programs which is difficult to do. Using some APIs I believe you can remove a window from the taskbar but it may complicate the use of the program or re-appear depending on how the app is designed .
Re: How To Minimize All Open Windows
Old thread, yes, but you don't need to add anything to your application to get the effect:
Code:
Dim Application As Object
Set Application = CreateObject("Shell.Application")
Application.MinimizeAll
For more information, see MSDN
(I originally was posting a reply to this thread but thought this would be a better choice.)
Re: How To Minimize All Open Windows
Thanks Merri, always more then 1 way to skin a cat.
Re: How To Minimize All Open Windows
Or the short version:
Code:
CreateObject("Shell.Application").MinimizeAll
The question is why anyone might want an application doing this spontaneously? It's my desktop, not some program's to fiddle with.
Re: How To Minimize All Open Windows
At least I'm doing it in a resolution changing full screen app, and once it completes it calls UndoMinimizeAll. The desktop is back as it was :) The advantage is that when resolution goes very small, not all apps are able to handle it well, especially if they're maximized or if they position themselves to the right edge or bottom of the desktop, as music players can do.
I've also made a bit of custom desktop application and because it literally sets itself to the desktop I have to minimize all the windows to let the user know something happened. And even if it won't be in final version, if it ever gets that far, it is a programming convenience as I don't need to minimize the VB IDE all the time.