zoukankan      html  css  js  c++  java
  • How to customize the console applicaton

    下面是如何最大化console和改变其显示的字体颜色的代码,顺便包含了计时代码(帮助做性能分析): 

        class Program
        {
            [DllImport("kernel32.dll", ExactSpelling = true)]
            private static extern IntPtr GetConsoleWindow();
            private static IntPtr ThisConsole = GetConsoleWindow();
    
            [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
    
            private const int HIDE = 0;
            private const int MAXIMIZE = 3;
            private const int MINIMIZE = 6;
            private const int RESTORE = 9;
    
            private const int OldestPhaseNo = 2003001;
    
            static void Main(string[] args)
            {
                // Set maximum console windows size
                Console.SetWindowSize(Console.LargestWindowWidth, Console.LargestWindowHeight);
                ShowWindow(ThisConsole, MAXIMIZE);
    
                // Start the time watch
                Stopwatch watch = new Stopwatch();
                watch.Start();
                
                // Stop the time wattch
                Dictionary<string, string> ssqRecords = GetSsQiuRecords().Result;
                watch.Stop();
    
                // Change/Set the console's foregound clodr as green
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine(watch.Elapsed.TotalSeconds);
    
                // Restart the time calculation to 0
                watch.Restart();
                SaveLotteryDataToLocalConfig(ssqRecords);
                watch.Stop();
    
                Console.WriteLine(watch.Elapsed.TotalSeconds);
                // Revert back to the default color
                Console.ForegroundColor = ConsoleColor.Gray;
    
                // Set the display buffer for console window
                Console.SetBufferSize(1000, 30000);
            }
        }
  • 相关阅读:
    三周#学习进度总结
    四则运算(修改版)
    是否需要有代码规范?
    结对项目:代码复审+PSP
    二周#学习进度总结
    GitHub注册流程(中英对比)
    四则运算:我的设计和设想(未完成版)
    Spring4总结
    Hibernate5总结
    Struts2总结
  • 原文地址:https://www.cnblogs.com/researcher/p/5004970.html
Copyright © 2011-2022 走看看