CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Apr 2009
    Posts
    1,355

    [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?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    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

  3. #3
    Join Date
    Apr 2009
    Posts
    1,355

    Re: can anyone tell me all colors const for SetConsoleTextAttribute() function?

    Quote Originally Posted by VictorN View Post
    Well, I have to repeat: why don't you want to read MSDN?
    SetConsoleTextAttribute function
    character attributes
    sorry.. don't be mad with me. the msdn is limited in very ways
    i have now the const that i can use them:
    Code:
    #define BLACK			0
    #define BLUE			1
    #define GREEN			2
    #define CYAN			3
    #define RED				4
    #define MAGENTA			5
    #define BROWN			6
    #define LIGHTGRAY		7
    #define DARKGRAY		8
    #define LIGHTBLUE		9
    #define LIGHTGREEN		10
    #define LIGHTCYAN		11
    #define LIGHTRED		12
    #define LIGHTMAGENTA	13
    #define YELLOW			14
    #define WHITE			15
    
    
    void SetColorAndBackground(int ForgC, int BackC=0)
    	{
    		WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);
    		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);		
    	}
    i can't blink, but i think that i can do it, after i complete 1 little class.
    (i have tested all colors and works)
    let me ask you something: can you see all these colors in msdn?(that links you give me)
    sorry but i don't like, not all there, how they explain and don't tell me all
    or i need study how they tells us the things
    (i will share the blink thing... the SetConsoleTextAttribute() can't do the blink, but i can do it )

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    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
    Meaning
    FOREGROUND_BLUE
    Text color contains blue.
    FOREGROUND_GREEN
    Text color contains green.
    FOREGROUND_RED
    Text color contains 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

  5. #5
    Join Date
    Apr 2009
    Posts
    1,355

    Re: can anyone tell me all colors const for SetConsoleTextAttribute() function?

    Quote Originally Posted by VictorN View Post
    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)

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: can anyone tell me all colors const for SetConsoleTextAttribute() function?

    Quote Originally Posted by Cambalinho View Post
    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.

    Quote Originally Posted by Cambalinho View Post
    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
    Quote Originally Posted by Cambalinho View Post
    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

  7. #7
    Join Date
    Apr 2009
    Posts
    1,355

    Re: can anyone tell me all colors const for SetConsoleTextAttribute() function?

    Quote Originally Posted by VictorN View Post
    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?

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,395

    Re: can anyone tell me all colors const for SetConsoleTextAttribute() function?

    Quote Originally Posted by Cambalinho View Post
    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
    Quote Originally Posted by Cambalinho View Post
    is like the blink?
    No.
    Victor Nijegorodov

  9. #9
    Join Date
    Apr 2009
    Posts
    1,355

    Re: can anyone tell me all colors const for SetConsoleTextAttribute() function?

    Quote Originally Posted by VictorN View Post
    Did you try to use Englesh-Portguese dictionary? Or the Google-traslater?

    No.
    sorry something.. and thanks for all.. realy thanks

  10. #10
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    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)

  11. #11
    Join Date
    Apr 2009
    Posts
    1,355

    Re: [RESOLVED] can anyone tell me all colors const for SetConsoleTextAttribute() func

    Quote Originally Posted by 2kaud View Post
    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

  12. #12
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    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
  •  





Click Here to Expand Forum to Full Width

Featured