Change color

How do I change the color of the text/background in a C++ console app? Also, how do I make the characters fade in/out?

Thanks.
AverageJoezAsked:
Who is Participating?
 
EarthQuakerConnect With a Mentor Commented:
This is for a console app. You were just not able to understand it.

As you seem to have problem understanding the code in the url, here is a sample :

#include <iostream>
#include <windows.h>

using namespace std;

int main()
{
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | BACKGROUND_BLUE);
    cout << "Hello World" << endl;
   
    return 0;
}
 
0
 
AverageJoezAuthor Commented:
That might work, but I'm looking for a way to change the color in a console app. This link points to a Win32 GUI program.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
EarthQuakerCommented:
To change the color on *nix it's another way, ask if you want to know under *nix.
0
 
AverageJoezAuthor Commented:
The prog that was given in the question (http://www.experts-exchange.com/Programming/Programming_Languages/Cplusplus/Q_20182590.html) was a C++ Win32 GUI app.

The app that you gave seems to work for the console, but to only make a segment of the output windows a certain color do I do SetConsoleTextAttribute and set the default parameters (black and whit), or is there a way to cancel the function?

Also, do you know how to make characters fade in/out?

Thanks.
0
 
EarthQuakerCommented:
It was a Win32 GUI app, what I meant was that it has the solution for your problem in it, I only had to read the link pasted to create the sample I gaved you.

To reput in white over black call that :

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE );

As far as I know, there is no way of fading characters in console... you can maybe trick around like :

while (1)
{
     system ("cls");
     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED);
     cout << "Hello World" << endl;
     Sleep(100);
     system ("cls");
     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY);
     cout << "Hello World" << endl;
     Sleep(100);
}
0
All Courses

From novice to tech pro — start learning today.