Is there a way to do color in a console app? Im using VC++ 6.0. Its just to jazz parts up. anyone?
Is there a way to do color in a console app? Im using VC++ 6.0. Its just to jazz parts up. anyone?
http://www.t-p-n.co.uk//
check it out
the colors can be mixed
FOREGROUND_BLUE Text color contains blue.
FOREGROUND_GREEN Text color contains green.
FOREGROUND_RED Text color contains red.
FOREGROUND_INTENSITY Text color is intensified.
BACKGROUND_BLUE Background color contains blue.
BACKGROUND_GREEN Background color contains green.
BACKGROUND_RED Background color contains red.
BACKGROUND_INTENSITY Background color is intensified.
Code:#include <windows.h> int main() { HANDLE hStdout; hStdout = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(hStdout, FOREGROUND_RED); printf("WWWWOOOOO MY TEXT IS RED WWOOOOO!!"); return 0; }
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.
THANKS!!
But, Can I have multiple text on the screen??
PHP Code:
#include <windows.h>
#include <iostream.h>
void color(int color_num)
{
if( color_num == 1)
{
HANDLE hStdout;
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdout, FOREGROUND_RED);
}
if( color_num == 2)
{
HANDLE hStdout;
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdout, FOREGROUND_BLUE);
}
}
int main()
{
color(2);
cout << " RED ";
color(1);
cout << " BLUE";
return 0;
}
This outbuts both in the same color....so????
any ideas?
ACAC
http://www.t-p-n.co.uk//
check it out
Visual C++ only changes the color for one line. You'll have to put them on seperate lines, then use SetConsoleTextAttribute again
In other words use
color(2);
cout << " RED "<<endl; //or you could use \n
color(1);
cout << " BLUE"<<endl; //same here \n
C++ Is Powerful
I use C++
There fore I am Powerful
I've tried this multiple ways, but I can't get a, lets say, a blue background w/ green text. Is there a way to accomplish this?
Thanks!
Mike
i've tried it and Background colors will not change... so i don't know either, sorry.
ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.
Are there any different colors that can be used?
Thanks
Not really. The problem is that ostream is buffered. Try:Visual C++ only changes the color for one line. You'll have to put them on seperate lines, then use SetConsoleTextAttribute againCode:color(2); cout << " RED " << flush; color(1); cout << " BLUE" << flush;See here: Windows Programming FAQI've tried this multiple ways, but I can't get a, lets say, a blue background w/ green text. Is there a way to accomplish this?
- lmov
with this code....
color(2);
cout << " RED " << flush;
color(1);
cout << " BLUE" << flush;
***sorry about the previous one...hit a reply by accident***
with this code....
color(2);
cout << " RED " << flush;
color(1);
cout << " BLUE" << flush;
what header do you use ?
Originally Posted by Unregistered
Hi!, How I can return to Black and White???
I don't see how this is a game programming related thread?
ehhh Thread necrophilia!
You can have a blue text on a green background. You have to mix colors to achieve this. You would OR the foreground and background flags like so:
You would then be able to toggle the color using the function SetConsoleTextAttribute. You would need to call this function each time you want to change the color.Code:WORD color_attribute=FOREGROUND_BLUE|BACKGROUND_GREEN
With a windows console the screen buffer is an array of CHAR_INFO structures. There are several windows console functions that work with CHAR_INFO arrays to modify the color and text and then display them to the screen. You can goto the msdn library for a complete list of Windows console functions.
Last edited by manofsteel972; 10-25-2006 at 04:03 AM.
"Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
-- Cowper
Operating Systems=Slackware Linux 9.1,Windows 98/Xp
Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)
You may teach a person from now until doom's day, but that person will only know what he learns himself.
Now I know what doesn't work.
A problem is understood by solving it, not by pondering it.
For a bit of humor check out xkcd web comic http://xkcd.com/235/