Gold mine of Visual C++ tricks!
How to Set Console Text Color?
![]()
Getting bored with the black and white console? Did you ever wish to change the text or background color of console?

Image Courtesy – reginadowntown.
![]()
Yes! You can use the api – SetConsoleTextAttribute(). See the code snippet below.
// Set text color as Yellow with white background.
SetConsoleTextAttribute(
GetStdHandle( STD_OUTPUT_HANDLE ),
FOREGROUND_INTENSITY | // Set Text color
FOREGROUND_RED | FOREGROUND_GREEN | // Text color as Yellow.
BACKGROUND_INTENSITY | // Set Background color
BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE ); // White Bg.
![]()
Please note that you can mix red/green/blue constants to make new colors. Have fun.
![]()
Targeted Audience – Beginners.
| Print article | This entry was posted by Jijo Raj on March 29, 2009 at 6:09 pm, and is filed under Codeproject, Visual C++, Windows APIs. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
about 1 year ago
Hi. I tried it and it worked. Thanks a lot. Pretty bored of black and white… yeah.
about 1 year ago
Hi Josh,
Happy to know that you enjoyed it!
Keep watching!
Regards,
Jijo