|
-
October 21st, 1999, 09:42 PM
#1
How to change the text color for a console app?
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.
-
October 24th, 1999, 05:10 PM
#2
Re: How to change the text color for a console app?
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|