Solved

Q: How to minimise all open windows

Posted on 1998-07-02
5
166 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

708 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

15 Experts available now in Live!

Get 1:1 Help Now