View Single Post
Join Date: Apr 2005
Posts: 1,419
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 229
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: Change text color using visual c++

 
0
  #6
Sep 26th, 2007
I used this one to save me some time
This is not Visual C++ dependant, I use this with DEv-C++ as well, you just need the windows header
  1. enum Colors { blue=1, green, cyan, red, purple, yellow, grey, dgrey, hblue, hgreen, hred, hpurple, hyellow, hwhite };
  2.  
  3. void coutc(int color, char* output)
  4. {
  5. HANDLE handle= GetStdHandle(STD_OUTPUT_HANDLE);
  6. SetConsoleTextAttribute( handle, color);
  7. cout<< output;
  8. SetConsoleTextAttribute( handle, color);
  9. }

Then to output in color you would just do
  1. coutc(red, "This is in red!");
  2. coutc(purple, "This is purple!");
Last edited by ShawnCplus; Sep 26th, 2007 at 5:48 pm.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote