#include <windows.h> // WinApi header
int setcolor(int k)
{
HANDLE hConsole; //핸들러 정의
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);//핸들러 생성
SetConsoleTextAttribute(hConsole, k);//값 셋팅 k 값에 맞는 색상이 출력)
return 0;
}
예제
#include <stdio.h>
#include <windows.h> // WinApi header
int main()
{
HANDLE hConsole;
int k;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
// you can loop k higher to see more color choices
for(k = 1; k < 10; k++)
{
SetConsoleTextAttribute(hConsole, k);
printf("%3d %s\n", k, "I want to be nice today!");
}
getchar(); // wait
return 0;
}