C++콘 솔(명령 행)창 커서 위치 및 앞 배경 색 설정
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
/*
#define FOREGROUND_BLUE 0x0001 // text color contains blue.
#define FOREGROUND_GREEN 0x0002 // text color contains green.
#define FOREGROUND_RED 0x0004 // text color contains red.
#define FOREGROUND_INTENSITY 0x0008 // text color is intensified.
#define BACKGROUND_BLUE 0x0010 // background color contains blue.
#define BACKGROUND_GREEN 0x0020 // background color contains green.
#define BACKGROUND_RED 0x0040 // background color contains red.
#define BACKGROUND_INTENSITY 0x0080 // background color is intensified.
*/
// ( / )
void ColorPrintf(WORD cl,char* str)
{
static HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );
//WORD wOldColorAttrs;
//CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
//First save the current color information
//GetConsoleScreenBufferInfo(h, &csbiInfo);
//wOldColorAttrs = csbiInfo.wAttributes;
//Set the new color information
SetConsoleTextAttribute ( h, cl );
printf ( str);
//Restore the original colors
//SetConsoleTextAttribute ( h, wOldColorAttrs);
SetConsoleTextAttribute(h, FOREGROUND_INTENSITY | FOREGROUND_INTENSITY);
}
//
void MoveCursorTo(int x,int y)
{
static HANDLE m=GetStdHandle(STD_OUTPUT_HANDLE);
COORD cp={x,y};
SetConsoleCursorPosition(m,cp);
}
int main ( void )
{
char st[10];
ColorPrintf (FOREGROUND_BLUE | FOREGROUND_INTENSITY, "This is a color test
" );
for (int j=0;j<255;j+=16)
{
for (int i=0;i<16;i++)
{
sprintf(st,"%02x ",j+i);
ColorPrintf(j+i,st);
}
printf("
");
}
//printf("
");
//MoveCursorTo( 1, 9 );
//ColorPrintf(0x0083,"This is a test
");
return 0;
}터미널/콘 솔 색상 글꼴,커서 위치 확인 및 화면 정리 설정printf("\033[47;31mhello world\033[5m");
47 은 글자 배경 색 이 고 31 은 글꼴 색 이 며 hello World 는 문자열 입 니 다.뒤의\033[5m 는 제어 코드 입 니 다.
색상 코드:
QUOTE:
글자 배경 색상 범위:40-49 글자 색상:30-39
40:흑 30:흑
41:레 드 31:레 드
42:녹색 32:녹색
43:황 33:황
44:파랑 34:파랑
45:자색 35:자색
46:진 한 녹색 36:진 한 녹색
47:흰색 37:흰색
ANSI 제어 코드:
QUOTE:
\033[0m 모든 속성 닫 기
\033[1m 밝기 설정
밑줄
\033[5m 깜빡 임
033[7m 반 현
\033[8m 소 은
\033[30m]\033[37m 전경 치 설정
\033[40m]\033[47m 배경 색 설정
\033[nA 커서 n 줄 위로 이동
\03[nB 커서 n 줄 아래로 이동
\033[nC 커서 오른쪽으로 n 줄 이동
\033[nD 커서 왼쪽으로 n 줄 이동
\033[y;xH 커서 위치 설정
\033[2J 클 리 어 스크린
\033[K 커서 에서 줄 끝까지 내용 지우 기
\033[s 커서 위치 저장
\033[u 커서 위치 복원
\033[?25l 커서 숨 기기
\33[?25h 디 스 플레이 커서
이렇게 하면 어떤 때 는 동적 출력 을 실현 할 수 있다.