Skip to content

Instantly share code, notes, and snippets.

@matarillo
Created September 12, 2019 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matarillo/ee65dba587f093dc20ad8e1782673140 to your computer and use it in GitHub Desktop.
Save matarillo/ee65dba587f093dc20ad8e1782673140 to your computer and use it in GitHub Desktop.
using System;
using System.Runtime.InteropServices;
namespace mattn
{
class Program
{
static void Main(string[] args)
{
IntPtr h = NativeMethods.GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord = new COORD(80, 31);
bool b = NativeMethods.SetConsoleScreenBufferSize(h, coord);
Console.WriteLine(b);
}
internal const int STD_OUTPUT_HANDLE = -11;
internal static class NativeMethods
{
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern IntPtr GetStdHandle(int nStdHandle);
[DllImport("kernel32.dll", SetLastError = true)]
internal static extern bool SetConsoleScreenBufferSize(IntPtr hConsoleOutput, COORD size);
}
internal struct COORD
{
internal short X;
internal short Y;
internal COORD(short x, short y)
{
this.X = x;
this.Y = y;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment