Jump to content
  • Advertisement

Archived

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

virus3355

change text color in console app?

This topic is 5647 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

using C++ in a Win32 Console Application can u change the text color and the background color? Whats the syntax?? Could u share that? :D Thanks!

Share this post


Link to post
Share on other sites
Advertisement
sure but what are u using to make the window and draw the text? windows gdi or directX. Or something else?

The only thing that defines man from animal is our knowledge of computer programming.

Share this post


Link to post
Share on other sites
HANDLE consoleWindow = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
GetConsoleScreenBufferInfo(consoleWindow, &csbiInfo);
SetConsoleTextAttribute(consoleWindow, FOREGROUND_RED | FOREGROUND_GREEN);
printf("bla bla bla\n");
SetConsoleTextAttribute(consoleWindow, csbiInfo.wAttributes);

Share this post


Link to post
Share on other sites
How about just writing

system("color 03");

for example??

You can check the colour definitions when simply typing 'color /help' in console.
Hope that helps

[edited by - l3mon on January 28, 2003 4:17:47 AM]

Share this post


Link to post
Share on other sites
How about just changing the color of a certain part of the text?

Like not the whole program.

Example

i just want to change the color of:


cout << "BLUE" << endl;


not the entire program.

EDIT:
im guessing you cant have several different lines in different colors... just ONE foreground and ONE background?

I'm so sad
[edited by - virus3355 on January 28, 2003 6:32:03 PM]

[edited by - virus3355 on January 28, 2003 6:32:45 PM]

[edited by - virus3355 on January 28, 2003 7:07:53 PM]

[edited by - virus3355 on January 29, 2003 9:38:08 AM]

Share this post


Link to post
Share on other sites
Hi..

Don''t know if the escape codes are supported my Windows consoles... In Linux, you can use escape codes to change the color of the text...

Haven''t got any time to try it out now, but you might want to check out escape codes...

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!