Archived

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

change text color in console app?

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

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