Here is an example program so you can better see how it works, remember use this tutorial to learn, not as a tool to copy and paste.
Code:
// Code by: Justin (Code Monkey)
#include <windows.h>
#include <iostream>
#include <string>
// This is our function that will change the text color of the text passed in
void g_ColorText(std::string, WORD);
int main() {
g_ColorText("Hello World", FOREGROUND_BLUE | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY);
return 0;
}
// This is our function that will change the text color of the text passed in
void g_ColorText(std::string text_message, WORD text_color) {
// This is our handle to our output device (monitor)
// But before we use the output_handle we need to initialize it,
// so we get the standard handle and set it to the standard output
// handled device
HANDLE output_handle = GetStdHandle(STD_OUTPUT_HANDLE);
// This is our default color so that after the we change the text
// we can change it back to the default dos console color
WORD default_dos_color = FOREGROUND_RED |
FOREGROUND_GREEN |
FOREGROUND_BLUE |
FOREGROUND_INTENSITY;
// Here we pass in the output_handle and the text_color that we want
// the text to look like. This function changes the dos text colors.
// Its like as if yoou went to the DOS properties and change the colors
// mannualy. But this function lets you set the text attributes for the
// program so you don't have to tell the player/user of it to change
// the colors. = ]
SetConsoleTextAttribute(output_handle, text_color);
std::cout << text_message << std::endl;
// Simply sets every thing back to normal
SetConsoleTextAttribute(output_handle, default_dos_color);
}