Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define NOMINMAX
- #define WIN32_LEAN_AND_MEAN
- #include <Windows.h>
- #include <iostream>
- void cls()
- {
- // Get the Win32 handle representing standard output.
- // This generally only has to be done once, so we make it static.
- static const HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
- CONSOLE_SCREEN_BUFFER_INFO csbi;
- COORD topLeft = { 0, 0 };
- // std::cout uses a buffer to batch writes to the underlying console.
- // We need to flush that to the console because we're circumventing
- // std::cout entirely; after we clear the console, we don't want
- // stale buffered text to randomly be written out.
- std::cout.flush();
- // Figure out the current width and height of the console window
- if (!GetConsoleScreenBufferInfo(hOut, &csbi)) {
- // TODO: Handle failure!
- abort();
- }
- DWORD length = csbi.dwSize.X * csbi.dwSize.Y;
- DWORD written;
- // Flood-fill the console with spaces to clear it
- FillConsoleOutputCharacter(hOut, TEXT(' '), length, topLeft, &written);
- // Reset the attributes of every character to the default.
- // This clears all background colour formatting, if any.
- FillConsoleOutputAttribute(hOut, csbi.wAttributes, length, topLeft, &written);
- // Move the cursor back to the top left for the next sequence of writes
- SetConsoleCursorPosition(hOut, topLeft);
- }
- // x is the column, y is the row. The origin (0,0) is top-left.
- void setCursorPosition(int x, int y)
- {
- static const HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
- std::cout.flush();
- COORD coord = { (SHORT)x, (SHORT)y };
- SetConsoleCursorPosition(hOut, coord);
- }
- /* Trying to design a ship for ASCII art im just grabbing from text art
- this one is called sjw for some dumb reason T_T
- but its the samllest one they had
- /\
- ( )
- ( )
- /|/\|\
- /_||||_\
- */
- void setConsoleColour(unsigned short colour)
- {
- static const HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
- std::cout.flush();
- SetConsoleTextAttribute(hOut, colour);
- }
- int main(int argc, int argv[])
- {
- // Step through with a debugger, or insert sleeps, to see the effect.
- setCursorPosition(10, 5);
- std::cout << "CHEESE";
- setCursorPosition(10, 5);
- std::cout << 'W';
- setCursorPosition(10, 9);
- std::cout << 'Z';
- setCursorPosition(10, 5);
- std::cout << " "; // Overwrite characters with spaces to "erase" them
- std::cout.flush();
- // Voilà, 'CHEESE' converted to 'WHEEZE', then all but the last 'E' erased
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement