Results 1 to 21 of 21

Thread: How To Minimize All Open Windows

  1. #1

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Arrow 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:
    1. Option Explicit
    2. 'Copyright © 2005 by RobDog888 (VB/Office Guru™). All Rights reserved.
    3. '
    4. 'Distribution: You can freely use this code in your own
    5. '              applications provided that this copyright
    6. '              is left unchanged, but you may not reproduce
    7. '              or publish this code on any web site, online
    8. '              service, or distribute as source on any
    9. '              media without express permission.
    10. '
    11. 'Add a command button to your form and copy/paste this code
    12. Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, _
    13. ByVal dwExtraInfo As Long)
    14.  
    15. Const VK_STARTKEY = &H5B
    16. Const VK_M = 77
    17. Const KEYEVENTF_KEYUP = &H2
    18.  
    19. Private Sub Command1_Click()
    20.     'WinKey down
    21.     keybd_event VK_STARTKEY, 0, 0, 0
    22.     'M key down
    23.     keybd_event VK_M, 0, 0, 0
    24.     'M key up
    25.     keybd_event VK_M, 0, KEYEVENTF_KEYUP, 0
    26.     'WinKey up
    27.     keybd_event VK_STARTKEY, 0, KEYEVENTF_KEYUP, 0
    28. 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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.

  3. #3

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    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.

  5. #5
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  6. #6
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    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

  7. #7

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  8. #8
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    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 .

  9. #9

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  10. #10
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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:
    1. MinimizeAll
    2. Me.WindowState= vbNormal
    looks like it is the best method without subclassing.
    Last edited by iPrank; Jun 19th, 2006 at 11:15 AM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  11. #11
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    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!
    Last edited by tony007; Jun 19th, 2006 at 11:16 AM.

  12. #12
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    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 ?
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  13. #13
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    Re: How To Minimize All Open Windows

    Quote 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

  14. #14

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  15. #15

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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.
    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  16. #16
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    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:
    1. Private Sub Command1_Click()
    2.     'WinKey down
    3.     keybd_event VK_STARTKEY, 0, 0, 0
    4.     'M key down
    5.     keybd_event VK_M, 0, 0, 0
    6.     'M key up
    7.     keybd_event VK_M, 0, KEYEVENTF_KEYUP, 0
    8.     'WinKey up
    9.     keybd_event VK_STARTKEY, 0, KEYEVENTF_KEYUP, 0
    10.    
    11. [B]    'do not minimiz form itself
    12.     Me.WindowState = vbMaximized
    13.     Me.WindowState = vbNormal[/B]
    14. End Sub

  17. #17

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  18. #18
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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.)

  19. #19

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    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 PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI 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

  20. #20
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    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.

  21. #21
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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
  •  



Click Here to Expand Forum to Full Width