As you all know when you execute an console application it will load command prompt and shows out put. There are amny situation in which you do not want this console window to be dislayed to user while your application runing. You can do that by calling some unmanaged functions. I have used following method to do that which is posted by Brendan Grant on MSDN.
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
public static extern IntPtr
FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
IntPtr hWnd = FindWindow(null, title);
if (hWnd != IntPtr.Zero)
{
if (!visible)
//Hide the window
ShowWindow(hWnd, 0); // 0 = SW_HIDE
else
//Show window again
ShowWindow(hWnd, 1); //1 = SW_SHOWNORMA
}
Fig - (1) Code to hide console window in console application
8 comments:
This code works but the problem is it still shows the console window for a fraction of time before closing it.
All you have to do is change the output type to a Windows Application rather than a Console Application. This is stop the console window from showing when running the application.
There is no need for all this code? What a load of rubbish, this doesn't even do the job properly.
Daniel Coe, you are a LEGEND :)
But what if you want to change the output type programatically.
But what if you want to change the output type programatically.
best solution is in project property set out type to window application. It works well for me.---vinay
I set Output type to "Windows" and it worked for me.
Thanks alot :)
How to hide multiple windows of same name
Post a Comment