Search code examples
winapiwindows-console

C++ set font color to black


PS: I am using Code::blocks
no conio2.h available

I want to set the font color to black by windows API

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), XXXXXX);

What should I fill in XXXXXX?


Solution

  • From the documentation:

    The foreground attributes specify the text color. The background attributes specify the color used to fill the cell's background. The other attributes are used with DBCS.

    An application can combine the foreground and background constants to achieve different colors. For example, the following combination results in bright cyan text on a blue background.

    FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY | BACKGROUND_BLUE\
    

    If no background constant is specified, the background is black, and if no foreground constant is specified, the text is black. For example, the following combination produces black text on a white background.

    BACKGROUND_BLUE | BACKGROUND_GREEN | BACKGROUND_RED