void DrawColorString(string szText, int X, int Y, WORD color){ HANDLE OutputH; // This will be used for our handle to the output (basically, holds permission to change the output settings) COORD position = {X, Y}; // Create a COORD and set it's x and y to the X and Y passed in. OutputH = GetStdHandle(STD_OUTPUT_HANDLE); // Get a OUTPUT handle to our screen. SetConsoleTextAttribute(OutputH, color); // Set the text attribute to what ever color that was passed in. // The function SetConsoleTextAttribute takes (the handle to the output, and the color); SetConsoleCursorPosition(OutputH, position); // Set the cursor position to the desire position passed in. cout << szText; // Now print out what we wanted to at the position that was passed in.}void main(){ DrawColorString("Red", 0, 0, FOREGROUND_RED); // Draw "Red" in the color RED. Draw "White" in the color WHITE. //If we OR ("|") the colors together, it becomes white. DrawColorString("White",10, 1, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); DrawColorString("Blue", 20, 2, FOREGROUND_BLUE); // Draw "Blue" in the color BLUE. DrawColorString("Red", 0, 4, BACKGROUND_RED); // Draw "Red" with a background of RED. Draw "White" with a background of WHITE. DrawColorString("White",10, 5, BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE); DrawColorString("Blue", 20, 6, BACKGROUND_BLUE); // Draw "Blue" with a background of BLUE. // Draw a Red text color with a green background. DrawColorString("Color Text!", 0, 8, FOREGROUND_RED | BACKGROUND_GREEN); // This puts the "Press any key to continue..." on the next line. DrawColorString("", 0, 9, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);}
Edited by - bsxrider on February 3, 2002 7:11:37 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement