Created
September 18, 2012 08:07
-
-
Save lsauer/3741940 to your computer and use it in GitHub Desktop.
C# Fullscreen Console on Windows via unmanaged kernel32 calls to SetConsoleDisplayMode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//author: lsauer.com 2012, CC-BY-SA | |
//description: Fullscreen consoles were common until the last few years. | |
// Currently Windows XP, and Windows Vista, Windows 7’s Safe Mode allow fullscreen console mode. | |
// The reason is that the current display driver model does not support VGA text mode programs. | |
using System; | |
using System.IO; | |
using System.Collections.Generic; //for dictionary | |
using System.Runtime.InteropServices; //for P/Invoke DLLImport | |
class App | |
{ | |
/// <summary> | |
/// Contains native methods imported as unmanaged code. | |
/// </summary> | |
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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
doesnt work for me