Skip to content

Instantly share code, notes, and snippets.

@lsauer
Created September 18, 2012 08:07
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save lsauer/3741940 to your computer and use it in GitHub Desktop.
Save lsauer/3741940 to your computer and use it in GitHub Desktop.
C# Fullscreen Console on Windows via unmanaged kernel32 calls to SetConsoleDisplayMode
//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
}
}
@equalisysdev
Copy link

doesnt work for me

@rinrab
Copy link

rinrab commented Mar 1, 2024

doesnt work for me

for me also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment