public void Clear() { Coord coord = new Coord(); ConsoleScreenBufferInfo info = new ConsoleScreenBufferInfo(); GetConsoleScreenBufferInfo(outputHandle, out info); int size = info.Size.X * info.Size.Y; int written; FillConsoleOutputCharacter(outputHandle, ' ', size, coord, out written); GetConsoleScreenBufferInfo(outputHandle, out info); FillConsoleOutputAttribute(outputHandle, info.Attribute, size, coord, out written); SetConsoleCursorPosition(outputHandle, coord); }
public void SetBufferSize(int width, int height) { ConsoleScreenBufferInfo info = new ConsoleScreenBufferInfo(); GetConsoleScreenBufferInfo(outputHandle, out info); if (width - 1 > info.Window.Right) { throw new ArgumentOutOfRangeException("width"); } if (height - 1 > info.Window.Bottom) { throw new ArgumentOutOfRangeException("height"); } Coord coord = new Coord(width, height); if (!SetConsoleScreenBufferSize(outputHandle, coord)) { throw new ArgumentOutOfRangeException("height/width", "Cannot be smaller than the window size."); } }
extern static bool GetConsoleScreenBufferInfo (IntPtr handle, out ConsoleScreenBufferInfo info);
public void SetWindowSize (int width, int height) { ConsoleScreenBufferInfo info = new ConsoleScreenBufferInfo (); GetConsoleScreenBufferInfo (outputHandle, out info); SmallRect rect = info.Window; rect.Right = (short) (rect.Left + width - 1); rect.Bottom = (short) (rect.Top + height - 1); if (!SetConsoleWindowInfo (outputHandle, true, ref rect)) throw new ArgumentOutOfRangeException ("left/top", "Windows error " + Marshal.GetLastWin32Error ()); }
public void SetWindowPosition (int left, int top) { ConsoleScreenBufferInfo info = new ConsoleScreenBufferInfo (); GetConsoleScreenBufferInfo (outputHandle, out info); SmallRect rect = info.Window; rect.Left = (short) left; rect.Top = (short) top; if (!SetConsoleWindowInfo (outputHandle, true, ref rect)) throw new ArgumentOutOfRangeException ("left/top", "Windows error " + Marshal.GetLastWin32Error ()); }
public void SetBufferSize (int width, int height) { ConsoleScreenBufferInfo info = new ConsoleScreenBufferInfo (); GetConsoleScreenBufferInfo (outputHandle, out info); if (width - 1 > info.Window.Right) throw new ArgumentOutOfRangeException ("width"); if (height - 1 > info.Window.Bottom) throw new ArgumentOutOfRangeException ("height"); Coord coord = new Coord (width, height); if (!SetConsoleScreenBufferSize (outputHandle, coord)) throw new ArgumentOutOfRangeException ("height/width", "Cannot be smaller than the window size."); }
public void MoveBufferArea (int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight, int targetLeft, int targetTop, Char sourceChar, ConsoleColor sourceForeColor, ConsoleColor sourceBackColor) { if (sourceForeColor < 0) throw new ArgumentException ("Cannot be less than 0.", "sourceForeColor"); if (sourceBackColor < 0) throw new ArgumentException ("Cannot be less than 0.", "sourceBackColor"); if (sourceWidth == 0 || sourceHeight == 0) return; ConsoleScreenBufferInfo info = new ConsoleScreenBufferInfo (); GetConsoleScreenBufferInfo (outputHandle, out info); CharInfo [] buffer = new CharInfo [sourceWidth * sourceHeight]; Coord bsize = new Coord (sourceWidth, sourceHeight); Coord bpos = new Coord (0, 0); SmallRect region = new SmallRect (sourceLeft, sourceTop, sourceLeft + sourceWidth - 1, sourceTop + sourceHeight - 1); fixed (void *ptr = &buffer [0]) { if (!ReadConsoleOutput (outputHandle, ptr, bsize, bpos, ref region)) throw new ArgumentException (String.Empty, "Cannot read from the specified coordinates."); } int written; short attr = GetAttrForeground (0, sourceForeColor); attr = GetAttrBackground (attr, sourceBackColor); bpos = new Coord (sourceLeft, sourceTop); for (int i = 0; i < sourceHeight; i++, bpos.Y++) { FillConsoleOutputCharacter (outputHandle, sourceChar, sourceWidth, bpos, out written); FillConsoleOutputAttribute (outputHandle, attr, sourceWidth, bpos, out written); } bpos = new Coord (0, 0); region = new SmallRect (targetLeft, targetTop, targetLeft + sourceWidth - 1, targetTop + sourceHeight - 1); if (!WriteConsoleOutput (outputHandle, buffer, bsize, bpos, ref region)) throw new ArgumentException (String.Empty, "Cannot write to the specified coordinates."); }
public void Clear () { Coord coord = new Coord (); ConsoleScreenBufferInfo info = new ConsoleScreenBufferInfo (); GetConsoleScreenBufferInfo (outputHandle, out info); int size = info.Size.X * info.Size.Y; int written; FillConsoleOutputCharacter (outputHandle, ' ', size, coord, out written); GetConsoleScreenBufferInfo (outputHandle, out info); FillConsoleOutputAttribute (outputHandle, info.Attribute, size, coord, out written); SetConsoleCursorPosition (outputHandle, coord); }
private static extern int GetConsoleScreenBufferInfo(int hConsoleOutput, ref ConsoleScreenBufferInfo lpConsoleScreenBufferInfo);
static bool GetConsoleScreenBufferInfo (IntPtr handle, out ConsoleScreenBufferInfo info) { throw new System.NotImplementedException(); }
static extern bool GetConsoleScreenBufferInfo(IntPtr consoleOutput, out ConsoleScreenBufferInfo info);
static bool GetConsoleScreenBufferInfo(IntPtr handle, out ConsoleScreenBufferInfo info) { throw new System.NotImplementedException(); }
internal static extern bool GetConsoleScreenBufferInfo( IntPtr hConsoleOutput, out ConsoleScreenBufferInfo lpConsoleScreenBufferInfo);
private static extern IntPtr GetStdHandle(Handles handle); // 0x0000000180A78210-0x0000000180A782A0 private static extern bool GetConsoleScreenBufferInfo(IntPtr handle, out ConsoleScreenBufferInfo info); // 0x0000000180A78170-0x0000000180A78210
/// <summary> /// Returns the number of columns in the current console window /// </summary> /// <returns> Returns the number of columns in the current console window </returns> private static int GetConsoleWindowWidth() { ConsoleScreenBufferInfo csbi = new ConsoleScreenBufferInfo(); GetConsoleScreenBufferInfo(GetStdHandle(StdOutputHandle), ref csbi); int screenWidth = csbi.dwSize.x; return screenWidth; }
public WindowsConsoleDriver () { outputHandle = GetStdHandle (Handles.STD_OUTPUT); inputHandle = GetStdHandle (Handles.STD_INPUT); ConsoleScreenBufferInfo info = new ConsoleScreenBufferInfo (); GetConsoleScreenBufferInfo (outputHandle, out info); defaultAttribute = info.Attribute; // Not sure about this... }
extern static bool GetConsoleScreenBufferInfo(IntPtr handle, out ConsoleScreenBufferInfo info);
public static extern bool GetConsoleScreenBufferInfo(IntPtr hOut, out ConsoleScreenBufferInfo csbi);