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 foreground/background color? P.S. my compiler doesn't have <windows.h>....

  1. #1
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342

    Exclamation Background color

    How do you change the foreground/background color?

    P.S. my compiler doesn't have <windows.h>.

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    P.S. my compiler doesn't have <windows.h>.
    You should look into getting the windows library if you are into doing all this fancy shmancy stuff.


    win32API:
    Code:
    //You can set background color when you set the wndclass.hbrBackground attribute
    
    wndclass.hbrBackground = CreateSolidBrush(0);  //All black background
    Code:
    //Also, you can always create a new brush and insert the handle in the window class 
    //structure and then delete the old brush anytime you want to change background color:
    
    DeleteObject((HBRUSH)
         SetClassLong(hwnd, GCL_HBRBACKGROUND,    
              (LONG)CreateSolidBrush(RGB(color[0], color[1], color[2]))));
    
    //The next time windows recolors the background of the window, it will use this new brush

    Here is some example winAPI code that nicely demonstrates how to change background color. (too bad you don't have windows.h, maybe one of your friends can compile it and give it to you)
    Last edited by The Brain; 04-12-2005 at 10:44 PM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Where can I get a windows library?

  4. #4
    Even death may die... Dante Shamest's Avatar
    Join Date
    Apr 2003
    Location
    Malaysia
    Posts
    970
    Download a compiler that has it.

    E.g. Dev-C++

  5. #5
    Registered User r1ck0r's Avatar
    Join Date
    Apr 2005
    Location
    UK
    Posts
    30
    I am guessing Cool-August is using the console, which means the above code will not work. As far as I'm awear, there is no 'non-hackerish' way to change the color of the console screen. Yet I am not certain.

  6. #6
    Registered User starkhorn's Avatar
    Join Date
    Sep 2003
    Posts
    21
    See this thread. In it, adrianxw posts a link for his tutorial which covers colour....unfortunately windows.h would is needed so you should definitely try to download it.

    simple graphics in C... ??

    Cheers
    Starkhorn

  7. #7
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    On a Windows machine, the following code will change the text in a console application green (my favorite console color):
    Code:
    system("color a");
    The system() function take that string and passes it along to Windows's Command Prompt for it to run. You can use "help color" to find the values for all the colors.

    Just remember that this is only for Windows, and the system() function's behaviour is platform-dependant.

  8. #8
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    Download a compiler that has it.

    E.g. Dev-C++
    I think the bloodshed IDE supports windows.h

    Download it here.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

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