Re: How to minimize command mode window in console program?



On May 23, 2:17 pm, James Wong <cphk_ms...@xxxxxxxxxxxxx> wrote:
Hi Onur,

Thanks a lot for your help!  What I thought in the past is that I only need
to set some property to minimize the console window.  I never imagine that I
need to write code involving API.  I'll never make it without your help!

Regards,
James Wong



"kimiraikkonen" wrote:
On May 23, 12:18 pm, James Wong <cphk_ms...@xxxxxxxxxxxxx> wrote:
Hi Onur,

Thanks for your reply!  But I may not describe my question clearly.  The
console programs are either launched by Windows scheduler or manual
double-click in Windows Explorer, but not run by other VB application.  My
question is if it is possible to write code to minimize command window within
my console application.

Thanks again for your help!

Regards,
James Wong

"kimiraikkonen" wrote:
On May 23, 11:26 am, James Wong <cphk_ms...@xxxxxxxxxxxxx> wrote:
Dear all,

I'd like to know if there is any method to minimize command mode window when
a console program is running.  In my case, there are several console programs
which run periodically in server.  Now, every console program instance will
open a command mode window and they occupy the whole screen.  I want to
minimize all of them and maximize it if neccessary by manual.  Is it possible
and how to do it?  I'm using VB.NET 2005.

Thanks for your attention and kindly advice!

Regards,
James Wong

Hi James,
If you want to minimize them on application launch, it's pretty
simple:

' Assuming you have a console app
Dim info As New System.Diagnostics.ProcessStartInfo("c:\process.exe")
info.WindowStyle = ProcessWindowStyle.Minimized
Dim process As New Process
process.Start(info)

And i suppose you want to minimize *all* of your apps while they're
running, so why don't use just click on "show desktop" on quick launch
bar to minimize all to open spare space on screen?

Thanks,

Onur Güzel

Hi again,
I tested this and you can minimize a console window using ShowWindow
function API via P/Invoke.

Here is a full simple snippet to minimize a console window:
(Save and compile application as "myconsole")

Imports System.Diagnostics

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

    <Flags()> _
    Private Enum SHOW_WINDOW As Integer
        SW_HIDE = 0
        SW_SHOWNORMAL = 1
        SW_NORMAL = 1
        SW_SHOWMINIMIZED = 2
        SW_SHOWMAXIMIZED = 3
        SW_MAXIMIZE = 3
        SW_SHOWNOACTIVATE = 4
        SW_SHOW = 5
        SW_MINIMIZE = 6
        SW_SHOWMINNOACTIVE = 7
        SW_SHOWNA = 8
        SW_RESTORE = 9
        SW_SHOWDEFAULT = 10
        SW_FORCEMINIMIZE = 11
        SW_MAX = 11
    End Enum

    Sub Main()
        Console.Write("Press Any Key to minimize window")
        Console.ReadLine()
        ' Minimize function
        minimize()
        ' See it minimized, then exit
        Console.ReadLine()
    End Sub

    Private Sub minimize()
        For Each p As Process In
Process.GetProcessesByName("myconsole")
            ShowWindow(p.MainWindowHandle, SHOW_WINDOW.SW_MINIMIZE)
        Next p
    End Sub

End Module

.... And you can change "myconsole" which is your orginal console
application's name.(Don't add .exe extension, be careful!) to get
process. Then call the sub named "minimize" (even you can change this
sub name, you know) to invoke ShowWindow function API.

Hope this helps,

Onur Güzel- Hide quoted text -

- Show quoted text -

Thanks for the feedback, if it was a form then minimizing would be
done with a single codeline as you stated by setting windowState
property, but console window is minimized using API.

Glad you solved it :)

Thanks,

Onur Güzel
.



Relevant Pages

  • RE: Output Window
    ... to create a console applicaiton for each Exercise, ... Public Sub DirFiles() ... I'd like to clear the Output window of any previous output. ... Is there a way to clear previous output text in the Output Window? ...
    (microsoft.public.dotnet.languages.vb)
  • Re: How to minimize command mode window in console program?
    ... to set some property to minimize the console window. ... Sub Main ... you know) to invoke ShowWindow function API. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Console.Clear()
    ... data to the console window. ... uinhandled exception and the exception is that it does not have the ... Sub Main ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Console.Clear()
    ... I allways use console as a diagnostic tool. ... Its just that It would be nice to clear the console window, ... uinhandled exception and the exception is that it does not have the ... Sub Main ...
    (microsoft.public.dotnet.languages.vb)
  • Re: working set and console applications
    ... I created a windows application and then I created a child console process ... that I started from the parent process using CreateProcess. ... I minimize the child console window it also causes the working set of the ...
    (microsoft.public.win32.programmer.kernel)