Link to home
Start Free TrialLog in
Avatar of Linky
Linky

asked on

Minimize it?

How do I make a command button in VB that minimizes everything including the program and the stuff running in the background?
Avatar of agriggs
agriggs

Try doing an EnumWindows API function, then for each window do the following API:

ShowWindow(hWnd, SW_MINIMIZE)
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You could enumerate through everything which would work, or you could just press the windows key and key m in code which would do the same thing.

Option Explicit

Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal _
  bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Const KEYEVENTF_KEYUP = &H2
Private Const VK_LWIN = &H5B


Private Sub Command1_Click()
  Call keybd_event(VK_LWIN, 0, 0, 0)
  Call keybd_event(vbKeyM, 0, 0, 0)
  Call keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0)
End Sub
I guess from other responses that I may have misunderstood.  I thought you wanted to minimize everything running on the system ("everything including the program and the stuff running in the background.")

That's what the first suggestion is for.
Agriggs,

The code I gave him will as well...I assume we are thinking along the same line.  He can either enumerate through all the windows, see if they are appwindows and send a minimize message, or he can simply just press the Win-M key combination in code which will do the same thing, minimize all open windows including his own.  I have done it both ways, but it doesn't matter to me how he chooses to do so.