Console app : Text Color.

I am trying to set text to Black and Black background, so it is invisible. Later I want to change it to white text color and all the text that was written becomes white.

I want to do that because of I have app using a lot of for loops and it is printing charcaters and I can see the characters printing slowly...
I want to avoid that I want to set text to be invisible and then when it does all of its job (writes all characters) then turn it into white color.

Is that possible ?

HANDLE m_Handle;
m_Handle =GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(m_Handle,0);

with that foreground text and background are set black
For others color, from MSDN:
An application can combine the foreground and background constants to achieve different colors. For example, the following combination results in bright cyan text on a blue background.

FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY | BACKGROUND_BLUE

If no background constant is specified, the background is black, and if no foreground constant is specified, the text is black. For example, the following combination produces black text on a white background.

BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED



Hey, Thanks for replying,

Now I know how to make invisible text, but SetConsoleTextAttribute(m_Handle,0); will only do for text that is printed next, for example :

1
2
3
SetConsoleTextAttribute(m_Handle,0);

cout << "test invisible color";


But what I want to achieve is to make text in whole console invisible AND later when I call function settextcolorVisible(); to make it visible
For example :

1
2
3
4
5
6
7
SetConsoleTextAttribute(m_Handle,0);

cout << "Bla bla bla"; // This text is invisible

SetConsoleTextAttribute(m_Handle, 15); // NOW THE TEXT("Bla bla bla") ABOVE GETS WHITE

return 0;




Last edited on
I am afraid you can't change the color of the text that is printed already.
If the printing takes too much time you can store the output in a string and print it when everything is finished.
I was thinking about "Storing all printed text to string", But The invisible text would be a lot easier(In my case).

But for now String will do

1
2
3
4
5
string s = "Hello world";

s += '\n';
s += "here we go";
cout << s << endl;


Thank you very much @Thomas1965
Topic archived. No new replies allowed.