Win32 Color in Console Mode
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!!
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.
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.
This is a good place to start. I suggest you use WriteConsoleAttribute.
"A society without religion is like a crazed psychopath without a loaded .45"
"A society without religion is like a crazed psychopath without a loaded .45"
I think this should do it .. fills the window with red ...
Edited by - Martee on October 19, 2001 7:48:23 PM
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
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.
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.
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"
"A society without religion is like a crazed psychopath without a loaded .45"
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"
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement