User-defined color implementation in windows console
If there exist a better alternative (color enumerator) to my code which is?


You should use the constants defined in a Windows header file named Wincon.h, which are as follows:

#define FOREGROUND_BLUE      0x0001 // text color contains blue.
#define FOREGROUND_GREEN     0x0002 // text color contains green.
#define FOREGROUND_RED       0x0004 // text color contains red.
#define FOREGROUND_INTENSITY 0x0008 // text color is intensified.
#define BACKGROUND_BLUE      0x0010 // background color contains blue.
#define BACKGROUND_GREEN     0x0020 // background color contains green.
#define BACKGROUND_RED       0x0040 // background color contains red.
#define BACKGROUND_INTENSITY 0x0080 // background color is intensified.


For example, you could write:

enum COLOR
{
    // Text foreground colors
    // Standard text colors
    GRAY_TEXT=FOREGROUND_INTENSITY,
    BLUE_TEXT=FOREGROUND_BLUE,


The answers to C++ Win32 Console Color should be useful to you.

Alternatively here's a copy-and-paste of the equivalent .NET enum for C#, which I believe uses the same bit-values and assigns conventional color-names:

#region Assembly mscorlib.dll, v4.0.30319
// C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\mscorlib.dll
#endregion

namespace System
{
    // Summary:
    //     Specifies constants that define foreground and background colors for the
    //     console.
    [Serializable]
    public enum ConsoleColor
    {
        // Summary:
        //     The color black.
        Black = 0,
        //
        // Summary:
        //     The color dark blue.
        DarkBlue = 1,
        //
        // Summary:
        //     The color dark green.
        DarkGreen = 2,
        //
        // Summary:
        //     The color dark cyan (dark blue-green).
        DarkCyan = 3,
        //
        // Summary:
        //     The color dark red.
        DarkRed = 4,
        //
        // Summary:
        //     The color dark magenta (dark purplish-red).
        DarkMagenta = 5,
        //
        // Summary:
        //     The color dark yellow (ochre).
        DarkYellow = 6,
        //
        // Summary:
        //     The color gray.
        Gray = 7,
        //
        // Summary:
        //     The color dark gray.
        DarkGray = 8,
        //
        // Summary:
        //     The color blue.
        Blue = 9,
        //
        // Summary:
        //     The color green.
        Green = 10,
        //
        // Summary:
        //     The color cyan (blue-green).
        Cyan = 11,
        //
        // Summary:
        //     The color red.
        Red = 12,
        //
        // Summary:
        //     The color magenta (purplish-red).
        Magenta = 13,
        //
        // Summary:
        //     The color yellow.
        Yellow = 14,
        //
        // Summary:
        //     The color white.
        White = 15,
    }
}




If you're going to define your own enum then use it in your function declaration, i.e.:

BOOL setTextColor(HANDLE h, COLOR c)


... not ...

BOOL setTextColor(HANDLE h, WORD c)


I'd usually use mixed-case e.g. Color instead of COLOR for an enum; and I'd worry that it's already been defined in a header file.

Also I'd split it into two parameters instead of doubling the number of enum values, for example:

BOOL setTextColor(HANDLE h, ConsoleColor foregound, ConsoleColor background)
{
    WORD color = foregound | (background &lt;&lt; 4);
    return SetConsoleTextAttribute(h, color);
}