color problems with text
I know this is a FAQ, but none of the other posts have the answer im looking for. I was wondering how to change the color of the text as follows:
lets say that this is what the program displayed:
this is blue //in a blue color
this is darker blue //guess what? a darker blue color
this is red //i think you can figure this out by yourself...
this is darker red
this is standard white
this is green
this is darker green
I have read the other posts on this and they all suggest an alternative approach that i found to be very un-reliable (as in the colors would change without me telling the to) and you couldnt switch the color back to white... Is this possible and how can i do it?
if you're using the windows dos-console then
red baron's game "dungeon of moria" will
be a very good example for colored text mode... :)
i don't have a link by the hand, but i am sure you can
find a post of red baron with the link in the signature
um... ok... i am using microsoft C++ (on a pc...) if anyone is wondering.
P.S. that whole red barron thing isnt very helpful without a link...
and i'm pretty sure you have to #include <conio.h>
SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), 8 | FOREGROUND_INTENSITY);
the number 8 is what you'll change to get a different color. 0 is black and so forth. take out | FOREGROUND_INTENSITY if you don't want the colors to be bright.
btw, there are tons of posts about this here.:)
i have heard of that b4, and actually saw it in a thread, but i didnt know you could use numbers! Thanx a lot, ill try it
um... ya... error heaven. Here is what my compiler thinks of this
: error C2065: 'SetConsoleTextAttribute' : undeclared identifier
: error C2065: 'GetStdHandle' : undeclared identifier
: error C2065: 'STD_OUTPUT_HANDLE' : undeclared identifier
: error C2065: 'FOREGROUND_INTENSITY' : undeclared identifier
what the HECK is wrong here?
did you #include <conio.h>?
and by the way here is a site that lists all of the ascii code descriptions.
ok i figured it out, its #include <windows.h>, but thats not the problem. The problem is that after a while of changing color, the color goes wako and reverts to the origianl grey-ish annoying thing. What did i do wrong? Another thing thats wierd is that only PARTS of the text changes color for instance:
Title <--supposed to be blue, but is normal grey
wannanno! whoop whoop wh/*it turns completly white here*/oop whoop! wa/*it turns back to normal grey here*/nnanno!
you can go left <---- supposed to be blue, but in normal grey
It works for a bit then does this
Try including <stdio.h>, and make sure to code in the following (above where you start changing colors)
That normally works for me. And I think you have to use printf instead of cout, or something bad happens (don't remember what).
i advise that if you use \n its not a good idea cause it colours the whole line that colour and make sure you put the set colour command before typing in a line for all lines. and just for the hell of it check out the attachment and if you have time my game ;) good luck
ps if it still does not work post a bit of your code instead of only the output
red baron's code snippet works very well ! :)
hm..... this is getting bad because it is still not working... Here is my code (yes i know, it is very confusing, but maybe somebody a little bit brighter than me can see the problem)
One more thing b4 i show the code... how do i put it in that nice little thig that say "code:" becuase what i will post is about 100 lines...
code goes here
you have to remove the quotation marks.