C/C++ 언어 콘솔에서 텍스트에 색깔 적용하기


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <windows.h>
#include <conio.h>
#include <stdio.h>
 
void main(void) {
  int color;
  int bgcolor;
  int i;
 
  COORD pos;
  HANDLE ghOutput;
 
  system("cls");
 
  ghOutput = GetStdHandle(STD_OUTPUT_HANDLE);
 
  for(i = 0;i < 16;i++) {
    pos.X=(SHORT)i;
    pos.Y=(SHORT)i;
 
    SetConsoleCursorPosition(ghOutput,pos);
 
    color = i;
    bgcolor = 0;
 
    color &= 0x0F;
    bgcolor &= 0x0F;
    bgcolor <<= 4;
    SetConsoleTextAttribute(ghOutput,bgcolor|color);
 
    printf("color number : %d\n",i);
  }
}
cs


C/C++ 언어 콘솔에서 텍스트에 색깔 적용하기



+ Recent posts