c언어 ms-dos 문자 색깔, 배경 색깔, 커서 위치 변경(gotoxy, settextcolor, getcolor, getbgcolor)

프로그래밍 언어/WinApi 2014. 5. 20. 16:10



ms-dos에서

문자, 배경색 바꾸기

커서 위치 변경






헤더파일 windows.h 를 찾지 못하는 경우

C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include

위치에 windows.h 가 있는지 확인하고 환경변수에 추가.



소스)


#include <stdio.h>

#include <windows.h>


void gotoxy(int, int);

void settextcolor(int, int);

int getcolor();

int getbgcolor();


int main()

{

int color;

int bgcolor;


color = getcolor();

bgcolor = getbgcolor();


gotoxy(5, 5);

settextcolor(10, 0);

printf("hello\n");


gotoxy(5, 6);

settextcolor(12, 0);

printf("hello\n");


settextcolor(color, bgcolor);


return 0;

}



// 커서 위치 변경

void gotoxy(int x, int y)

{

COORD Pos = {x, y};

SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),Pos);

}



// 문자색, 배경색 변경.

void settextcolor(int color, int bgcolor)

{

color &= 0xF;

bgcolor &=0xF;

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), (bgcolor<<4|color));

}



// 문자색 얻기

int getcolor()

{

CONSOLE_SCREEN_BUFFER_INFO info;

int color;


GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);

color = info.wAttributes & 0xf;

return color;

}



// 배경색 얻기

int getbgcolor()

{

CONSOLE_SCREEN_BUFFER_INFO info;

int color;


GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);

color = (info.wAttributes & 0xf0) >> 4;

return color;

}

'프로그래밍 언어 > WinApi' 카테고리의 다른 글

Winapi) tooltip track이 안될 때  (0) 2014.11.28
Winapi) 소스에서 lib 추가하기  (0) 2014.11.27
영상처리 winapi 소스  (0) 2014.10.10
[WinApi]VFW함수 자료정리  (0) 2014.09.18
윈도우즈 API 정복 예제 소스  (0) 2014.07.13

설정

트랙백

댓글