/// <summary> /// Sets the active console screen buffer to the buffer referrenced by the sb parameter /// </summary> /// <param name="sb">The screen buffer that will become the active screen buffer.</param> public static void SetActiveScreenBuffer(ConsoleScreenBuffer sb) { if (!WinCon.SetConsoleActiveScreenBuffer(sb.Handle)) { throw new IOException("Error setting active screen buffer.", Marshal.GetLastWin32Error()); } }
public string ReadAll() { AttachConsole(_process.Id); _outputBuffer = GetActiveScreenBuffer(); var builder = new StringBuilder(_outputBuffer.Width * _outputBuffer.Height); for (int i = 0; i < _outputBuffer.CursorTop + 1; i++) { bool isLastLine = i == _outputBuffer.CursorTop; if (isLastLine) { builder.Append(Read(i, _outputBuffer.CursorLeft)); return builder.ToString(); } builder.Append(Read(i, _outputBuffer.Width)); } return builder.ToString(); }