Warning: INSERT command denied to user 'dbo292345962'@'74.208.16.27' for table 'watchdog' query: INSERT INTO watchdog (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (0, 'php', '%message in %file on line %line.', 'a:4:{s:6:\"%error\";s:12:\"user warning\";s:8:\"%message\";s:399:\"INSERT command denied to user 'dbo292345962'@'74.208.16.27' for table 'captcha_sessions'\nquery: INSERT into captcha_sessions (uid, sid, ip_address, timestamp, form_id, solution, status, attempts) VALUES (0, 'f69558d299e7086b0e9983adf0abfb4e', '54.166.122.86', 1418980740, 'comment_form', '182d938f56c73985ba91b542face55f7', 0, 0)\";s:5:\"%file\";s:62:\"/homepages/25/d199835659/htdocs/ID/modules/captcha/captcha.inc\";s:5:\"%line\";i:99;}� in /homepages/25/d199835659/htdocs/ID/includes/database.mysql.inc on line 135
Set Console Text Color | Inferno Development

Set Console Text Color

Setting console text color is a great way to add spice to your console games. Using a combination of ASCII art and Console coloring you can even make your own RPG game. It's very simple to do, all you need is windows.h.

Most of the colors go from 1 to 16, and after that you get background colors mixed with foreground colors (if you wanted to experiment just cast your number as (Color)).

#include <iostream>
#include <windows.h>

using namespace std;
HANDLE hCon;

enum Color { DARKBLUE = 1, DARKGREEN, DARKTEAL, DARKRED, DARKPINK, DARKYELLOW, GRAY, DARKGRAY, BLUE, GREEN, TEAL, RED, PINK, YELLOW, WHITE };

void SetColor(Color c){
        if(hCon == NULL)
                hCon = GetStdHandle(STD_OUTPUT_HANDLE);
        SetConsoleTextAttribute(hCon, c);
}

int main(){
  SetColor(RED);
  cout << "InfernoDevelopment.com\n";
  SetColor(DARKRED);
  cout << "Join our forums at www.infernodevelopment.com/forum\n";
  cin.get();
  return 0;
}

The SetColor function uses SetConsoleTextAttribute and GetStdHandle to grab the handle to your console and set the current color requested by the Color enum.

After you set the color, you can then use cout like a normal console to print the colored text.

It can really impress your friends who have probably never even seen console text color in their lives!

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.