Color changing

This is a discussion on Color changing within the C++ Programming forums, part of the General Programming Boards category; Ok I looked around the site and searched a few things on google. I couldnt figure out how to change ...

  1. #1
    Codigious FingerPrint's Avatar
    Join Date
    Mar 2006
    Posts
    60

    Color changing

    Ok I looked around the site and searched a few things on google. I couldnt figure out how to change the color of the text that displays on the screen of a program. Im currently working on the main menu potion of a game, and I want to change some of the text color so its easier to read.

    Like when someone presses an incorrect key, text appears saying that it was incorrect and they need to enter another key. I would like that to be red or something, so it sticks out a bit more. I gave it pretty good spacing, but some people might not see it and just think the program is repeating itself for no reason.

    If anyoen could explain here how to do this, or give me a link to smowhere that can..it would be much appreciated. Thank you.

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    That's OS specific. Assuming windows:

    http://www.adrianxw.dk/SoftwareSite/...Consoles4.html

    In Linux your best bet would be ncurses.
    Last edited by SlyMaelstrom; 03-26-2006 at 10:36 PM.
    Sent from my iPadŽ

  3. #3
    Codigious FingerPrint's Avatar
    Join Date
    Mar 2006
    Posts
    60
    Ah, hey thanks man. That helps qutie a bit. I aprreciate that!

  4. #4
    Codigious FingerPrint's Avatar
    Join Date
    Mar 2006
    Posts
    60
    Oooo...um I ran into a snag with that. Ok, I added the color coding to my program. Then I pressed the wrong key perpusly to test it. I have it set so that when a wrong key is pressed the error message shows up, and then it shows the options agian. With the color code in there, when the wrong key is pressed the error message and the repeated options are red. How do I get it to not show the options as being red? Here is the code just incase you need it(also I didnt add in the return 0; because that just closes the program)

    Code:
    {
                  SetConsoleTextAttribute(hOut,
                                FOREGROUND_RED |
                                FOREGROUND_INTENSITY);
                  cout << "Sorry, that is not a proper selection. Please choose again.\n\n\n\n" << endl;
             }
    I dont know if that'l help, but jsut incase it does, its there. Also all the text that appears after that shows up red.

  5. #5
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,074
    Yes, that's because you're changing the colors permenantly. All further output will be in that color, therefor, after you're done outputting the error message, you have to change the color back to normal.
    Sent from my iPadŽ

  6. #6
    Codigious FingerPrint's Avatar
    Join Date
    Mar 2006
    Posts
    60
    lol I guess I didnt really think of that. I got it now, thanks man.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21