Microsoft KB Archive/194914

= How To Minimize All Windows From Visual Basic =

Article ID: 194914

Article Last Modified on 7/14/2004

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q194914



SUMMARY
Occasionally you would like to programmatically minimize all visible windows. Using the keybd_event API, this can easily be accomplished.



MORE INFORMATION
The trick is to mimic the keyboard events required to bring the Taskbar popup menu and send it the letter "M" to select the "Minimize All Windows" option. This is accomplished with three calls to the keybd_event API.

The second argument for the keybd_event call is the hardware scan code, and, in this case, you could use the value 91. However, because applications should not use the scan code, it has been left as 0.

Step-by-Step Example
 Start a new Standard EXE project. Form1 is created by default. Place a CommandButton onto Form1.  Copy and paste the following code into Form1's Code Window. Private Declare Sub keybd_event Lib "user32" ( _        ByVal bVk As Byte, _         ByVal bScan As Byte, _         ByVal dwFlags As Long, _         ByVal dwExtraInfo As Long)

Const KEYEVENTF_KEYUP = &H2 Const VK_LWIN = &H5B

Private Sub Command1_Click ' 77 is the character code for the letter 'M'        Call keybd_event(VK_LWIN, 0, 0, 0) Call keybd_event(77, 0, 0, 0) Call keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0) End Sub

 Press the F5 key to run the application and Click on Command1. All visible windows will minimize.

