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
Solved

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

Posted on 2014-09-08
6
343 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
VBA saving file message display 5 72
String manipulation in Visual Basic 7 73
VBA/SQL - Connect to SQL server and pull data 4 118
Error with a code discussed on this page 5 31
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

840 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