Minimize it?

How do I make a command button in VB that minimizes everything including the program and the stuff running in the background?
Who is Participating?
Ryan ChongConnect With a Mentor Commented:
Try doing an EnumWindows API function, then for each window do the following API:

ShowWindow(hWnd, SW_MINIMIZE)
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.

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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.