Sign in to follow this  
Rhaal

SetConsoleTextAttribute

Recommended Posts

Rhaal    754
Is there a list somewhere of all the foreground/background colors possible using the MS Console function SetConsoleTextAttribute?

Share this post


Link to post
Share on other sites
Rhaal    754
Quote:
Original post by xMcBaiNx
MSDN


Please read my question before immediately pasting an MSDN link. Where do you think I got the function from?

I'm asking for a list of all possible colors as in yellow, purple, gold, etc...

Share this post


Link to post
Share on other sites
NewbJ    226
I don't use the SetConsoleTextAttribute too much, but don't you just use the | operator to combine colors? Like, (Console_Red | Console_Blue) would make purple? (I know Console_Red and Console_Blue aren't actually the colors, but you get the idea)

EDIT: fixed usage of vocabulary (| isn't an OR operator...)

Share this post


Link to post
Share on other sites
RenderTarget    398
Back to the MSDN page, click on the "Character attributes" parameter. There's the list of colors. And yes, you | them together to make secondaries and combine fore and background colors.

Share this post


Link to post
Share on other sites
Rhaal    754
Quote:
Original post by RenderTarget
Back to the MSDN page, click on the "Character attributes" parameter. There's the list of colors. And yes, you | them together to make secondaries and combine fore and background colors.


Oh my god.

I am familiar with MSDN, so links there will not really help. Maybe the beginners forum was a bad place for me to post.

I know if you set the bits FOREGROUND_RED | FOREGROUND_BLUE, you'll get purple, and I know how to use intensity.

My question is this. Obviously SetConsoleTextAttribute has been around for a while, and SOMEBODY has had to come up with all the possible combitations between

FOREGROUND_RED
FOREGROUND_GREEN
FOREGROUND_BLUE
FOREGROUND_INTENSITY

I simply want a list. I've already come up with quite a few myself (Gold, Cyan, Bright R|G|B, Light blue, etc...) but I want to make sure I'm not missing any.

I guess when I get home from work I'll paste all the ones I have. Sorry to be confusing in my initial question. I didn't think it was gonna be this misconstrued ;)

Share this post


Link to post
Share on other sites
RenderTarget    398
Ooooooooh. Gotcha. It's just like adding RBG colors:

red + green = dark yellow
red + blue = dark magenta
green + blue = dark cyan
red + green + blue = gray

adding intensity makes a brighter shade of each:

red + green + intense = yellow
red + blue + intense = magenta
green + blue + intense = cyan
red + green + blue + intense = white

It used to be (in DOS days) that background colors didn't have bright versions but I'm not sure anymore. That was a limitation of the video character format (they needed room for a blinky bit).

Share this post


Link to post
Share on other sites
Rhaal    754

switch(cl)
{
case GREY: { SetConsoleTextAttribute(ScreenBuffer, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN); break; }
case WHITE: { SetConsoleTextAttribute(ScreenBuffer, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY); break; }

case RED: { SetConsoleTextAttribute(ScreenBuffer, FOREGROUND_RED);break; }
case GREEN: { SetConsoleTextAttribute(ScreenBuffer, FOREGROUND_GREEN); break; }
case BLUE: { SetConsoleTextAttribute(ScreenBuffer, FOREGROUND_BLUE); break; }

case PURPLE: { SetConsoleTextAttribute(ScreenBuffer, FOREGROUND_RED | FOREGROUND_BLUE); break; }
case CYAN: { SetConsoleTextAttribute(ScreenBuffer, FOREGROUND_GREEN | FOREGROUND_BLUE); break; }

case BRIGHT_RED: { SetConsoleTextAttribute(ScreenBuffer, FOREGROUND_RED | FOREGROUND_INTENSITY); break; }
case BRIGHT_GREEN:{ SetConsoleTextAttribute(ScreenBuffer, FOREGROUND_GREEN | FOREGROUND_INTENSITY); break; }
case BRIGHT_BLUE: { SetConsoleTextAttribute(ScreenBuffer, FOREGROUND_BLUE | FOREGROUND_INTENSITY); break;}

case YELLOW: { SetConsoleTextAttribute(ScreenBuffer, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY); break; }
case GOLD: { SetConsoleTextAttribute(ScreenBuffer, FOREGROUND_RED | FOREGROUND_GREEN); break; }
}




That's all the foregrounds I could come up with.

Edit: Ah I see a couple missed..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this