Minimizing the Console Window

  • Thread starter Thread starter Guest
  • Start date Start date
It is a window and can be minimized manually by clicking the minimize box.
The question is how to programmatically minimize it.
 
Abelard said:
It is a window and can be minimized manually by clicking the minimize box.
The question is how to programmatically minimize it.

The problem is that the way you do it programatically in a Windows
Application project is by setting the Me.WindowState to Minimized. But
the WindowState property is defined in the System.Windows.Forms class
and a Console Application window is not a member of the
Systems.Windows.Forms class. To make things even worse, there is no
Console.WindowState property.

Now, I happen to agree with you, a console window is essentially a
Command Prompt window that is running a specific piece of code. And you
can minimize a Command Prompt (and a Console App) window by clicking on
the minimize button, so there should be some way to do it
programmatically, but I haven't found it. Maybe there is an API call to
do it? (Since .NET I try to avoid API calls whenever possible.)
 
Thanks to all of yoh for your input. The link below had exactly the answer I
needed. The console is a true window. You have to do a call to this
function with all the correct parameters to control its behavior:

Imports System.Diagnostics

Private Declare Function ShowWindow Lib "user32.dll" ( _
ByVal hWnd As IntPtr, _
ByVal nCmdShow As SHOW_WINDOW _
) As Boolean

The link Miro sent has the rest of the details. It's very nice code and a
generally
useful function.
 
Back
Top