View Single Post
Join Date: May 2006
Posts: 1
Reputation: Brian The Mad is an unknown quantity at this point 
Solved Threads: 0
Brian The Mad Brian The Mad is offline Offline
Newbie Poster

Re: Change text color using visual c++

 
0
  #4
May 4th, 2006
Originally Posted by hail2dthief
I'm using visual c++ compiler and I want to change the text color in my c++ dos program. What choices do I have if i don't wanna use system function (example: system("color 0a"))?
  1. #define BLACK 0
  2. #define BLUE 1
  3. #define GREEN 2
  4. #define CYAN 3
  5. #define RED 4
  6. #define MAGENTA 5
  7. #define BROWN 6
  8. #define LIGHTGREY 7
  9. #define DARKGREY 8
  10. #define LIGHTBLUE 9
  11. #define LIGHTGREEN 10
  12. #define LIGHTCYAN 11
  13. #define LIGHTRED 12
  14. #define LIGHTMAGENTA 13
  15. #define YELLOW 14
  16. #define WHITE 15
  17. #define BLINK 128
  18. HANDLE screen;
  19. int textcolor = LIGHTGREEN;
  20. int backgroundcolor = BLACK;
  21. screen = GetStdHandle(STD_OUTPUT_HANDLE);
  22. void TextColor(int fontcolor,int backgroundcolor,HANDLE screen)
  23. {
  24. int color_attribute;
  25. color_attribute = backgroundcolor;
  26. color_attribute = _rotl(color_attribute,4) | fontcolor;
  27. SetConsoleTextAttribute(screen,color_attribute);
  28. }
  29.  
  30. TextColor(textcolor,backgroundcolor ,screen);
  31. FillConsoleOutputAttribute(screen, _rotl(backgroundcolor,4) , 80 * 50,coord , &cWritten);


This works in Microsoft c++
Reply With Quote