background color

This is a discussion on background color within the C Programming forums, part of the General Programming Boards category; How do you change the text or background color of your output? Is there a FAQ on how to do ...

  1. #1
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357

    Question background color

    How do you change the text or background color of your output?

    Is there a FAQ on how to do that on this website somewhere?

  2. #2
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427
    HANDLE hStdout;

    hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hStdout, FOREGROUND_GREEN | FOREGROUND_INTENSITY); //CHANGING TEXT COLOR
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

  3. #3
    Un Artiste Extraordinaire volk's Avatar
    Join Date
    Dec 2002
    Posts
    357
    What about the background color?

  4. #4
    Rez
    Rez is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    82
    In some DOS compilers, you can...
    Code:
    /*...some code here...*/
    textbackgound(BLUE);
    clrscr();
    /*...voila!...*/

  5. #5
    left crog... back when? incognito's Avatar
    Join Date
    Oct 2001
    Posts
    1,427

    Wink

    Code:
    The SetConsoleTextAttribute function sets the foreground (text) and background color attributes of 
    characters written to the screen buffer by the WriteFile or WriteConsole function, or echoed by the ReadFile
     or ReadConsole function. This function affects only text written after the function call. 
    
    BOOL SetConsoleTextAttribute(
    
        HANDLE hConsoleOutput,	// handle of console screen buffer  
        WORD wAttributes 	// text and background colors 
       );	
    Parameters
    
    hConsoleOutput
    
    Identifies a console screen buffer. The handle must have GENERIC_READ access. 
    
    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

    Source: Win32 SDK Reference Help
    Last edited by incognito; 03-10-2003 at 05:33 PM.
    There are some real morons in this world please do not become one of them, do not become a victim of moronitis. PROGRAMMING IS THE FUTURE...THE FUTURE IS NOW!!!!!!!!!

    "...The only real game I thank in the world is baseball..." --Babe Ruth

    "Life is beautiful"-Don Corleone right before he died.

    "The expert on anything was once a beginner" -Baseball poster I own.


    Left cprog on 1-3-2005. Don't know when I am coming back. Thanks to those who helped me over the years.

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. Windows background color
    By Exile in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2005, 06:55 AM
  3. Setting the background color of my main window
    By Garfield in forum Windows Programming
    Replies: 5
    Last Post: 07-06-2002, 11:25 PM
  4. Text and background Color
    By Goof Program in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-29-2002, 05:59 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