RGB Specific Console Text Color C++

后端 未结 3 932
你的背包
你的背包 2020-12-14 21:07

I\'m trying to set a win32 console application\'s font color to a specific RGB value like 50, 75, 90 respectively. I\'ve already tried SetConsoleTextAttribute()

3条回答
  •  萌比男神i
    2020-12-14 21:53

    You need to use SetConsoleScreenBufferInfoEx to set this, see the ColorTable entry of the CONSOLE_SCREEN_BUFFER_INFOEX struct.

    Console colors are a two-level process: there's the console attribute, which has four bits each for foreground and background (red, green, blue and intensity), which appears to limit the colors to the basic primary and secondary colors. But these values are used as indices to the color table, to determine the actual display value. So think of the character attribute 'color' bits as "logical red" etc rather than physical red. (The value that Character Attribute 'red' maps to is actually RGB red by default, but doesn't have to be.) So you're always limited to 16 indexed colors; but you can set those to whatever 16 full-RGB colors you want via the ColorTable.

    The strip of colored squares you see in the dialog above is essentially that color table, and lists the colors in their Character Attribute order, the first suqare being 'logical black', and so on.

提交回复
热议问题