Console Text Colors

So i know of two ways of changing the text color of a console application.

1.) system("color #");
2.)
1
2
3
4
5
6
#include <windows.h>

    HANDLE  hColor;	
    hColor = GetStdHandle (STD_OUTPUT_HANDLE);

    SetConsoleTextAttribute(hColor, #); 


I was wondering if there was another way of changing the color because system("color #) changes the whole screen and method 2 is very clumsy to work with if you only want to change small parts of the code. Any body know if there are any other ways?
system (color) will change the whole screen.
You are using the right function SetConsoleTextAttribute() but
you are using it incorrectly.
Here is an example of how to use it. This will set the foreground text to RED - and as there is no mention of a background color then background will be BLACK.

SetConsoleTextAttribute(dosHandleOut,FOREGROUND_RED);

here is BLUE text on RED background:
SetConsoleTextAttribute(dosHandleOut,BACKGROUND_RED|FOREGROUND_BLUE);
Actually using the number directly is fine. The attribute byte is the same format as the EGA text attribute byte, except that the fourth bit of each nibble always represents intensity.
ok, i was just wondering if there was any better ways too do it. thanks for the responses
Topic archived. No new replies allowed.