Results 1 to 3 of 3

Thread: colors in console?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Location
    I'm mobile
    Posts
    166

    colors in console?

    Anyone knows how to write something in colors in console applications?

    For example, how do I write "Hello" in red?
    [p r a e t o r i a n]

  2. #2
    Megatron
    Guest
    If you're using Borland, try this:
    Code:
    #include <conio.h>
    #include <stdio.h>
    
    int main()
    {
        textcolor(15);
        printf("Hello World!\n");
        return 0;
    }
    If you're using Visual C++, try this:
    Code:
    #include <windows.h>
    #include <stdio.h>
    
    int main()
    {
        // Set color to yellow
        SetConsoleTextAttribute(GetStdHandle(STD_OUT), 14);
        printf("Hello World!\n");
        return 0;
    }

  3. #3
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Here is some more info for the SetConsoleTextAttribute second parameter

    wAttributes
    Specifies the foreground and background color attributes. Any combination of the following values can be specified: FOREGROUND_BLUE, FOREGROUND_GREEN, FOREGROUND_RED, FOREGROUND_INTENSITY, BACKGROUND_BLUE, BACKGROUND_GREEN, BACKGROUND_RED, and BACKGROUND_INTENSITY. For example, the following combination of values produces white text on a black background:

    FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width