change text color in console app?
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!
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.
The only thing that defines man from animal is our knowledge of computer programming.
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);
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
GetConsoleScreenBufferInfo(consoleWindow, &csbiInfo);
SetConsoleTextAttribute(consoleWindow, FOREGROUND_RED | FOREGROUND_GREEN);
printf("bla bla bla\n");
SetConsoleTextAttribute(consoleWindow, csbiInfo.wAttributes);
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]
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]
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]
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]
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...
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...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement