Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Minimize All Windows (Show Desktop)

API Functions

Minimize All Windows (Show Desktop)

by  craigsboyd  Posted    (Edited  )
Slighthaze = [color blue]NULL[/color]

Below I am providing two ways to minimize all of the applications (top level windows) currently running. Cut-N-Paste the code below into prg file(s) and run the different alternatives to see how it works.

[color green]******************FIRST WAY TO DO IT*******************

*!* Let's Minimize and UnMinimize All Top Level Windows[/color]
#DEFINE WM_COMMAND 0x111
DECLARE INTEGER FindWindow IN user32 STRING, STRING
DECLARE INTEGER SendMessage IN user32 INTEGER, INTEGER, INTEGER, INTEGER
SendMessage(FindWindow("Shell_TrayWnd", NULL), WM_COMMAND, 415, 0) [color green]&&Minimize All[/color]
=INKEY(2) [color green]&&Give windows a chance to catch up[/color]
MESSAGEBOX("Now we will undo the minimize")
SendMessage(FindWindow("Shell_TrayWnd", NULL), WM_COMMAND, 416, 0) [color green]&&Undo Minimize

******************SECOND WAY TO DO IT*******************

*!* Let's Minimize All Top Level Windows[/color]
DECLARE INTEGER CloseWindow IN user32 INTEGER
DECLARE INTEGER GetActiveWindow IN user32
DECLARE INTEGER GetWindow IN user32 INTEGER, INTEGER
DECLARE INTEGER GetWindowTextLength IN user32 INTEGER
DECLARE INTEGER IsIconic IN user32 INTEGER
DECLARE INTEGER IsWindow IN user32 INTEGER
DECLARE INTEGER IsWindowVisible IN user32 INTEGER

LOCAL nActive, nCounter, nHwnd, nIndex
LOCAL cWindowCaption

nCounter = 0
nHwnd = -1

nActive = GetActiveWindow()

DO WHILE nHwnd != GetWindow(nActive, 1) [color green]&&1 = FIRST WINDOW[/color]
IF nHwnd != -1
nHwnd = GetWindow(nHwnd, 2) [color green]&&2 = NEXT WINDOW[/color]
ELSE
nHwnd = GetWindow(nActive, 0) [color green]&&0 = LAST WINDOW[/color]
ENDIF

IF GetWindowTextLength(nHwnd) > 0 AND IsWindow(nHwnd) != 0 AND IsWindowVisible(nHwnd) != 0
nCounter = nCounter + 1
DIMENSION aryWindows(nCounter)
aryWindows(nCounter) = nHwnd
ENDIF
ENDDO

FOR nIndex=1 TO nCounter
If IsIconic(aryWindows(nIndex)) = 0
IF CloseWindow(aryWindows(nIndex)) = 0
[color green]*!* Non-existant window or something went wrong[/color]
ENDIF
ENDIF
ENDFOR

[color green]******************SCARY WAY TO DO IT*******************

*!* Use the following with EXTREME CAUTION
*!* Will minimize all windows including hidden ones
*!* Won't break anything but you will have a
*!* window mess on your hands It is kind
*!* of informative so for the brave go ahead
*!* and uncomment it and run it
*!* #DEFINE HWND_BROADCAST 0xffff
*!* #DEFINE SC_MINIMIZE 0xF020
*!* #DEFINE WM_SYSCOMMAND 0x112
*!* DECLARE INTEGER SendMessage IN user32 INTEGER, INTEGER, INTEGER, INTEGER
*!* SendMessage (HWND_BROADCAST, WM_SYSCOMMAND, SC_MINIMIZE, 0)[/color]
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top