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

Tech-Archive recommends: Fix windows errors by optimizing your registry



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
.



Relevant Pages

  • Re: Hyperthreading problem
    ... SetConsoleWindowInfo() shouldn't return until its ... window and the server will get around to it eventually. ... of GetConsoleWindow simply tells you the size of the console window at the ... be used by console programs and to make reasonable features available to ...
    (microsoft.public.win32.programmer.kernel)
  • Re: Executing system() command without console popping ...
    ... >> The startup info also needs to be setup like so even for ... >window that doesn't exist, no? ... Windows programs which want to launch hidden console programs ...
    (microsoft.public.vc.language)
  • Re: New to programming...
    ... > the debugger with Ctrl+F5). ... > way to prevent the window closing automatically. ... >> console programs, the console window runs my program and then the window ... >> VS.net the zeroes are cut off the last rate computed for the code. ...
    (microsoft.public.vsnet.ide)
  • Re: "SendKeys" equivalent in Linux
    ... > That's limited to console programs. ... entire X server, not an arbitrary window. ... or mouse events in the currently active window) or the ...
    (comp.os.linux.misc)
  • Re: launching IE
    ... through or on top of the window originally created with the handle. ... Private Declare Function SetWindowPos Lib "USER32" (ByVal hWnd As Long, ... Private Declare Sub Sleep Lib "kernel32" ... >> Using VB is it possible to launch a website and make an internet explorer ...
    (microsoft.public.vb.general.discussion)