rc-chuah

ClearScreen2

Mar 3rd, 2022 (edited)
678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. #include <windows.h>
  2.  
  3. void ClearScreen() {
  4.     HANDLE hStdOut;
  5.     CONSOLE_SCREEN_BUFFER_INFO csbi;
  6.     DWORD count;
  7.     DWORD cellCount;
  8.     COORD homeCoords = { 0, 0 };
  9.     hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  10.     if (hStdOut == INVALID_HANDLE_VALUE)
  11.     {
  12.         return;
  13.     }
  14.     /* Get the number of cells in the current buffer */
  15.     if (!GetConsoleScreenBufferInfo(hStdOut, &csbi))
  16.     {
  17.         return;
  18.     }
  19.     cellCount = csbi.dwSize.X *csbi.dwSize.Y;
  20.     /* Fill the entire buffer with spaces */
  21.     if (!FillConsoleOutputCharacter(hStdOut,
  22.                                     (TCHAR) ' ',
  23.                                     cellCount,
  24.                                     homeCoords,
  25.                                     &count))
  26.     {
  27.         return;
  28.     }
  29.     /* Fill the entire buffer with the current colors and attributes */
  30.     if (!FillConsoleOutputAttribute(hStdOut,
  31.                                     csbi.wAttributes,
  32.                                     cellCount,
  33.                                     homeCoords,
  34.                                     &count))
  35.     {
  36.         return;
  37.     }
  38.     /* Move the cursor home */
  39.     SetConsoleCursorPosition(hStdOut, homeCoords);
  40. }
Add Comment
Please, Sign In to add comment