Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- void ClearScreen() {
- HANDLE hStdOut;
- CONSOLE_SCREEN_BUFFER_INFO csbi;
- SMALL_RECT scrollRect;
- COORD scrollTarget;
- CHAR_INFO fill;
- hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- // Get the number of character cells in the current buffer.
- if (!GetConsoleScreenBufferInfo(hStdOut, &csbi))
- {
- return;
- }
- // Scroll the rectangle of the entire buffer.
- scrollRect.Left = 0;
- scrollRect.Top = 0;
- scrollRect.Right = csbi.dwSize.X;
- scrollRect.Bottom = csbi.dwSize.Y;
- // Scroll it upwards off the top of the buffer with a magnitude of the entire height.
- scrollTarget.X = 0;
- scrollTarget.Y = (SHORT)(0 - csbi.dwSize.Y);
- // Fill with empty spaces with the buffer's default text attribute.
- fill.Char.UnicodeChar = TEXT(' ');
- fill.Attributes = csbi.wAttributes;
- // Do the scroll
- ScrollConsoleScreenBuffer(hStdOut, &scrollRect, NULL, scrollTarget, &fill);
- // Move the cursor to the top left corner too.
- csbi.dwCursorPosition.X = 0;
- csbi.dwCursorPosition.Y = 0;
- SetConsoleCursorPosition(hStdOut, csbi.dwCursorPosition);
- }
Add Comment
Please, Sign In to add comment