CodeItBetter Programming Another VB Programming Blog

How to Minimize all windows (in four ways)

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'System & API - How to Minimize all windows (in four ways)
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, _
    ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
 
Sub Main()
    Call keybd_event(&H5B, 0, 0, 0)
    Call keybd_event(&H4D, 0, 0, 0)
    Call keybd_event(&H5B, 0, &H2, 0)
End Sub
 
'Another way:

Option Explicit
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As Byte, ByVal bScan As Byte, _
    ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
 
Const VK_STARTKEY = &H5B
Const VK_M = 77
Const KEYEVENTF_KEYUP = &H2
 
Public Sub Main()
    'WinKey down
    keybd_event VK_STARTKEY, 0, 0, 0
    'M key down
    keybd_event VK_M, 0, 0, 0
    'M key up
    keybd_event VK_M, 0, KEYEVENTF_KEYUP, 0
    'WinKey up
    keybd_event VK_STARTKEY, 0, KEYEVENTF_KEYUP, 0
End Sub
 
'Another way:

Option Explicit
' Add a reference to Microsoft Shell Control & Automation
Dim MyShell As New Shell32.Shell
 
Private Sub Command1_Click()
    MyShell.MinimizeAll
End Sub
 
Private Sub Command2_Click()
    MyShell.UndoMinimizeALL
End Sub
 
'Another way:

Option Explicit
'Create a new .scf file (or use the default one) and use shell execute to call it.
'To create a .scf file:
'In Notepad, type the following text on individual lines:
'[Shell]
'Command = 2
'IconFile=explorer.exe,3
'[Taskbar]
'Command = ToggleDesktop
'Click File, click Save As, and then save the file to your desktop as Show Desktop.scf.
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
    ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, _
    ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Const SW_SHOWNORMAL = 1
 
Public Sub Main()
    ShellExecute Me.hwnd, vbNullString, App.Path & "\aaa.scf", vbNullString, "C:\", SW_SHOWNORMAL
End Sub
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.