Created
January 23, 2014 00:56
-
-
Save kaecy/8570737 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <windows.h> | |
| #include <cstdio> | |
| /* Standard error macro for reporting API errors */ | |
| #define PERR(bSuccess, api){if(!(bSuccess)) printf("%s:Error %d from %s \ | |
| on line %d\n", __FILE__, GetLastError(), api, __LINE__);} | |
| void clear( HANDLE hConsole ) | |
| { | |
| COORD coordScreen = { 0, 0 }; /* here's where we'll home the | |
| cursor */ | |
| BOOL bSuccess; | |
| DWORD cCharsWritten; | |
| CONSOLE_SCREEN_BUFFER_INFO csbi; /* to get buffer info */ | |
| DWORD dwConSize; /* number of character cells in | |
| the current buffer */ | |
| /* get the number of character cells in the current buffer */ | |
| bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi ); | |
| PERR( bSuccess, "GetConsoleScreenBufferInfo" ); | |
| dwConSize = csbi.dwSize.X * csbi.dwSize.Y; | |
| /* fill the entire screen with blanks */ | |
| bSuccess = FillConsoleOutputCharacter( hConsole, (TCHAR) ' ', | |
| dwConSize, coordScreen, &cCharsWritten ); | |
| PERR( bSuccess, "FillConsoleOutputCharacter" ); | |
| /* get the current text attribute */ | |
| bSuccess = GetConsoleScreenBufferInfo( hConsole, &csbi ); | |
| PERR( bSuccess, "ConsoleScreenBufferInfo" ); | |
| /* now set the buffer's attributes accordingly */ | |
| bSuccess = FillConsoleOutputAttribute( hConsole, csbi.wAttributes, | |
| dwConSize, coordScreen, &cCharsWritten ); | |
| PERR( bSuccess, "FillConsoleOutputAttribute" ); | |
| /* put the cursor at (0, 0) */ | |
| bSuccess = SetConsoleCursorPosition( hConsole, coordScreen ); | |
| PERR( bSuccess, "SetConsoleCursorPosition" ); | |
| return; | |
| } | |
| int main() | |
| { | |
| clear(GetStdHandle(STD_OUTPUT_HANDLE)); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment