Solved

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

Posted on 2014-09-08
6
302 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:Iammontoya
Comment Utility
Is scripting an option for you? As in using AutoIT to write a script that meets your criteria?
0
 

Author Comment

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

Expert Comment

by:vb_elmar
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:npaun
Comment Utility
@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
Comment Utility
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
Comment Utility
@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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now