rc-chuah

ClearScreen4

Mar 3rd, 2022 (edited)
849
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.14 KB | None | 0 0
  1. #include <windows.h>
  2.  
  3. void ClearScreen() {
  4.     HANDLE hStdOut;
  5.     CONSOLE_SCREEN_BUFFER_INFO csbi;
  6.     SMALL_RECT scrollRect;
  7.     COORD scrollTarget;
  8.     CHAR_INFO fill;
  9.     hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  10.     // Get the number of character cells in the current buffer.
  11.     if (!GetConsoleScreenBufferInfo(hStdOut, &csbi))
  12.     {
  13.         return;
  14.     }
  15.     // Scroll the rectangle of the entire buffer.
  16.     scrollRect.Left = 0;
  17.     scrollRect.Top = 0;
  18.     scrollRect.Right = csbi.dwSize.X;
  19.     scrollRect.Bottom = csbi.dwSize.Y;
  20.     // Scroll it upwards off the top of the buffer with a magnitude of the entire height.
  21.     scrollTarget.X = 0;
  22.     scrollTarget.Y = (SHORT)(0 - csbi.dwSize.Y);
  23.     // Fill with empty spaces with the buffer's default text attribute.
  24.     fill.Char.UnicodeChar = TEXT(' ');
  25.     fill.Attributes = csbi.wAttributes;
  26.     // Do the scroll
  27.     ScrollConsoleScreenBuffer(hStdOut, &scrollRect, NULL, scrollTarget, &fill);
  28.     // Move the cursor to the top left corner too.
  29.     csbi.dwCursorPosition.X = 0;
  30.     csbi.dwCursorPosition.Y = 0;
  31.     SetConsoleCursorPosition(hStdOut, csbi.dwCursorPosition);
  32. }
Add Comment
Please, Sign In to add comment