Development/C/C++
TC::textattr() ↔ VC::SetConsoleTextAttribute() (윈도우 콘솔에서 글자 및 배경색 바꾸기)
키르히아이스
2011. 8. 13. 15:05
출처 :
+ SetConsoleTextAttribute() + |
VC++(console) 에서 TC++ :: textcolor() 의 기능을 원한다면
SetConsoleTextAttribute() 를 사용합니다.
나타낼수 있는 색상수는 마찬가지로 8bit 에 지나지 않습니다.
#include <windows.h>
#include <stdio.h>
const HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
inline int _drgb ( bool d, bool r, bool g, bool b)
{
return (d << 3) + (r << 2) + (g << 1) + (b << 0);
}
inline int _clr ( int fc, int bc )
{
return (fc << 0) + (bc << 4);
}
main()
{
int fore = _drgb (1,1,1,0);
int back = _drgb (0,1,0,1);
int color = _clr (fore,back);
SetConsoleTextAttribute ( h, color );
printf (" + SetConsoleTextAttribute() + ");
}