Solved

Q: How to minimise all open windows

Posted on 1998-07-02
5
175 Views
Last Modified: 2010-05-03
Hi,
Can some kind soul please let me know how to minimise all open windows on the desktop.

(VB5/SP3 / WIN95/98)

Many thanks.
   Tony
0
Comment
Question by:scvb
  • 2
  • 2
5 Comments
 

Expert Comment

by:wiltonk
ID: 1464883
You could try the following code:

Dim frm as Form

For Each frm In Forms
   frm.WindowState = vbMinimized
Next frm


This program scan through all forms in the desktop and minimize them.
0
 

Author Comment

by:scvb
ID: 1464884
I may have misphrased my question ...

I want to minimise all open PROGRAM windows on the desktop. Your sample will work well if only my app's forms needed to be minned, but not other (external) apps.

Looking forward to hearing from you.

Regards,
   Tony

0
 
LVL 2

Accepted Solution

by:
peterwest earned 100 total points
ID: 1464885
Hi there,

There is a way to achieve it using the API - the following code should work fine, although i've not had a chance to thoroughly test it...

First - in a module under generate declarations:

Public Declare Function GetDesktopWindow Lib "user32" () As Long
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Public Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function IsWindowEnabled Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long

Public lMinimList() As Long

Public Const GW_CHILD = 5
Public Const GW_HWNDNEXT = 2
Public Const GWL_STYLE = (-16)
Public Const WS_MINIMIZEBOX = &H20000
Public Const SW_SHOWMINNOACTIVE = 7



And then - assign the following code to a button!!!


'Declare local variables
Dim lDeskTop As Long
Dim lChildWindow As Long
Dim lRetVal As Long
Dim lStyle As Long
Dim bFirstWindow As Boolean
Dim iX As Integer
Dim iWindowCount As Integer

'Set initial variable states
bFirstWindow = True

'Get the hWnd for the desktop and then get the first child of the
'desktop
lDeskTop = GetDesktopWindow()
lChildWindow = GetWindow(lDeskTop, GW_CHILD)

'Loop through all the children of the desktop
Do While lChildWindow <> 0
   
    'Get the style mask for the current child window
    lStyle = GetWindowLong(lChildWindow, GWL_STYLE)
   
    'If the window can be minimized then....
    If lStyle And WS_MINIMIZEBOX Then
       
        'Check the hWnd is for a window and that the window is enabled and visible; this prevents
        'hidden system windows from being minimized - doing so would cause major problems...
        If IsWindow(lChildWindow) Then
            If IsWindowEnabled(lChildWindow) Then
                If IsWindowVisible(lChildWindow) Then
                   
                    'If the window was valid then resize the array to hold the hWnd as necessary
                    If bFirstWindow Then
                        bFirstWindow = False
                        ReDim lMinimList(0)
                    Else
                        ReDim lMinimList(UBound(lMinimList) + 1)
                    End If
                   
                    'Load the hWnd into the array - we'll minimize all the windows in the array
                    'later
                    lMinimList(UBound(lMinimList)) = lChildWindow
   
                End If
            End If
        End If
    End If
   
    'Get the next child window
    lChildWindow = GetWindow(lChildWindow, GW_HWNDNEXT)

Loop

'Determine how many windows we need to minimize and store in a variable
iWindowCount = UBound(lMinimList)

'Loop through the array, using the SizeChange API to minimize each in turn
For iX = 0 To iWindowCount
    lRetVal = ShowWindow(lMinimList(iX), SW_SHOWMINNOACTIVE)
Next iX




Hope this helps

Pete

0
 
LVL 2

Expert Comment

by:peterwest
ID: 1464886
Ooops!!!

Sorry, I accidentally missed out the 'preserve' keyword in the redim statement about half way through the main routine.  Just change the line:

ReDim lMinimList(UBound(lMinimList) + 1)

to read

ReDim Preserve lMinimList(UBound(lMinimList) + 1)

and everything should be fine!!!

Sorry 'bout that!!

Pete

0
 

Author Comment

by:scvb
ID: 1464887
Thanks very much indeed. Yes, the Redim statement fixed it!!
Brilliant answer!

All the best.

Kind regards,
    Tony Jones
    Southern Cross Visual Basic Code and Links
    http://www.geocities.com/capecanaveral/6740/index.html

0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

810 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