Been programming in C++ for a few months now so I'm pretty confident with the basics. Currently playing around with a few text-based games and I'm wondering how you change the colour of the text outputted to the screen. If someone could point me in the right direction of what to research/use (libraries, etc) I'd much appreciate it.
Cheers,
S
P.S Forgot to mention, I'm using Microsoft Visual C++ 2008 Express Edition
To change the enire output color in a console program simply use system("Color XX"); where 'X' is an hexadecimal digit for a color.
The first 'X' is for background, the second for foreground.
By using <windows.h> you will find the funcion SetConsoleTextAttribute() useful to change the color for all the output after its call.
It works as follow: SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),/*newcolor*/);. Where newcolor is a number. If you write that number with hexadeciam base (0xNN) the meaning will be the same as in the previous function.
Cheers, Baz. SetConsoleTextAttribute() worked a treat. Appreciate your help.
I'm currently looking into changing the size of the console window due to my text game displaying more text than what can fit in the default one, and I dont want to have to manually resize it every time i start up the game. I think I need to use SetConsoleWindowInfo() or something like that but I'm finding it a bit confusing.
Can someone give an example on how to use it? Also, is there a way to remove the scroll bar down the right hand-side of the console window?
To Move/Resize the console window: MoveWindow(GetConsoleWindow(),x,y,width,height,true);
To resize without moving, use GetWindowInfo() and set x,y position as the old one