Solved

Programmatically Minimize All Windows ("ShowDesktop"), Minimize/Restore windows?

Posted on 2014-09-08
6
352 Views
Last Modified: 2014-09-08
a)      How to programmatically, using API functions, minimize all windows and show desktop, i.e. to simulate effect of pressing Win+M
b)      How to programmatically, using API functions, toggle between states when all windows are minimized and desktop shown and then toggled and all windows restored to their previous states and positions, i.e. to simulate effect of pressing Win+D

REMARK: obviously, I don’t want to do this by simulating pressing of the Win+M or Win+D key combination (for instance using keybd_event or similar function); I need a more elegant method to do it directly, using API…
0
Comment
Question by:npaun
6 Comments
 
LVL 19

Expert Comment

by:Montoya
ID: 40309838
Is scripting an option for you? As in using AutoIT to write a script that meets your criteria?
0
 

Author Comment

by:npaun
ID: 40309844
no, AutoIT script would not be an option...
0
 
LVL 17

Expert Comment

by:vb_elmar
ID: 40309846
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
    Const VK_LWIN = 91
    Const VK_STARTKEY = &H5B '=91
    Const VK_D = &H44 'D
'***********************************************************************
Private Sub sendWinD()


    keybd_event VK_LWIN, 0, 0, 0                   'press winKey
    keybd_event VK_D, MapVirtualKey(VK_D, 0), 0, 0    'press 'D'
    DoEvents   'gives Windows some time to show the Desktop hwnd
   
    keybd_event VK_D, MapVirtualKey(VK_D, 0), 2, 0   'release 'D'
    DoEvents   'gives the Alt-Tab DialogWindow some time to load
    keybd_event VK_LWIN, 0, 2, 0                '2=release winKey

End Sub
'**********************************************************************

'sample :
Private Sub Timer1_Timer()
    Call sendWinD
End Sub

Open in new window

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:npaun
ID: 40310037
@vb_elmar
Thank you for the post
As I said in the problem, for my purposes, any synthesizing of Win+M/Win+D is not an option... I need a way to to do it more directly, presumably using API, without using these keyboard shortcuts...
0
 
LVL 4

Accepted Solution

by:
Chris Watson earned 500 total points
ID: 40310793
Hi npaun,

Try this:

Dim Shell As Object

Set Shell = CreateObject("Shell.Application")

Shell.ToggleDesktop()

Set Shell = Nothing

Open in new window

0
 

Author Comment

by:npaun
ID: 40310929
@Chris Watson
Thanks, this works like a charm:)
Now, after I got idea where to look, after quick googling, I've found that Shell object also have MinimizeAll method which elegantly solves my other problem :)

I was expecting some solution based on API, but this is very compact and elegant, so I will stick with this. Thanks!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question