Thread: Colors in DOS console

  1. #1
    Unregistered
    Guest

    Question Colors in DOS console

    Is it possible to change your program so that it breaks out of the normal black and white does scheme? for instance in CMOS, it uses blue and red...thanks.

  2. #2
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    look at the conio.h and conio.c files

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    textcolor

    Syntax

    #include <conio.h>
    void textcolor(int newcolor);

    Description

    Selects new character color in text mode.

    Note: Do not use this function for Win32s or Win32 GUI applications.

    textcolor selects the foreground character color. This function works for the console output functions. newcolor selects the new foreground color. You can set newcolor to an integer as given in the table below, or to one of the symbolic constants defined in conio.h. If you use symbolic constants, you must include conio.h.
    Once you have called textcolor, all subsequent functions using direct video output (such as cprintf) will use newcolor. textcolor does not affect any characters currently onscreen.

    The following table lists the allowable colors (as symbolic constants) and their numeric values:

    Symbolic constant Numeric value

    BLACK 0
    BLUE 1
    GREEN 2
    CYAN 3
    RED 4
    MAGENTA 5
    BROWN 6
    LIGHTGRAY 7
    DARKGRAY 8
    LIGHTBLUE 9
    LIGHTGREEN 10
    LIGHTCYAN 11
    LIGHTRED 12
    LIGHTMAGENTA 13
    YELLOW 14
    WHITE 15
    BLINK 128

    You can make the characters blink by adding 128 to the foreground color. The predefined constant BLINK exists for this purpose.
    For example:

    textcolor(CYAN + BLINK);

    Note: Some monitors do not recognize the intensity signal used to create the eight "light" colors (8-15). On such monitors, the light colors are displayed as their "dark" equivalents (0-7). Also, systems that do not display in color can treat these numbers as shades of one color, special patterns, or special attributes (such as underlined, bold, italics, and so on). Exactly what you'll see on such systems depends on your hardware.

    Return Value: None.


    textbackground

    Syntax

    #include <conio.h>
    void textbackground(int newcolor);

    Description

    Selects new text background color.

    Note: Do not use this function for Win32s or Win32 GUI applications.

    textbackground selects the background color. This function works for functions that produce output in text mode directly to the screen. newcolor selects the new background color. You can set newcolor to an integer from 0 to 7, or to one of the symbolic constants defined in conio.h. If you use symbolic constants, you must include conio.h.
    Once you have called textbackground, all subsequent functions using direct video output (such as cprintf) will use newcolor. textbackground does not affect any characters currently onscreen.

    The following table lists the symbolic constants and the numeric values of the allowable colors:

    Symbolic constant Numeric value

    BLACK 0
    BLUE 1
    GREEN 2
    CYAN 3
    RED 4
    MAGENTA 5
    BROWN 6
    LIGHTGRAY 7

    Return Value: None.



    Use cprintf() to print coloured text
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    I am the worst best coder Quantrizi's Avatar
    Join Date
    Mar 2002
    Posts
    644
    NOTE: You can also use these in C++.

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    If you'd like to speed-anhance your program, make your own out of Assembly language. It's a basic function, so you could find out how exactly to do this by just looking in any decent book for a a minute, and also look at the aforementioned files with a text editor, to gve you an idea of the system they used,

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Internet Programming for DOS Console
    By KoolFriend in forum C++ Programming
    Replies: 9
    Last Post: 09-27-2004, 10:49 AM
  2. Console DOS/ Dos
    By jkw2068 in forum C++ Programming
    Replies: 5
    Last Post: 07-31-2003, 09:28 AM
  3. colors in DOS console based applications
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 06-09-2002, 10:37 PM
  4. DOS program versus DOS console program
    By scromer in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 01-10-2002, 01:42 PM