转:隐藏C#控制台程序运行时的窗口

using System;

using System.Collections.Generic;

using System.Text;

using System.Runtime.InteropServices;

 

namespace HideConsole

{

    ///

    /// 实现: 隐藏控制台程序的演示

    /// 作者: 三角猫/DeltaCat

    /// 网址: http://www.zu14.cn/

    /// 说明: 转载务必保留此信息

    ///

    class Program

    {

        [DllImport("user32.dll", EntryPoint = "ShowWindow", SetLastError = true)]

        static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow);

        [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]

        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        static void Main(string[] args)

        {

            Console.Title = "我被隐藏"; //为控制台窗体指定一个标题,便于定位和区分

            IntPtr a = FindWindow("ConsoleWindowClass", "我被隐藏");

            if (a != IntPtr.Zero)

                ShowWindow(a, 0); //隐藏这个窗口

 

            Console.ReadKey(); //这句代码,保证程序不会退出,为了做演示而已

        }

    }

}

 

 

转自:http://www.zu14.cn/2009/05/26/hide-console-application-window-by-windows-api-showwindow/

你可能感兴趣的:(C/C++,c#,string,user,class)