Development/C/C++

TC::textattr() ↔ VC::SetConsoleTextAttribute() (윈도우 콘솔에서 글자 및 배경색 바꾸기)

키르히아이스 2011. 8. 13. 15:05

출처 :

http://kin.naver.com/detail/detail.php?d1id=1&dir_id=10104&eid=LmtmuaIfGw33jutBVLqNVDVX0amVAH7W&qb=xNy81iDA1LfCILHbwNo=&pid=fiDhowoi5UNssbAUwvZsss--316641&sid=SZlQGBNMmUkAAC%40XDwg

 

 


  + 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() + ");
  }