Scrolling a Screen Buffer's Window

The SetConsoleWindowInfo function can be used to scroll the contents of a screen buffer in the console window. This function can also change the window size. The function can either specify the new upper left and lower right corners of the screen buffer's window as absolute screen buffer coordinates or specify the changes from the current window coordinates. The function fails if the specified window coordinates are outside the boundaries of the screen buffer.

The following example scrolls the view of the screen buffer up one row by modifying the absolute window coordinates returned by the GetConsoleScreenBufferInfo function.

HANDLE hStdout;

CONSOLE_SCREEN_BUFFER_INFO csbiInfo;

SMALL_RECT srctWindow;

hStdout = GetStdHandle(STD_OUTPUT_HANDLE);

/* Get the current screen buffer size and window position. */

if (! GetConsoleScreenBufferInfo(hStdout, &csbiInfo))

MyErrorExit("GetConsoleScreenBufferInfo");

/* Set srctWindow to the current window size and location. */

srctWindow = csbiInfo.srWindow;

/* If window is not at the screen buffer top, move it up one line. */

if ( srctWindow.Top > 0 ) {

srctWindow.Top -= 1; /* move top up by one row */

srctWindow.Bottom -= 1; /* move bottom up by one row */

if (! SetConsoleWindowInfo(

hStdout, /* screen buffer handle */

TRUE, /* absolute coordinates */

&srctWindow)) /* specifies new location */

MyErrorExit("SetConsoleWindowInfo");

}

The same scrolling can be done by specifying changes in the window coordinates.

/* Get the current screen buffer window position. */

if (! GetConsoleScreenBufferInfo(hStdout, &csbiInfo))

MyErrorExit("GetConsoleScreenBufferInfo");

/*If window is not at the screen buffer top, move it up one line. */

if (csbiInfo.srWindow.Top > 0) {

srctWindow.Top = -1; /* move top up by one row */

srctWindow.Bottom = -1; /* move bottom up by one row */

srctWindow.Left = 0; /* no change */

srctWindow.Right = 0; /* no change */

if (! SetConsoleWindowInfo(

hStdout, /* screen buffer handle */

FALSE, /* deltas, not absolute */

&srctWindow)) /* specifies new location */

MyErrorExit("SetConsoleWindowInfo");

}

Software for developers
Delphi Components
.Net Components
Software for Android Developers
More information resources
MegaDetailed.Net
Unix Manual Pages
Delphi Examples
Databases for Amazon shops developers
Amazon Categories Database
Browse Nodes Database