Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text color of text displayed by my program?

Status
Not open for further replies.

MattHimself

Technical User
Jan 27, 2003
10
0
0
GB
How do I change the text color of text displayed by my program? Can someone please give me an example. The text I need to change is in a variable and I need to change the color that it is displayed. This is the variable bellow.

char m[]={"JG04H503GH78RTHGUFDSYTRG89G6TJGDJGIJREWITJGDJGIJREWITJGDJGIJREWITJ"};

Please can someone tell me how to do this.
Thanks
 
is it in winodws or in console?

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Erm Im using visual C++ and i want to change the color of the text displayed when the program is run if thats wat you mean? Im very new to programming.
 
in this case would be better you to study what is console and what is window

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Come on dude just help me out dont be smart. The forum is here to help people learn stuff.
 
Ok, I ask yo a again:
is your text displayed in a winodw or in console?


Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
you should use SetConsoleTextAttribute

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
I expect what the information above is not enough, so I think a short sample would give you a start:
#include<windows.h>
#include<iostream>
using namespace std;

int main()
{

HANDLE cons = GetStdHandle(STD_OUTPUT_HANDLE);
BOOL ret = SetConsoleTextAttribute(
cons, FOREGROUND_RED | FOREGROUND_INTENSITY | BACKGROUND_BLUE
);
SetConsoleTitle(
&quot;hello from the console&quot;
);


cout<< cons<< endl;
return 0;
}

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Thanks thats really good but could you give me an example of how i would use my above variable with that? I need to make the text green.
 
#include<windows.h>
#include<iostream>
using namespace std;

int main()
{
char m[]={&quot;JG04H503GH78RTHGUFDSYTRG89G6TJGDJGIJREWITJGDJGIJREWITJGDJGIJREWITJ&quot;};

HANDLE cons = GetStdHandle(STD_OUTPUT_HANDLE);
BOOL ret = SetConsoleTextAttribute(
cons, FOREGROUND_GREEN );


cout<< m<< endl;
return 0;
}

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top