美文网首页
C# 控制台隐藏程序窗口

C# 控制台隐藏程序窗口

作者: norman1981 | 来源:发表于2017-03-22 10:19 被阅读0次
    using System;
    using System.Runtime.InteropServices;
    
    namespace Test
    {
        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)
            {
                #region 隐藏本体窗口
                Console.Title = "SysGreenBackService";
                IntPtr intptr = FindWindow("ConsoleWindowClass", "SysGreenBackService");
                if (intptr != IntPtr.Zero)
                {
                    ShowWindow(intptr, 0);//隐藏这个窗口
                }
                string x;
                x = Console.ReadLine();
                #endregion
             }
        }
    

    相关文章

      网友评论

          本文标题:C# 控制台隐藏程序窗口

          本文链接:https://www.haomeiwen.com/subject/mmznnttx.html