program Project2;
{$APPTYPE CONSOLE}
uses
sysutils, windows;
var hStdout, hNewScreenBuffer : THandle;
srctReadRect, srctWriteRect : _SMALL_RECT;
coordBufSize, coordBufCoord : _COORD;
fSuccess : Boolean;
chiBuffer :
array[0..159]
of CHAR_INFO;
// [2][80]; <--
begin
hStdout := GetStdHandle(STD_OUTPUT_HANDLE);
hNewScreenBuffer := CreateConsoleScreenBuffer(GENERIC_READ
or GENERIC_WRITE, 0,
nil, CONSOLE_TEXTMODE_BUFFER,
nil);
if (hStdout = INVALID_HANDLE_VALUE)
or (hNewScreenBuffer = INVALID_HANDLE_VALUE)
then
raise Exception.Create('
CreateConsoleScreenBuffer: '+IntToStr(GetLastError));
if not SetConsoleActiveScreenBuffer(hNewScreenBuffer)
then
raise Exception.Create('
SetConsoleActiveScreenBuffer: '+IntToStr(GetLastError));
srctReadRect.Top := 0;
// top left: row 0, col 0
srctReadRect.Left := 0;
srctReadRect.Bottom := 1;
// bottom right: row 1, col 79
srctReadRect.Right := 79;
// The temporary buffer size is 2 rows x 80 columns
coordBufSize.Y := 2;
coordBufSize.X := 80;
// The top left destination cell of the temporary buffer is
// row 0, col 0.
coordBufCoord.X := 0;
coordBufCoord.Y := 0;
// Copy the block from the screen buffer to the temp. buffer.
fSuccess := ReadConsoleOutput(hStdout, @chiBuffer[0], coordBufSize, coordBufCoord, srctReadRect);
if not fSuccess
then
raise Exception.Create('
ReadConsoleOutput: '+IntToStr(GetLastError));
// Set the destination rectangle.
srctWriteRect.Top := 10;
// top lt: row 10, col 0
srctWriteRect.Left := 0;
srctWriteRect.Bottom := 11;
// bot. rt: row 11, col 79
srctWriteRect.Right := 79;
// Copy from the temporary buffer to the new screen buffer.
fSuccess := WriteConsoleOutput(hNewScreenBuffer, @chiBuffer[0], coordBufSize, coordBufCoord, srctWriteRect);
if not fSuccess
then
raise Exception.Create('
WriteConsoleOutput: '+IntToStr(GetLastError));
Sleep(5000);
// Nötig ????
// Restore the original active screen buffer.
if not SetConsoleActiveScreenBuffer(hStdout)
then
raise Exception.Create('
SetConsoleActiveScreenBuffer: '+IntToStr(GetLastError));
readln;
end.