?
Solved

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

Posted on 2014-09-08
6
Medium Priority
?
407 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: 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 5

Accepted Solution

by:
Chris Watson earned 2000 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

Industry Leaders: 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!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month11 days, 10 hours left to enroll

752 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