ScrollConsoleScreenBuffer function
Important
This document describes console platform functionality that is no longer a part of our ecosystem roadmap. We do not recommend using this content in new products, but we will continue to support existing usages for the indefinite future. Our preferred modern solution focuses on virtual terminal sequences for maximum compatibility in cross-platform scenarios. You can find more information about this design decision in our classic console vs. virtual terminal document.
Moves a block of data in a screen buffer. The effects of the move can be limited by specifying a clipping rectangle, so the contents of the console screen buffer outside the clipping rectangle are unchanged.
Syntax
BOOL WINAPI ScrollConsoleScreenBuffer(
_In_ HANDLE hConsoleOutput,
_In_ const SMALL_RECT *lpScrollRectangle,
_In_opt_ const SMALL_RECT *lpClipRectangle,
_In_ COORD dwDestinationOrigin,
_In_ const CHAR_INFO *lpFill
);
Parameters
hConsoleOutput [in]
A handle to the console screen buffer. The handle must have the GENERIC_READ access right. For more information, see Console Buffer Security and Access Rights.
lpScrollRectangle [in]
A pointer to a SMALL_RECT structure whose members specify the upper-left and lower-right coordinates of the console screen buffer rectangle to be moved.
lpClipRectangle [in, optional]
A pointer to a SMALL_RECT structure whose members specify the upper-left and lower-right coordinates of the console screen buffer rectangle that is affected by the scrolling. This pointer can be NULL.
dwDestinationOrigin [in]
A COORD structure that specifies the upper-left corner of the new location of the lpScrollRectangle contents, in characters.
lpFill [in]
A pointer to a CHAR_INFO structure that specifies the character and color attributes to be used in filling the cells within the intersection of lpScrollRectangle and lpClipRectangle that were left empty as a result of the move.
Return value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
ScrollConsoleScreenBuffer copies the contents of a rectangular region of a screen buffer, specified by the lpScrollRectangle parameter, to another area of the console screen buffer. The target rectangle has the same dimensions as the lpScrollRectangle rectangle with its upper-left corner at the coordinates specified by the dwDestinationOrigin parameter. Those parts of lpScrollRectangle that do not overlap with the target rectangle are filled in with the character and color attributes specified by the lpFill parameter.
The clipping rectangle applies to changes made in both the lpScrollRectangle rectangle and the target rectangle. For example, if the clipping rectangle does not include a region that would have been filled by the contents of lpFill, the original contents of the region are left unchanged.
If the scroll or target regions extend beyond the dimensions of the console screen buffer, they are clipped. For example, if lpScrollRectangle is the region contained by (0,0) and (19,19) and dwDestinationOrigin is (10,15), the target rectangle is the region contained by (10,15) and (29,34). However, if the console screen buffer is 50 characters wide and 30 characters high, the target rectangle is clipped to (10,15) and (29,29). Changes to the console screen buffer are also clipped according to lpClipRectangle, if the parameter specifies a SMALL_RECT structure. If the clipping rectangle is specified as (0,0) and (49,19), only the changes that occur in that region of the console screen buffer are made.
This function uses either Unicode characters or 8-bit characters from the console's current code page. The console's code page defaults initially to the system's OEM code page. To change the console's code page, use the SetConsoleCP or SetConsoleOutputCP functions. Legacy consumers may also use the chcp or mode con cp select= commands, but it is not recommended for new development.
Tip
This API is not recommended and does not have a virtual terminal equivalent. Use can be approximated with scroll margins to fix an area of the screen, cursor positioning to set the active position outside the region, and newlines to force text to move. The remaining space can be filled by moving the cursor, setting graphical attributes, and writing normal text.
Examples
For an example, see Scrolling a Screen Buffer's Contents.
Requirements
Minimum supported client | Windows 2000 Professional [desktop apps only] |
Minimum supported server | Windows 2000 Server [desktop apps only] |
Header | ConsoleApi2.h (via WinCon.h, include Windows.h) |
Library | Kernel32.lib |
DLL | Kernel32.dll |
Unicode and ANSI names | ScrollConsoleScreenBufferW (Unicode) and ScrollConsoleScreenBufferA (ANSI) |