Color?

This is a discussion on Color? within the Game Programming forums, part of the General Programming Boards category; Is there a way to do color in a console app? Im using VC++ 6.0. Its just to jazz parts ...

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    13

    Color?

    Is there a way to do color in a console app? Im using VC++ 6.0. Its just to jazz parts up. anyone?
    http://www.t-p-n.co.uk//
    check it out

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    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;
    }
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    13
    THANKS!!
    But, Can I have multiple text on the screen??

    PHP Code:
    #include <windows.h>
    #include <iostream.h>



    void color(int color_num)
    {
        if( 
    color_num == 1)
        {
        
    HANDLE hStdout;
        
    hStdout GetStdHandle(STD_OUTPUT_HANDLE); 
        
    SetConsoleTextAttribute(hStdoutFOREGROUND_RED);
        }
        
        if( 
    color_num == 2)
        {
        
        
    HANDLE hStdout;
        
    hStdout GetStdHandle(STD_OUTPUT_HANDLE); 
        
    SetConsoleTextAttribute(hStdoutFOREGROUND_BLUE);

        }



    }


    int main()
    {

        
    color(2);
        
    cout << " RED ";
        
    color(1);
        
    cout << " BLUE";
        return 
    0;


    This outbuts both in the same color....so????

    any ideas?
    ACAC
    http://www.t-p-n.co.uk//
    check it out

  4. #4
    Intranasal Heroin User Xterria's Avatar
    Join Date
    Sep 2001
    Location
    Buffalo, NY
    Posts
    1,035
    Visual C++ only changes the color for one line. You'll have to put them on seperate lines, then use SetConsoleTextAttribute again

  5. #5
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    In other words use

    color(2);
    cout << " RED "<<endl; //or you could use \n
    color(1);
    cout << " BLUE"<<endl; //same here \n
    C++ Is Powerful
    I use C++
    There fore I am Powerful

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    7

    Background w/ Foreground

    I've tried this multiple ways, but I can't get a, lets say, a blue background w/ green text. Is there a way to accomplish this?

    Thanks!
    Mike

  7. #7
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    i've tried it and Background colors will not change... so i don't know either, sorry.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  8. #8
    Unregistered
    Guest
    Are there any different colors that can be used?
    Thanks

  9. #9
    Registered User
    Join Date
    Aug 2001
    Posts
    101
    Visual C++ only changes the color for one line. You'll have to put them on seperate lines, then use SetConsoleTextAttribute again
    Not really. The problem is that ostream is buffered. Try:
    Code:
        color(2);
        cout << " RED " << flush;
        color(1);
        cout << " BLUE" << flush;
    I've tried this multiple ways, but I can't get a, lets say, a blue background w/ green text. Is there a way to accomplish this?
    See here: Windows Programming FAQ
    - lmov

  10. #10
    Unregistered
    Guest
    with this code....

    color(2);
    cout << " RED " << flush;
    color(1);
    cout << " BLUE" << flush;

  11. #11
    Unregistered
    Guest
    ***sorry about the previous one...hit a reply by accident***


    with this code....

    color(2);
    cout << " RED " << flush;
    color(1);
    cout << " BLUE" << flush;


    what header do you use ?

  12. #12
    Registered User
    Join Date
    Oct 2006
    Posts
    3
    Quote Originally Posted by Unregistered
    ***sorry about the previous one...hit a reply by accident***


    with this code....

    color(2);
    cout << " RED " << flush;
    color(1);
    cout << " BLUE" << flush;


    what header do you use ?

    Hi!, How I can return to Black and White???

  13. #13
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    I don't see how this is a game programming related thread?

  14. #14
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    ehhh Thread necrophilia!

  15. #15
    Registered User manofsteel972's Avatar
    Join Date
    Mar 2004
    Posts
    317
    You can have a blue text on a green background. You have to mix colors to achieve this. You would OR the foreground and background flags like so:

    Code:
     WORD color_attribute=FOREGROUND_BLUE|BACKGROUND_GREEN
    You would then be able to toggle the color using the function SetConsoleTextAttribute. You would need to call this function each time you want to change the color.

    With a windows console the screen buffer is an array of CHAR_INFO structures. There are several windows console functions that work with CHAR_INFO arrays to modify the color and text and then display them to the screen. You can goto the msdn library for a complete list of Windows console functions.
    Last edited by manofsteel972; 10-25-2006 at 04:03 AM.
    "Knowledge is proud that she knows so much; Wisdom is humble that she knows no more."
    -- Cowper

    Operating Systems=Slackware Linux 9.1,Windows 98/Xp
    Compilers=gcc 3.2.3, Visual C++ 6.0, DevC++(Mingw)

    You may teach a person from now until doom's day, but that person will only know what he learns himself.

    Now I know what doesn't work.

    A problem is understood by solving it, not by pondering it.

    For a bit of humor check out xkcd web comic http://xkcd.com/235/

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Critique my lighting model.
    By psychopath in forum Game Programming
    Replies: 4
    Last Post: 08-12-2006, 06:23 PM
  2. egavga.bgi problem
    By sunil21 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 09-22-2003, 05:06 PM
  3. My opinion on skin color
    By Leeman_s in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 07-11-2003, 12:12 PM
  4. [WinAPI] Developing a color customizable program
    By Templario in forum Windows Programming
    Replies: 6
    Last Post: 02-04-2003, 05:12 PM
  5. Just one Question?
    By Irish-Slasher in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2002, 09:19 AM

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