//hàm chỉnh màu chữ
void textcolor(WORD color)
{
HANDLE hConsoleOutput;
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO screen_buffer_info;
GetConsoleScreenBufferInfo(hConsoleOutput, &screen_buffer_info);
WORD wAttributes = screen_buffer_info.wAttributes;
color &= 0x000f;
wAttributes &= 0xfff0;
wAttributes |= color;
SetConsoleTextAttribute(hConsoleOutput, wAttributes);
}
//cách sử dụng
muốn in ra màn hình chữ có màu gì thì gọi hàm textcolor({màu}) trước khi gọi hàm printf. Ví dụ ở trên a muốn in ra dòng chữ màu hồng thì làm như sau:
textcolor(13);
printf("DO AN 1 - 1212390\n");
màu chữ ở đây là một số thập phân, lâu quá rồi nên a quên màu nào là số nào rồi, h chỉ còn biết ngồi thử thôi..kkkk..như hình trên thì hầu hết là nằm trong khoảng [9, 15], còn màu khác a chưa thử...=))