|
-
Sep 14th, 2005, 11:36 PM
#1
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
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 14th, 2005, 11:50 PM
#2
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.
-
Sep 14th, 2005, 11:51 PM
#3
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Sep 15th, 2005, 12:00 AM
#4
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
Last edited by dglienna; Sep 15th, 2005 at 12:04 AM.
-
Jun 9th, 2006, 10:18 AM
#5
Re: How To Minimize All Open Windows
Alternate Ideas 
(PS: If anyone finds a way to call the Shell32.IShellDispatch4.ToggleDesktop() method from VB6, please let me know. ) - Resolved
Last edited by iPrank; Apr 18th, 2007 at 08:56 AM.
-
Jun 19th, 2006, 05:03 AM
#6
Frenzied Member
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
-
Jun 19th, 2006, 09:32 AM
#7
Re: How To Minimize All Open Windows
You mean minimize all windows but one?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 19th, 2006, 10:19 AM
#8
Frenzied Member
Re: How To Minimize All Open Windows
 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 .
-
Jun 19th, 2006, 10:21 AM
#9
Re: How To Minimize All Open Windows
If its your own form/window then you can easily just add Me.WindowState = vbMaximized.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 19th, 2006, 11:11 AM
#10
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.
Last edited by iPrank; Jun 19th, 2006 at 11:15 AM.
-
Jun 19th, 2006, 11:11 AM
#11
Frenzied Member
Re: How To Minimize All Open Windows
 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!
Last edited by tony007; Jun 19th, 2006 at 11:16 AM.
-
Jun 19th, 2006, 11:14 AM
#12
Re: How To Minimize All Open Windows
 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 ?
-
Jun 19th, 2006, 11:17 AM
#13
Frenzied Member
Re: How To Minimize All Open Windows
 Originally Posted by iPrank
By setting the form's ShowInTaskBar property to false ? 
Is there a way not to maximize it just leave same size?Thanks
-
Jun 19th, 2006, 11:18 AM
#14
Re: How To Minimize All Open Windows
No it doesnt but you can subclass your form and trap the window message.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 19th, 2006, 11:19 AM
#15
Re: How To Minimize All Open Windows
 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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 19th, 2006, 11:22 AM
#16
Frenzied Member
Re: How To Minimize All Open Windows
 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
-
Jun 19th, 2006, 11:28 AM
#17
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 .
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 12th, 2008, 01:14 PM
#18
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.)
-
Jul 13th, 2008, 03:06 PM
#19
Re: How To Minimize All Open Windows
Thanks Merri, always more then 1 way to skin a cat.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jul 20th, 2008, 02:28 PM
#20
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.
-
Jul 20th, 2008, 05:27 PM
#21
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.
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
|