In the process of our program, we often need to use the console program to do experiments or used as a background of some small applications, we usually can use the console program, and, many times we do not need to show his window, how to hide his window? Very simple......
First look at a simple program, this program is the way we use to hide the window!
#region Hidden Window [DllImport ("user32.dll", EntryPoint = "ShowWindow", SetLastError = True)] private static extern BOOL ShowWindow (INTPTR hWnd, uint ncmdshow); [DllImport ("user32.dll", EntryPoint = "FindWindow", SetLastError = True)] private static extern IntPtr FindWindow (string lpclassname, String lpwindowname); public static void Windowhide (string consoletitle) { IntPtr a = FindWindow ("Consolewindowclass", Consoletitle) ; if (A! = IntPtr.Zero) ShowWindow (A, 0);//Hide window else throw new Exception ("Can ' t hide console window"); #endregion
This code inside calls Windows API, very simple can implement hidden window method, as for more detailed things, or check Google Bar!
Method to invoke:
static void Main (string[] args) { try { console.title = ' testpmars ';//Specify a title for the console form for easy positioning and differentiation Windowhide ("Testpmars"); } Catch { Console.WriteLine ("Error"); } Thread.Sleep ( -1); }
Very simple, Console.title = "testpmars", set a name to the console, and then pass this name to Windowhide!
Where we used the namespace
Using System.Runtime.InteropServices;
The above content is enough for us to realize the purpose of hidden windows!
Remember here, share to everyone!
Ways to hide the console window