Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

randomDecay

Win32 Color in Console Mode

This topic is 6121 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I want to use colors in my program for my text and fill the entire portion of the console with a specific color. Can any one help me out!!

Share this post


Link to post
Share on other sites
Advertisement
To output red text:
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(consoleHandle, FOREGROUND_RED);
To output blue or green text, replace FOREGROUND_RED with FOREGROUND_GREEN or FOREGROUND_BLUE. You can also combine colors by using something like FOREGROUND_RED | FOREGROUND_BLUE to get purple.

Share this post


Link to post
Share on other sites
I think this should do it .. fills the window with red ...
    
CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD numCharactersWritten;
COORD consoleCoords = {0, 0};
SetConsoleTextAttribute(consoleHandle, BACKGROUND_RED);
GetConsoleScreenBufferInfo(consoleHandle, &consoleInfo);
FillConsoleOutputCharacter(consoleHandle, ' ', consoleInfo.dwSize.X * consoleInfo.dwSize.Y,
consoleCoords, &numCharactersWritten);
FillConsoleOutputAttribute(consoleHandle, consoleInfo.wAttributes, consoleInfo.dwSize.X * consoleInfo.dwSize.Y,
consoleCoords, &numCharactersWritten);


Edited by - Martee on October 19, 2001 7:48:23 PM

Share this post


Link to post
Share on other sites
One more quick q...

I have one line at the top of the window with a blue background and white text for the player''s score and name. How would I keep that there for the entire program, and have it stay at the top while the rest of the program keeps going below it.

Share this post


Link to post
Share on other sites
Martee: Using WriteConsoleAttribute would let you set the color independently, without having to write to the cells.

"A society without religion is like a crazed psychopath without a loaded .45"

Share this post


Link to post
Share on other sites
quote:
Original post by Martee
Ahh, cool. Thanks for the tip. We learn something new every day


No point in getting out of bed otherwise

"A society without religion is like a crazed psychopath without a loaded .45"

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!