Using Color In Console App

This is a discussion on Using Color In Console App within the C++ Programming forums, part of the General Programming Boards category; CAN ANYONE TELL ME HOW I ADD COLOR IN A PROGRAM??? LIKE THIS =D...

  1. #1
    Dragoon Lover wyvern's Avatar
    Join Date
    Jul 2005
    Location
    dragooncity
    Posts
    28

    Using Color In Console App

    CAN ANYONE TELL ME HOW I ADD COLOR IN A PROGRAM???

    LIKE THIS =D
    http://img76.imageshack.us/img76/1808/expl7pb.png

    AN EXPLOSION DOESNT HAPPEN CUZ GOD WANTS, IT HAPPENS WHEN A SOMETHING "EXPLODES

  2. #2
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Include windows.h and call this function:
    Code:
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED);
    More info on it here.
    Is it really necessary to write in all caps?
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  3. #3
    Dragoon Lover wyvern's Avatar
    Join Date
    Jul 2005
    Location
    dragooncity
    Posts
    28

    ups

    UPS sorry caps was on and i was in a rush sorry

    =(
    http://img76.imageshack.us/img76/1808/expl7pb.png

    AN EXPLOSION DOESNT HAPPEN CUZ GOD WANTS, IT HAPPENS WHEN A SOMETHING "EXPLODES

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,437
    Perhaps you rushed your sig as well
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    #include <me!> Flakster's Avatar
    Join Date
    May 2005
    Location
    Canada
    Posts
    50
    You can also use 'system("color xx");', which I believe is also covered in the windows.h header file.

    Replace the first x with your desired background color, and the second x with your desired foreground or text color (check the table below for what to replace the x's with). Keep in mind that this affects the whole application, where as jmd15's way can be used on certain pieces of text.

    0 - Black
    1 - Blue
    2 - Green
    3 - Aqua
    4 - Red
    5 - Purple
    6 - Yellow
    7 - White
    8 - Gray
    9 - Light Blue
    A - Light Green
    B - Light Aqua
    C - Light Red
    D - Light Purple
    E - Light Yellow
    F - Bright White

  6. #6
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Actually the way you are doing it Flakster doesn't require you to include windows.h, so I think your way is better(because less includes=smaller program size). That command is also quite fun to play around with in DOS.
    Last edited by jmd15; 10-17-2005 at 01:21 PM.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Console app termination
    By C+/- in forum C++ Programming
    Replies: 2
    Last Post: 05-24-2008, 11:29 AM
  2. Console App w/ Threads and Events?
    By sean in forum C# Programming
    Replies: 1
    Last Post: 07-02-2004, 12:16 AM
  3. Need help migrating console app to windows app
    By DelphiGuy in forum C++ Programming
    Replies: 1
    Last Post: 03-14-2004, 06:05 PM
  4. MSVC Console app - two enters?
    By LuckY in forum Windows Programming
    Replies: 4
    Last Post: 12-30-2003, 01:13 PM
  5. Project Builder console app
    By Luigi in forum C++ Programming
    Replies: 0
    Last Post: 12-28-2002, 06:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21