zoukankan      html  css  js  c++  java
  • C# 调用控制台输出

         [DllImport("kernel32.dll")]
            public static extern bool AllocConsole();
            [DllImport("User32.dll ", EntryPoint = "FindWindow")]
            private static extern int FindWindow(string lpClassName, string lpWindowName);
            [DllImport("user32.dll ", EntryPoint = "GetSystemMenu")]
            extern static IntPtr GetSystemMenu(IntPtr hWnd, IntPtr bRevert);
            [DllImport("user32.dll ", EntryPoint = "RemoveMenu")]
            extern static int RemoveMenu(IntPtr hMenu, int nPos, int flags);
            [DllImport("kernel32.dll")]
            public static extern bool FreeConsole();
         ///
            /// 打开控制台方法(条用次方法可打开控制台)
            ///
            public static void OpenConsole()
            {
                AllocConsole();
                //根据控制台标题找控制台
                int WINDOW_HANDLER = FindWindow(null, Console.Title);
                //A找关闭按钮 次代码和B下的代码是禁用打开窗口的关闭按钮(同时也会关闭程序)           
                IntPtr CLOSE_MENU = GetSystemMenu((IntPtr)WINDOW_HANDLER, IntPtr.Zero);
                int SC_CLOSE = 0xF060;
                //B关闭按钮禁用 (A和B可根据情况选用)          
                RemoveMenu(CLOSE_MENU, SC_CLOSE, 0x0);
    
                Console.WriteLine("程序已启动");
            }
    在需要启动的位置,调用OpenConsole方法,在程序关闭后,调用FreeConsole方法,释放一下。
  • 相关阅读:
    css布局模型
    HTML元素分类
    《水经注》卷三十五
    《水经注》卷二十八
    沧浪之水
    网页布局基础
    IndexError: tuple index out of range
    树回归-CART
    树回归-CART
    支持向量机SVM
  • 原文地址:https://www.cnblogs.com/ZXdeveloper/p/12092387.html
Copyright © 2011-2022 走看看