C++ color console define

Started by
7 comments, last by guyaton 18 years, 8 months ago
I have looked on google for a little bit but I can't find anything on changing the color of text or other ascii symbols in a console progect. If you ahve a link you could pots or tell me how here that would be great thanks.
Advertisement
There is no standard way to do this in C++. You'll have to let us know what OS you are using. If it's windows, the info can probably be found at MSDN
I am using windows xp
More specifically this page should show you how to do it.

Also here are the Windows specific console functions.
My teammate already knows of that way to do colors but he wants to use some #define 0x0ff01 type of colors he says those are better I really have no idea. Anybody know where info on that is?
I don't do windows specific dev, hopefully someone here can help. But if you have a good relationship with your teammate, have you considered asking him why he thinks they're better?
With the #define you can define each indivdual color, yellow, green , blue, brown, etc. instead of doing the 3 colors and intensity combination.
Quote:Original post by Grahf750
With the #define you can define each indivdual color, yellow, green , blue, brown, etc. instead of doing the 3 colors and intensity combination.


ripped from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/char_info_str.asp ...

FOREGROUND_BLUE            0x0001 	Text color contains blue.FOREGROUND_GREEN           0x0002 	Text color contains green.FOREGROUND_RED             0x0004 	Text color contains red.FOREGROUND_INTENSITY       0x0008 	Text color is intensified.BACKGROUND_BLUE            0x0010 	Background color contains blue.BACKGROUND_GREEN           0x0020 	Background color contains green.BACKGROUND_RED             0x0040 	Background color contains red.BACKGROUND_INTENSITY       0x0080 	Background color is intensified.COMMON_LVB_LEADING_BYTE    0x0100 	Leading byte.COMMON_LVB_TRAILING_BYTE   0x0200 	Trailing byte.COMMON_LVB_GRID_HORIZONTAL 0x0400 	Top horizontalCOMMON_LVB_GRID_LVERTICAL  0x0800 	Left vertical.COMMON_LVB_GRID_RVERTICAL  0x1000 	Right vertical.COMMON_LVB_REVERSE_VIDEO   0x4000 	Reverse foreground and background attribute.COMMON_LVB_UNDERSCORE      0x8000 	Underscore.

As an example:
#include <windows.h>#define FOREGROUND_LTBLUE    FOREGROUND_BLUE && FOREGROUND_INTENSITY        ...orenum {  FOREGROUND_LTBLUE  = FOREGROUND_BLUE && FOREGROUND_INTENSITY,        FOREGROUND_LTGREEN = FOREGROUND_GREEN && FOREGROUND_INTENSITY,        FOREGROUND_LTCYAN  = FOREGROUND_LTBLUE && FOREGROUND_LTGREEN,        ...};

That is all you can really do in a console window; the hex colors are already defined for you. Hope this helps.

:stylin:
:stylin: "Make games, not war.""...if you're doing this to learn then just study a modern C++ compiler's implementation." -snk_kid
you can also use <conio.h> forget what the fcn calls are, but it should be with the ms compiler include files. just look in it and see what fcn calls are there. it also has alot of other console stuff.

~guyaton
~guyaton

This topic is closed to new replies.

Advertisement