Thread: Win32 Console Color Question

  1. #1
    Fallen AndyBomstad's Avatar
    Join Date
    Jan 2005

    Win32 Console Color Question

    Hey Guys Im Using The windows.h header on my program, and ive got the function all built and what not, but ive noticed i can only choose between red,green,and blue....

    lol big suprise but im just wondering if theres some simple way of tweaking it so i can use colors other than that for the text in my program

  2. #2
    Join Date
    Feb 2002
    You can use the bitwise-or operator to combine the colors.
    SetConsoleTextAttribute ( h, FOREGROUND_RED | FOREGROUND_INTENSITY );
    The FOREGROUND_INTENSITY is useful to mix with the other colors, giving 16 total colors.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  3. #3
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Manassas, VA USA
    You can mix your own colors using Red, Green, and Blue.

    Define your own colors as numeric constants using the RGB( ) macro, where the arguments are the amount of red, green, and blue respectively.. on a scale of 0 to 255.

    COLORREF green =  RGB(0, 255, 0);
    COLORREF yellow = RGB(255, 255, 0);
    COLORREF purple = RGB(255, 0, 255);
    COLORREF dark_gray = RGB(128, 128, 128);
    Last edited by The Brain; 02-03-2005 at 02:37 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

  4. #4
    Fallen AndyBomstad's Avatar
    Join Date
    Jan 2005
    hey yeah, i knew there was a way to adjust the values of the RGB but i wasnt really sure, but yeah thanks for the help guys!

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001

    Link to the MSDN console reference

    Thank's pianorain. I used SetConsoleTextAttribute() to re-find the MSDN Console Reference. I just "bookmarked" it!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Adding a console window to a Win32 app
    By VirtualAce in forum Game Programming
    Replies: 7
    Last Post: 02-01-2009, 01:09 PM
  2. Console program to Win32
    By Ducky in forum Windows Programming
    Replies: 3
    Last Post: 02-25-2008, 12:46 PM
  3. making a stealthy win32 console application?
    By killdragon in forum C++ Programming
    Replies: 3
    Last Post: 09-08-2004, 02:50 PM
  4. confusion win32 -console app
    By GanglyLamb in forum C Programming
    Replies: 2
    Last Post: 06-11-2003, 10:12 AM
  5. win32 apps compiled with GCC start console window!
    By Citrus538 in forum Windows Programming
    Replies: 5
    Last Post: 02-18-2002, 10:35 PM