Thread: Colours of text/background?

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    16

    Colours of text/background?

    Hello. How can i change the color of text or the background?
    I cant seem to find the answer anywhere on the internet but I know it can be done.

    Jon

  2. #2
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    16
    Ok I have used that to help me change the 1st line to blue background but I cant figure out how to change the rest of the background back to black.

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    8
    Put in BACKGROUND_0 somewhere, I think that's the right one.

    Also, if you do the function again and don't specify any BACKGROUND_ parameters, it should skip back to black.

  5. #5
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Write this function include windows.h header:

    Code:
    void DrawColorString(string szText, int X, int Y, WORD color)
    {	
    	HANDLE OutputH;									
    	COORD position = {X, Y};							
    
    	OutputH = GetStdHandle(STD_OUTPUT_HANDLE);		
    
    	SetConsoleTextAttribute(OutputH, color);		
    													
    	SetConsoleCursorPosition(OutputH, position);	
    
    	cout << szText;									
    }
    In program, use this:

    Code:
    DrawColorString("", 0, 5, FOREGROUND_BLUE | BACKGROUND_RED);
    Hope this helps!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Printf in different colours?
    By JFonseka in forum C Programming
    Replies: 7
    Last Post: 12-27-2007, 02:45 AM
  2. Ncurses colours without allocating colour pairs?
    By kzar in forum C Programming
    Replies: 12
    Last Post: 04-17-2005, 11:55 AM
  3. Colours in DOS box
    By denizengt in forum Tech Board
    Replies: 1
    Last Post: 09-10-2003, 06:53 AM
  4. Changing Text/Background colours for window controls ...
    By Shag in forum Windows Programming
    Replies: 1
    Last Post: 11-16-2002, 11:57 AM
  5. Colours?
    By Fountain in forum C++ Programming
    Replies: 7
    Last Post: 01-29-2002, 03:41 PM