I need help to get a new way to clear the screen. I have researched for hours now and can not find a way to get it to work. I know how to use system("cls"). It is way too slow. Can someone please help.
void ClearScreen()
{
COORD coordScreen = {0, 0}; // home for the cursor
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
// Get the number of character cells in the current buffer.
if(!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
{
return;
}
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
// Fill the entire screen with blanks.
if(!FillConsoleOutputCharacter(GetStdHandle(STD_OUTPUT_HANDLE), (TCHAR) ' ', dwConSize, coordScreen, &cCharsWritten))
{
return;
}
// Get the current text attribute.
if(!GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
{
return;
}
// Set the buffer's attributes accordingly.
if(!FillConsoleOutputAttribute(GetStdHandle(STD_OUTPUT_HANDLE), csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten))
{
return;
}
// Put the cursor at its home coordinates.
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coordScreen);
}