I'm writing a console program and would like to display some of the characters (text) in yellow when in the DOS Prompt Box,
how do I code it ?
Thanks and regards.
Printable View
I'm writing a console program and would like to display some of the characters (text) in yellow when in the DOS Prompt Box,
how do I code it ?
Thanks and regards.
Hi,
Use the API function SetConsoleTextAttribute.
First, you need a handle to the screen buffer, if you are using standard I/O you can get this with a call to GetStdHandle:
// Begin snippet
HANDLE hScreen;
hScreen = GetStdHandle (STD_OUTPUT_HANDLE);
// Set the console text to green on a blue background
SetConsoleTextAttribute (hScreen, FOREGROUND_GREEN | BACKGROUND_BLUE);
// End Snippet
The second paramater to SetConsoleTextAttribute specifies the colours and can be a combination of the following values:
FOREGROUND_RED, FOREGROUND_GREEN, FOREGROUND_BLUE, FOREGROUND_INTENSITY, BACKGROUND_RED, BACKGROUND_GREEN, BACKGROUND_BLUE, and BACKGROUND_INTENSITY.
Hope this helps.
Darren.