Thread: How do you add colour to the text in DOS?

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    8

    Question How do you add colour to the text in DOS?

    Doe's anyone know how to add colour to DOS programs? I use C++ and I would like to know how to use colour instead of the boring white text as usual. If you know then please post how to on this board and show some source code!

  2. #2
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    Include conio.h. Then use the following function:

    textcolor(int color)

    That will change the text color, but it does not come into effect unless you clear the screen:

    clrscr();

    So, here is some example code:

    #include <iostream.h>
    #include <conio.h>

    int main (void)
    {
    textcolor(RED);
    clrscr();
    cout << "Hello, World!";
    getch();
    return 0;
    }
    My Website

    "Circular logic is good because it is."

  3. #3
    Disagreeably Disagreeable
    Join Date
    Aug 2001
    Posts
    711
    It (textcolor()) does come into effect, but you have to use the right functions. I think all output functions that use direct access will work (putch(), cprintf(), etc...).

  4. #4
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    to prevent confuson i'll ask first, are you usin a console?
    Last edited by no-one; 09-30-2001 at 11:13 AM.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    8
    I am using a console and not a GUI program.

  6. #6
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    repost,

    the colors can be mixed

    FOREGROUND_BLUE Text color contains blue.
    FOREGROUND_GREEN Text color contains green.
    FOREGROUND_RED Text color contains red.
    FOREGROUND_INTENSITY Text color is intensified.
    BACKGROUND_BLUE Background color contains blue.
    BACKGROUND_GREEN Background color contains green.
    BACKGROUND_RED Background color contains red.
    BACKGROUND_INTENSITY Background color is intensified.

    Code:
    #include <windows.h>
    
    int main()
    {
    
        HANDLE hStdout;
        hStdout = GetStdHandle(STD_OUTPUT_HANDLE); 
        SetConsoleTextAttribute(hStdout, FOREGROUND_RED);
        
        printf("WWWWOOOOO MY TEXT IS RED WWOOOOO!!");
        return 0;
    }
    Last edited by no-one; 10-01-2001 at 10:02 AM.

  7. #7
    Registered User st0ic's Avatar
    Join Date
    Oct 2001
    Posts
    5

    Text color with ANSI C ?

    Ah, I don't do C++, so I was wondering about doing the eqivulent in C? I'm not really aware of any functions that can do that in C. Any comments would be apperciated....

    Thanks.

  8. #8
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    that is C, it should work fine...
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  9. #9
    Registered User st0ic's Avatar
    Join Date
    Oct 2001
    Posts
    5

    Unhappy Ops

    Ops.. my bad. Well, thanks for the info anyways...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-24-2006, 08:36 PM
  2. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 04:49 PM
  3. changing the colour of text in vc++6
    By satory in forum C Programming
    Replies: 1
    Last Post: 10-22-2004, 08:35 AM
  4. Add to my football strategy text game
    By real_cozzy in forum Game Programming
    Replies: 6
    Last Post: 01-20-2002, 05:09 PM