?
Solved

Q: How to minimise all open windows

Posted on 1998-07-02
5
Medium Priority
?
192 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
[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
  • 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 400 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses
Course of the Month13 days, 2 hours left to enroll

777 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