| | |
Change text color using visual c++
![]() |
conio.h
It has a lot funtions for console input/output.Take a look at it.
TextColor(RED);
TextBackground(BLUE);
The color values range from 0-15 with 0 being black and 15 being white
warning,i am not too sure of the funtion names,been a while since i used this, though i used it almost everywhere, man time flies
It has a lot funtions for console input/output.Take a look at it.
TextColor(RED);
TextBackground(BLUE);
The color values range from 0-15 with 0 being black and 15 being white
warning,i am not too sure of the funtion names,been a while since i used this, though i used it almost everywhere, man time flies
•
•
Join Date: May 2006
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by hail2dthief
I'm using visual c++ compiler and I want to change the text color in my c++ dos program. What choices do I have if i don't wanna use system function (example: system("color 0a"))?
C++ Syntax (Toggle Plain Text)
#define BLACK 0 #define BLUE 1 #define GREEN 2 #define CYAN 3 #define RED 4 #define MAGENTA 5 #define BROWN 6 #define LIGHTGREY 7 #define DARKGREY 8 #define LIGHTBLUE 9 #define LIGHTGREEN 10 #define LIGHTCYAN 11 #define LIGHTRED 12 #define LIGHTMAGENTA 13 #define YELLOW 14 #define WHITE 15 #define BLINK 128 HANDLE screen; int textcolor = LIGHTGREEN; int backgroundcolor = BLACK; screen = GetStdHandle(STD_OUTPUT_HANDLE); void TextColor(int fontcolor,int backgroundcolor,HANDLE screen) { int color_attribute; color_attribute = backgroundcolor; color_attribute = _rotl(color_attribute,4) | fontcolor; SetConsoleTextAttribute(screen,color_attribute); } TextColor(textcolor,backgroundcolor ,screen); FillConsoleOutputAttribute(screen, _rotl(backgroundcolor,4) , 80 * 50,coord , &cWritten);
This works in Microsoft c++
•
•
Join Date: May 2007
Posts: 1
Reputation:
Solved Threads: 0
Of course, if you're just wanting to change the color as you're typing it, then the above is a bit much. A simpler way would be to use this:
C++ Syntax (Toggle Plain Text)
#include <windows.h> #include <iostream.h> int main() { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0); //replace the 0 with a number for the color you want cout << "Your text here" << endl; return 0; }
Last edited by MagikMan74; Sep 26th, 2007 at 2:10 pm. Reason: edit: forgot the [code][/code]
I used this one to save me some time
This is not Visual C++ dependant, I use this with DEv-C++ as well, you just need the windows header
Then to output in color you would just do
This is not Visual C++ dependant, I use this with DEv-C++ as well, you just need the windows header
c++ Syntax (Toggle Plain Text)
enum Colors { blue=1, green, cyan, red, purple, yellow, grey, dgrey, hblue, hgreen, hred, hpurple, hyellow, hwhite }; void coutc(int color, char* output) { HANDLE handle= GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute( handle, color); cout<< output; SetConsoleTextAttribute( handle, color); }
Then to output in color you would just do
c++ Syntax (Toggle Plain Text)
coutc(red, "This is in red!"); coutc(purple, "This is purple!");
Last edited by ShawnCplus; Sep 26th, 2007 at 5:48 pm.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
•
•
Join Date: Jan 2009
Posts: 11
Reputation:
Solved Threads: 0
HELLO
Can sombody tell me how can i chang the color of concol background????
Can sombody tell me how can i chang the color of concol background????
•
•
•
•
Of course, if you're just wanting to change the color as you're typing it, then the above is a bit much. A simpler way would be to use this:
C++ Syntax (Toggle Plain Text)
#include <windows.h> #include <iostream.h> int main() { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0); //replace the 0 with a number for the color you want cout << "Your text here" << endl; return 0; }
•
•
Join Date: Sep 2008
Posts: 36
Reputation:
Solved Threads: 1
Try this.
You can change RED to GREEN or BLUE and BACKGROUND to FOREGROUND.
If you want to mix colors you just separate them with a |
CPP Syntax (Toggle Plain Text)
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_RED BACKGROUND_INTENSITY);
You can change RED to GREEN or BLUE and BACKGROUND to FOREGROUND.
If you want to mix colors you just separate them with a |
All i've got is a slice of pi
•
•
Join Date: Jan 2009
Posts: 11
Reputation:
Solved Threads: 0
Hi
Thank you for your reply mostermand but that code didnt work in
microsoft vitual c++(I dont know why??). after searching in the net for hours I found a
useful site about win32 consul application, I thought that it would be very useful for beginners .
http://www.adrianxw.dk/SoftwareSite/index.html
Bye
Thank you for your reply mostermand but that code didnt work in
microsoft vitual c++(I dont know why??). after searching in the net for hours I found a
useful site about win32 consul application, I thought that it would be very useful for beginners .
http://www.adrianxw.dk/SoftwareSite/index.html
Bye
![]() |
Similar Threads
- HTML Editor. Text Color Change (C#)
- unable to change text color in swf file (Graphics and Multimedia)
Other Threads in the C++ Forum
- Previous Thread: Struct within Class, Problem with OVERLOADING OPERATORS
- Next Thread: Recursion in C++
| Thread Tools | Search this Thread |
addition api array base based binary bitmap c++ c/c++ char class classes code coding compile console conversion count delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email embed encryption error erroraftercompilation excel file forms fstream function functions game getline givemetehcodez gmail graph gui homework homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker loop looping loops map math matrix matrix3d memory multiple news node output parameter pointer problem program programming project python random read recursion reference rpg std::coutwstring string strings temperature template test text text-file tree url variable vector video visualization win32 windows winsock word wordfrequency wxwidgets






