-
Clear Screen Code
Can someone please explain this function? I found it in one of the threads on this forum, but I can't decipher it.
Code:
void clrscr()
{
COORD coordScreen = { 0, 0 };
DWORD cCharsWritten;
CONSOLE_SCREEN_BUFFER_INFO csbi;
DWORD dwConSize;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole, &csbi);
dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten);
GetConsoleScreenBufferInfo(hConsole, &csbi);
FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten);
SetConsoleCursorPosition(hConsole, coordScreen);
}
Thanks in advance.
-
I do understand what it does, but not how it does it.
-
You can look up each function here. Like GetConsoleScreenBufferInfo().
Also, Windows specific questions should go on this message board.
gg
-
What don't you understand?
The screen of a console is simply a buffer of characters. What that code does is gets the buffer, replaces the buffers existing contents with spaces then homes the cursor.