Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Strabbi

Color Text in Console Mode Programs?

This topic is 6666 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it possible to change the color of the text in a console mode program. (Under windows) I tried using ANSI escape codes, but no luck. How do you change the color in C under DOS? (It might the same) Can I call int10 (in assembly) under windows console mode?

Share this post


Link to post
Share on other sites
Advertisement
No, I don't think you can use int 10 (or any intterupt) under console programs. You can do it the "Win32 way" using SetConsoleTextAttribute(). It needs a handle to the consoel screen buffer as an argument so you can either call GetStdHandle() early and save it as a global or just wrap the whole thing in a function, like this:

                        
int ChangeTextColor(WORD text_attribute)
{

HANDLE screen_buffer;

screen_buffer = GetStdHandle(STD_OUTPUT_HANDLE);

SetConsoleTextAttribute(screen_buffer, text_attribute);

return(1);

}



And to call it you make a call like:


ChangeTextColor(FOREGROUND_BLUE);
ChangeTextColor(FOREGROUND_BLUE / BACKGROUND_RED / FOREGROUND_INTENSITY);
or whatever. The arguments can be any of the combination of the following (taken out of the VC++ help):

FOREGROUND_BLUE, FOREGROUND_GREEN, FOREGROUND_RED, FOREGROUND_INTENSITY, BACKGROUND_BLUE, BACKGROUND_GREEN, BACKGROUND_RED, and BACKGROUND_INTENSITY

Note it is supposed to be a pipe instead of the back slash. I guess HTML formats the pipes to back slashes for some reason. If you don't know a pipe is just shift+back slash. And I know there is probably an alt combination or whatever that gives you pipes but I'm too lazy to look it up.

Edited by - Sheltem on June 20, 2000 2:40:19 AM

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!