Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- void ClearScreen() {
- HANDLE hStdOut;
- COORD coordScreen = { 0, 0 }; // home for the cursor
- DWORD cCharsWritten;
- CONSOLE_SCREEN_BUFFER_INFO csbi;
- DWORD dwConSize;
- hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- // Get the number of character cells in the current buffer.
- if (!GetConsoleScreenBufferInfo(hStdOut, &csbi))
- {
- return;
- }
- dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
- // Fill the entire screen with blanks.
- if (!FillConsoleOutputCharacter(hStdOut, // Handle to console screen buffer
- (TCHAR)' ', // Character to write to the buffer
- dwConSize, // Number of cells to write
- coordScreen, // Coordinates of first cell
- &cCharsWritten)) // Receive number of characters written
- {
- return;
- }
- // Get the current text attribute.
- if (!GetConsoleScreenBufferInfo(hStdOut, &csbi))
- {
- return;
- }
- // Set the buffer's attributes accordingly.
- if (!FillConsoleOutputAttribute(hStdOut, // Handle to console screen buffer
- csbi.wAttributes, // Character attributes to use
- dwConSize, // Number of cells to set attribute
- coordScreen, // Coordinates of first cell
- &cCharsWritten)) // Receive number of characters written
- {
- return;
- }
- // Put the cursor at its home coordinates.
- SetConsoleCursorPosition(hStdOut, coordScreen);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement