Ways to hide the console window

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.