Thread: Text color

  1. #16
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    522
    Code:
    SetConsoleTextAttribute(hStdout, FOREGROUND_RED | BACKGROUND_BLUE);
    You can mix as many as you like, enjoy.
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  2. #17
    Registered User
    Join Date
    Sep 2001
    Posts
    19
    ahhh....thank you
    Jacob Sheehy

  3. #18
    Registered User
    Join Date
    Sep 2001
    Posts
    19
    Ok, I just checked MSDN, and it says that SetConsoleTextAttribute only effects text printed after the call. "This function affects only text written after the function call." But this isn't true (or I'm just really confused.) The function will color all of the text on the screen, no matter when it was printed. What I'm trying to do is to color the headings and credits of my game, but not all of the rest of the text. But I can only get one color on the screen at a time. Here's the code I'm using:

    Code:
    	// set the colors
    	hStdout = GetStdHandle(STD_OUTPUT_HANDLE); 
    	SetConsoleTextAttribute(hStdout, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY); // yellow
    
    	// welcome the user
    	cout << "Welcome to my adventure game\n";
    	cout << "written by Jacob Sheehy\n\n";
        
    	SetConsoleTextAttribute(hStdout, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY); // white
    
    	// show the user a menu
    	cout << "Please make a choice.\n";
    	cout << "1. Create a Character/New Game\n";
    	cout << "2. Load a Character/Game\n";
    	cout << "3. Quit\n>";
    If I take out the second SetConsoleTextAttribute, then the menu is yellow, too, which looks bad. Basically, what I think is happening, is that the console colors all of text the color of the last call, even the text printed before. How can I make it so that it only colors some text? Thank you, and sorry for my ignorance.
    Jacob Sheehy

  4. #19
    Registered User
    Join Date
    Sep 2001
    Posts
    19
    I just realized I have to use printf() rather than cout.....thanks a bunch guys... No really, thanks
    Jacob Sheehy

  5. #20
    Registered User
    Join Date
    Mar 2002
    Posts
    30

    any1 know....

    .. my sleep goes to begining even if its at the middle?
    HOw are ya?

  6. #21
    Registered User
    Join Date
    Sep 2001
    Posts
    19
    Well, it depends on how you lie on your bed at night... huh? what sleep?
    Jacob Sheehy

  7. #22
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > I just realized I have to use printf() rather than cout.....
    That's C programming, not C++.
    Try searching google for such a common question.
    Try http://www.ProgrammersHeaven.com also.
    I believe they had a few tutorials or source code downloads.
    I messed around with one the other night..
    The world is waiting. I must leave you now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GUI Text Color Problem
    By justlivelife15 in forum Windows Programming
    Replies: 3
    Last Post: 06-25-2007, 05:47 AM
  2. Change text color in C
    By IndioDoido in forum C Programming
    Replies: 9
    Last Post: 04-15-2007, 05:54 AM
  3. Critique my lighting model.
    By psychopath in forum Game Programming
    Replies: 4
    Last Post: 08-12-2006, 06:23 PM
  4. Color text from windows.h?
    By Saintdog in forum C++ Programming
    Replies: 10
    Last Post: 12-03-2004, 09:20 AM
  5. Ok, Structs, I need help I am not familiar with them
    By incognito in forum C++ Programming
    Replies: 7
    Last Post: 06-29-2002, 09:45 PM