Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,233 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,735 people online right now. Registration is fast and FREE... Join Now!




Color in Win32 Console Output?

 
Reply to this topicStart new topic

Color in Win32 Console Output?, easy way to do it?

tallfreek
26 Jan, 2007 - 01:29 PM
Post #1

New D.I.C Head
*

Joined: 26 Jan, 2007
Posts: 5


My Contributions
I am taking a comp. prog. class that teaches C++ at my high school. I am basically ahead of almost all the class in everything. so i do all the extra credit. one of them is to get color (besides black/white) into other colors. and I would like to make it so that only things i want are colored certain colors. like one of our programs is "ghetto dice"..i would like the dice to be white with the black dots on them. I have the program done so all i need now is colors. which would also goin into most every program i do that it would look good in from now on.


this is the only code ive found that works...

CODE

#include  <stdio.h>
#include  <windows.h>

void ChangeColour(WORD theColour)
{
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);  // Get handle to standard output
    SetConsoleTextAttribute(hConsole,theColour);  // set the text attribute of the previous handle
}

int main()
{
    ChangeColour(FOREGROUND_BLUE);      // Set the foreground colour to be blue
    printf("This text is blue\n");      
    ChangeColour(FOREGROUND_RED);     // Set the foreground colour to be blue
    printf("This text is red\n");    
    ChangeColour( FOREGROUND_BLUE | BACKGROUND_RED);  // Set the foreground colour to be blue, the background to be red
    printf("This is blue text on a red background\n");  

    return  0;
}

User is offlineProfile CardPM
+Quote Post

NickDMax
RE: Color In Win32 Console Output?
8 Jan, 2008 - 07:53 AM
Post #2

2B||!2B
Group Icon

Joined: 18 Feb, 2007
Posts: 2,859



Thanked: 50 times
Dream Kudos: 550
My Contributions
Windows Console Output
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 03:49PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month