Char Output Color

Numeri (32)
I have been trying to output characters in the console in colors other than the sixteen default colors that

SetConsoleTextAttribute( hstdout, 0xa );

will let you do, i.e.

1
2
3
4
5
6
7
8
0 = Black       8 = Gray
1 = Blue        9 = Light Blue
2 = Green       A = Light Green
3 = Aqua        B = Light Aqua
4 = Red         C = Light Red
5 = Purple      D = Light Purple
6 = Yellow      E = Light Yellow
7 = White       F = Bright White


I want to specify the color with RGB values.

I tried using this,

1
2
3
COLORREF B = RGB(100,0,0);

SetConsoleTextAttribute( hstdout, B );	


but it did the text w/ red foreground and yellow background, not just the regular black background!

Thanks so much!

Numeri

Last edited on
Numeri (32)
Bump.
coder777 (2378)
Look at this:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms686047%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682088%28v=vs.85%29.aspx#_win32_character_attributes

the console is limited when it comes to (more or less) graphical output. Try using a gui
Duoas (6734)
You are limited to 16 distinct colors at any one time, but you can actually modify the colors used. See SetConsoleScreenBufferInfoEx()
http://www.google.com/search?btnI=1&q=msdn+SetConsoleScreenBufferInfoEx

(Check out the ColorTable in the CONSOLE_SCREEN_BUFFER_INFOEX structure.)

Good luck!
Topic archived. No new replies allowed.