?
Solved

Change color

Posted on 2003-02-23
6
Medium Priority
?
263 Views
Last Modified: 2012-06-21
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.
0
Comment
Question by:AverageJoez
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 

Author Comment

by:AverageJoez
ID: 8003948
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
 
LVL 3

Accepted Solution

by:
EarthQuaker earned 240 total points
ID: 8004003
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Expert Comment

by:EarthQuaker
ID: 8004005
To change the color on *nix it's another way, ask if you want to know under *nix.
0
 

Author Comment

by:AverageJoez
ID: 8004121
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
 
LVL 3

Expert Comment

by:EarthQuaker
ID: 8004205
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question