Solved

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

Posted on 2014-09-08
6
367 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…

734 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