WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Sample code
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Code to Automatically Minimize Open Windows

Keywords: winzoom winhide minimize 

Code to automatically minimize all open windows.

There is a .SCF file in the Windows System directory that can 'show the desktop'. In other words, minimize *all* windows. This seems to work on *all* platforms *except* Windows NT 4.0, which doesn't seem to support this file.

showdesktop=strcat(DirWindows(1),"Show Desktop.scf")
If FileExist(showdesktop)
  ShellExecute(showdesktop,"",DirWindows(1),@NORMAL,"")
Endif
Or if you want to run this script on NT 4.0 or if the 'Show Desktop.scf' file doesn't exist. Give this a shot:
list=WinItemize()
count=ItemCount(list,@tab)

for xx=1 to count
   thiswin=ItemExtract(xx,list,@tab)
   if WinState(thiswin)==@HIDDEN then continue
   WinIconize(thiswin)
next
or
oShell = ObjectOpen("Shell.Application")
oShell.MinimizeAll
ObjectClose(oShell) 

Other Options

Here's some code extracted from (and slightly edited from) the INSTALL.WBT example file.

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 ;SetupSplash iconizes all windows
 :setupsplash
 OrigWindowList=WinItemize()   ;Get list of all open Windows
 OrigWindowCount=ItemCount(OrigWindowList,@tab)
 for i=1 to OrigWindowCount
    a=ItemExtract(i,OrigWindowList,@tab)
    b = WinState(a)
    OrigWindowState%i% = b

    ; Note we could hide the other windows here, but if the install
    ; bombs kind of bad, it leaves the user in a lurch and they
    ; got to reboot.  Bad news.  With icons they can always recover
    ; by themselves.

    if b!=@HIDDEN && b!=@ICON && WinExist(a) then WinIconize(a)

 next
 return

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

 ;UnSplash undoes Setup Splash
 :UnSplash
 ErrorMode(@off)
 for i= OrigWindowCount to 1 by -1
    a=ItemExtract(i,OrigWindowList,@tab)
     switch OrigWindowState%i%
        case @HIDDEN
           break
        case @NORMAL
           WinShow(a)
           break
        case @ICON
           break
        case @ZOOMED
           WinZoom(a)
           break
     end switch
 next
 ErrorMode(@cancel)
 return

Additional Notes:

Windows can be zoomed, but hidden.

ZOOMED, NORMAL and ICON are one set of states.

SHOWING and HIDDEN are a different set of states. WinShow goes with WinHide (if all else fails, try WinActivate).

WinZoom, WinIconize and WinShow are another set of functions.

(WinShow appears twice above. There is no easy way to handle the situation - all the possible ways of changing the Windows simply doesn't exist.)


Article ID:   W13744
Filename:   Code to Automatically Minimize Open Windows.txt
File Created: 2002:01:31:12:17:26
Last Updated: 2002:01:31:12:17:26