/********************************************************************************** * * * Copyright (c) by Royal. All rights reserved. * * * * Permission to use, copy, modify, and distribute this software for any purpose * * is hereby granted without fee, provided that this copyright and permissions * * notice appear in all copies and derivatives, and that no charge may be made * * for the software and its documentation except to cover cost of distribution. * * * * This software is provided "as is" without express or implied warranty. * * * **********************************************************************************/ /* * Description: * * A few Windows Console APIs could make your C++ programs cool:) * This code is excerpted from class dragon::wcui::Console. * * History: * * Initial version created by Royal, July, 2004. * * Notes: * * This code has been written to conform to standard C++ and STL. It has been * compiled successfully using GNU C++ 3.2 (MinGW), Borland C++ 5.5, and Visual C++ 7.0. * * OS: * Windows. */ #include #include #include enum Colors { BLACK = 0, BLUE = 1, DARK_GREEN = 2, LIGHT_BLUE = 3, RED = 4, PURPLE = 5, ORANGE = 6, GREY = 7, DARKER_GREY = 8, MEDIUM_BLUE = 9, LIGHT_GREEN = 10, TEAL = 11, RED_ORANGE = 12, LIGHT_PURPLE = 13, YELLOW = 14, WHITE = 15 }; void set_cursor(short x, short y) { COORD point = {x, y}; ::SetConsoleCursorPosition(::GetStdHandle(STD_OUTPUT_HANDLE), point); } void set_color(unsigned short color) { ::SetConsoleTextAttribute(::GetStdHandle(STD_OUTPUT_HANDLE), color); } void delay(unsigned int delay) { ::Sleep(delay); } void set_title(std::string title) { ::SetConsoleTitle(title.c_str()); } void show_cursor(bool show, int size = 25) { CONSOLE_CURSOR_INFO cci; if (size <= 0) size = 1; if (size > 100) size = 100; cci.dwSize = size; cci.bVisible = show; ::SetConsoleCursorInfo(::GetStdHandle(STD_OUTPUT_HANDLE), &cci); } void clear_screen() { system("cls"); }