當(dāng)我回想起來我剛剛學(xué)習(xí)C語言,Turbo C2.0提供的豐富的函數(shù),可以讓枯燥的文本界面,顯示出花花綠綠的文字界面。在windows時代,這些函數(shù)都不在標(biāo)準(zhǔn)庫中。不過WINAPI可以幫你實現(xiàn)。
代碼很簡單,不用多作解釋了
#include <windows.h>
#include <string>
#include <ctime>
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");
}
#include <string>
#include <ctime>
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");
}
代碼很簡單,不用多作解釋了