Coloured Text in DOS
Posted: Tue Apr 06, 2010 2:56 pm
Hey all, I have found some source code for setting up a function for printing coloured text in a DOS window. However Im unsure about the x, y co-ords.
The function has some parameters passed into it including the x-y coords, the way I want to use this function is like a standard cout, so it just prints certain text in a different colour. I understand this code looking at it with an explanation, however I am unsure about modifying it. I may be jumping the boat a bit here. But if I miss out the x- y coords will it still work. Im gonna try it anyway, but just wondering if an expert can give me some advice.
The function has some parameters passed into it including the x-y coords, the way I want to use this function is like a standard cout, so it just prints certain text in a different colour. I understand this code looking at it with an explanation, however I am unsure about modifying it. I may be jumping the boat a bit here. But if I miss out the x- y coords will it still work. Im gonna try it anyway, but just wondering if an expert can give me some advice.
void DrawColorString(string szText, int X, int Y, WORD color)
{
HANDLE OutputH;
COORD position = {X, Y};
OutputH = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(OutputH, color);
SetConsoleCursorPosition(OutputH, position);
cout << szText;
}