-
August 19th, 2013, 05:14 PM
#1
[RESOLVED] can anyone tell me all colors const for SetConsoleTextAttribute() function?
i have these nice function for change the textcolor\backcolor:
Code:
void SetColorAndBackground(int ForgC, int BackC){
WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
return;
}
but can anyone tell me the colors const and and how can i blink?
-
August 20th, 2013, 03:17 AM
#2
Re: can anyone tell me all colors const for SetConsoleTextAttribute() function?
Well, I have to repeat: why don't you want to read MSDN?
SetConsoleTextAttribute function
character attributes
Victor Nijegorodov
-
August 20th, 2013, 03:32 AM
#3
Re: can anyone tell me all colors const for SetConsoleTextAttribute() function?
-
August 20th, 2013, 03:59 AM
#4
Re: can anyone tell me all colors const for SetConsoleTextAttribute() function?
Well, whz reinvent the wheel?
From MSDN article Character Attributes:
The following attributes are defined in the Wincon.h header file.
Attribute FOREGROUND_BLUE Text color contains blue. FOREGROUND_GREEN Text color contains green. FOREGROUND_RED FOREGROUND_INTENSITY Text color is intensified. BACKGROUND_BLUE Background color contains blue. BACKGROUND_GREEN Background color contains green. BACKGROUND_RED Background color contains red. BACKGROUND_INTENSITY Background color is intensified.
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.
Code:
FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY | BACKGROUND_BLUE
And just FYI (from wincon.h):
Code:
#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.
Victor Nijegorodov
-
August 20th, 2013, 04:41 AM
#5
Re: can anyone tell me all colors const for SetConsoleTextAttribute() function?
Originally Posted by VictorN
Well, whz reinvent the wheel?
From MSDN article Character Attributes:
And just FYI (from wincon.h):
Code:
#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.
can you explain to me the COMMON_LVB_REVERSE_VIDEO atribute?
how can i combine the 'RGB' values?(imagine the yellow, how can i do it?)
(they don't show a sample)
-
August 20th, 2013, 05:07 AM
#6
Re: can anyone tell me all colors const for SetConsoleTextAttribute() function?
Originally Posted by Cambalinho
can you explain to me the COMMON_LVB_REVERSE_VIDEO atribute?
MSDN already did explain it! It is just to
Reverse foreground and background attribute.
In other words foreground attribute will be now applied to the foreground and v.v.
Originally Posted by Cambalinho
how can i combine the 'RGB' values?
Again. See MSDN
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.
Code:
FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_INTENSITY | BACKGROUND_BLUE
Originally Posted by Cambalinho
imagine the yellow, how can i do it?
Very simple! For the foreground color it is
Code:
FOREGROUND_BLUE | FOREGROUND_GREEN
for background
Code:
BACKGROUND_BLUE | BACKGROUND_GREEN
Victor Nijegorodov
-
August 20th, 2013, 05:09 AM
#7
Re: can anyone tell me all colors const for SetConsoleTextAttribute() function?
Originally Posted by VictorN
MSDN already did explain it! It is just toIn other words foreground attribute will be now applied to the foreground and v.v.
Again. See MSDN[/CODE]
Very simple! For the foreground color it is
Code:
FOREGROUND_BLUE | FOREGROUND_GREEN
for background
Code:
BACKGROUND_BLUE | BACKGROUND_GREEN
sorry. but i don't understand what means these:
"Reverse foreground and background attribute."
(i'm portguese)
is like the blink?
-
August 20th, 2013, 05:14 AM
#8
Re: can anyone tell me all colors const for SetConsoleTextAttribute() function?
Originally Posted by Cambalinho
sorry. but i don't understand what means these:
"Reverse foreground and background attribute."
(i'm portguese)
Did you try to use Englesh-Portguese dictionary? Or the Google-traslater?
Atributo primeiro plano eo fundo reverter
Originally Posted by Cambalinho
is like the blink?
No.
Victor Nijegorodov
-
August 20th, 2013, 05:16 AM
#9
Re: can anyone tell me all colors const for SetConsoleTextAttribute() function?
Originally Posted by VictorN
Did you try to use Englesh-Portguese dictionary? Or the Google-traslater?
No.
sorry something.. and thanks for all.. realy thanks
-
August 20th, 2013, 06:16 AM
#10
Re: [RESOLVED] can anyone tell me all colors const for SetConsoleTextAttribute() func
This may be of help
Code:
//Define extra colours
#define FOREGROUND_WHITE (FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN)
#define FOREGROUND_YELLOW (FOREGROUND_RED | FOREGROUND_GREEN)
#define FOREGROUND_CYAN (FOREGROUND_BLUE | FOREGROUND_GREEN)
#define FOREGROUND_MAGENTA (FOREGROUND_RED | FOREGROUND_BLUE)
#define FOREGROUND_BLACK 0
#define FOREGROUND_INTENSE_RED (FOREGROUND_RED | FOREGROUND_INTENSITY)
#define FOREGROUND_INTENSE_GREEN (FOREGROUND_GREEN | FOREGROUND_INTENSITY)
#define FOREGROUND_INTENSE_BLUE (FOREGROUND_BLUE | FOREGROUND_INTENSITY)
#define FOREGROUND_INTENSE_WHITE (FOREGROUND_WHITE | FOREGROUND_INTENSITY)
#define FOREGROUND_INTENSE_YELLOW (FOREGROUND_YELLOW | FOREGROUND_INTENSITY)
#define FOREGROUND_INTENSE_CYAN (FOREGROUND_CYAN | FOREGROUND_INTENSITY)
#define FOREGROUND_INTENSE_MAGENTA (FOREGROUND_MAGENTA | FOREGROUND_INTENSITY)
#define BACKGROUND_WHITE (BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_GREEN)
#define BACKGROUND_YELLOW (BACKGROUND_RED | BACKGROUND_GREEN)
#define BACKGROUND_CYAN (BACKGROUND_BLUE | BACKGROUND_GREEN)
#define BACKGROUND_MAGENTA (BACKGROUND_RED | BACKGROUND_BLUE)
#define BACKGROUND_BLACK 0
#define BACKGROUND_INTENSE_RED (BACKGROUND_RED | BACKGROUND_INTENSITY)
#define BACKGROUND_INTENSE_GREEN (BACKGROUND_GREEN | BACKGROUND_INTENSITY)
#define BACKGROUND_INTENSE_BLUE (BACKGROUND_BLUE | BACKGROUND_INTENSITY)
#define BACKGROUND_INTENSE_WHITE (BACKGROUND_WHITE | BACKGROUND_INTENSITY)
#define BACKGROUND_INTENSE_YELLOW (BACKGROUND_YELLOW | BACKGROUND_INTENSITY)
#define BACKGROUND_INTENSE_CYAN (BACKGROUND_CYAN | BACKGROUND_INTENSITY)
#define BACKGROUND_INTENSE_MAGENTA (BACKGROUND_MAGENTA | BACKGROUND_INTENSITY)
There is no default mechanism to blink a character on screen. if you want this, it can be done by first reversing (exchanging) foreground and background attributes (COMMON_LVB_REVERSE_VIDEO) then setting a timer for the required blink period then reversing foreground and background attributes when timer triggers.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
August 20th, 2013, 06:27 AM
#11
Re: [RESOLVED] can anyone tell me all colors const for SetConsoleTextAttribute() func
Originally Posted by 2kaud
This may be of help
Code:
//Define extra colours
#define FOREGROUND_WHITE (FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN)
#define FOREGROUND_YELLOW (FOREGROUND_RED | FOREGROUND_GREEN)
#define FOREGROUND_CYAN (FOREGROUND_BLUE | FOREGROUND_GREEN)
#define FOREGROUND_MAGENTA (FOREGROUND_RED | FOREGROUND_BLUE)
#define FOREGROUND_BLACK 0
#define FOREGROUND_INTENSE_RED (FOREGROUND_RED | FOREGROUND_INTENSITY)
#define FOREGROUND_INTENSE_GREEN (FOREGROUND_GREEN | FOREGROUND_INTENSITY)
#define FOREGROUND_INTENSE_BLUE (FOREGROUND_BLUE | FOREGROUND_INTENSITY)
#define FOREGROUND_INTENSE_WHITE (FOREGROUND_WHITE | FOREGROUND_INTENSITY)
#define FOREGROUND_INTENSE_YELLOW (FOREGROUND_YELLOW | FOREGROUND_INTENSITY)
#define FOREGROUND_INTENSE_CYAN (FOREGROUND_CYAN | FOREGROUND_INTENSITY)
#define FOREGROUND_INTENSE_MAGENTA (FOREGROUND_MAGENTA | FOREGROUND_INTENSITY)
#define BACKGROUND_WHITE (BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_GREEN)
#define BACKGROUND_YELLOW (BACKGROUND_RED | BACKGROUND_GREEN)
#define BACKGROUND_CYAN (BACKGROUND_BLUE | BACKGROUND_GREEN)
#define BACKGROUND_MAGENTA (BACKGROUND_RED | BACKGROUND_BLUE)
#define BACKGROUND_BLACK 0
#define BACKGROUND_INTENSE_RED (BACKGROUND_RED | BACKGROUND_INTENSITY)
#define BACKGROUND_INTENSE_GREEN (BACKGROUND_GREEN | BACKGROUND_INTENSITY)
#define BACKGROUND_INTENSE_BLUE (BACKGROUND_BLUE | BACKGROUND_INTENSITY)
#define BACKGROUND_INTENSE_WHITE (BACKGROUND_WHITE | BACKGROUND_INTENSITY)
#define BACKGROUND_INTENSE_YELLOW (BACKGROUND_YELLOW | BACKGROUND_INTENSITY)
#define BACKGROUND_INTENSE_CYAN (BACKGROUND_CYAN | BACKGROUND_INTENSITY)
#define BACKGROUND_INTENSE_MAGENTA (BACKGROUND_MAGENTA | BACKGROUND_INTENSITY)
There is no default mechanism to blink a character on screen. if you want this, it can be done by first reversing (exchanging) foreground and background attributes (COMMON_LVB_REVERSE_VIDEO) then setting a timer for the required blink period then reversing foreground and background attributes when timer triggers.
see the code:
Code:
void SetColorAndBackground(int ForgC, int BackC=0, bool Blink=false)
{
if (Blink==false)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), ForgC|BackC );
}
else
{
for (;;)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), ForgC|COMMON_LVB_REVERSE_VIDEO|BackC );
Sleep(1000);
}
}
}
what i'm doing wrong?
i try put some text before 'sleep()', but isn't blinking
i have another way, but i don't finish the MultiThread class
-
August 20th, 2013, 06:43 AM
#12
Re: [RESOLVED] can anyone tell me all colors const for SetConsoleTextAttribute() func
Set ConsoleText Attribute sets the attribute for text that follows on the screen. So if you put some text on the screen then call your function, you have to move the cursor back to the character you want to blink in your function before calling SetConsoleTextAttribute - or set the cursor back to the start of the text in the calling program.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
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
|