C# full screen console?

后端 未结 5 1381
别那么骄傲
别那么骄傲 2020-12-16 17:01

I have seen that Windows can switch to the very basic console interface when updating the video drivers and I have also seen programs like Borland C++ doing this.
I\'d r

5条回答
  •  不思量自难忘°
    2020-12-16 17:32

    Perhaps my implementation here may help. Note that this will not work on windows systems lacking text-mode driver support.

    using System;
    using System.IO;
    using System.Collections.Generic; //for dictionary
    using System.Runtime.InteropServices; //for P/Invoke DLLImport
    
    class App
    {
    
            /// 
            /// Contains native methods imported as unmanaged code.
            /// 
            internal static class DllImports
            {
                [StructLayout(LayoutKind.Sequential)]
                public struct COORD
                {
    
                    public short X;
                    public short Y;
                    public COORD(short x, short y) { 
                        this.X = x;
                        this.Y = y;
                    }
    
                }
                [DllImport("kernel32.dll")]
                public static extern IntPtr GetStdHandle(int handle);
                [DllImport("kernel32.dll", SetLastError = true)]
                public static extern bool SetConsoleDisplayMode(
                    IntPtr ConsoleOutput
                    ,uint Flags
                    ,out COORD NewScreenBufferDimensions
                    );
            }
            /// Main App's Entry point
            public static void Main (string[] args)
            {
                IntPtr hConsole = DllImports.GetStdHandle(-11);   // get console handle
                DllImports.COORD xy = new DllImports.COORD(100,100);
                DllImports.SetConsoleDisplayMode(hConsole, 1, out xy); // set the console to fullscreen
                //SetConsoleDisplayMode(hConsole, 2);   // set the console to windowed
    
            }
    }
    

提交回复
热议问题