HOWTO: Minimize All Windows From Visual Basic
ID: Q194914
|
The information in this article applies to:
-
Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, versions 5.0, 6.0
-
Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 32-bit only, for Windows, version 4.0
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.
REFERENCES
For more information, please Search on keybd_event in either the Win32
Programmer's Reference or The Microsoft Developer Network (MSDN) Library CD-ROM.
Keywords : kbAPI kbGrpUser kbVBp kbVBp400 kbVBp500 kbVBp600 kbGrpVB
Version : WINDOWS:4.0,5.0,6.0
Platform : WINDOWS
Issue type : kbhowto
|