關於c 顏色的控制

2021-08-06 00:20:49 字數 3146 閱讀 2386

1.

改變整個控制台的顏色

用 system("color 0a"); 

其中color後面的0是背景色代號,a是前景色代號。各顏色**如下: 

0=黑色 

1=藍色 

2=綠色 

3=湖藍色 

4=紅色 

5=紫色 

6=黃色 

7=白色 

8=灰色 

9=淡藍色 

a=淡綠色 

b=淡淺綠色 

c=淡紅色 

d=淡紫色 

e=淡黃色 

f=亮白色 

[cpp]

view plain

copy

print?

void account::entrance()  

if(n=='1')   

if(n=='2') m.select();  

if(n=='3') return;  

}  }   2.

改變下乙個輸出或者輸入字型和背景的顏色

採用setconsoletextattribute函式,如

white on black:

setconsoletextattribute(getstdhandle(std_output_handle),foreground_intensity |

foreground_red | foreground_green | foreground_blue);

red on black:

setconsoletextattribute(getstdhandle(std_output_handle),foreground_intensity |

foreground_red);

green on black:

setconsoletextattribute(getstdhandle(std_output_handle),foreground_intensity |

foreground_green);

yellow on black:

setconsoletextattribute(getstdhandle(std_output_handle),foreground_intensity |

foreground_red | foreground_green);

blue on black:

setconsoletextattribute(getstdhandle(std_output_handle),foreground_intensity |

foreground_blue);

magenta on black:

setconsoletextattribute(getstdhandle(std_output_handle),foreground_intensity |

foreground_red | foreground_blue);

cyan on black:

setconsoletextattribute(getstdhandle(std_output_handle),foreground_intensity |

foreground_green | foreground_blue);

black on gray:

setconsoletextattribute(getstdhandle(std_output_handle),background_intensity |

background_intensity);

black on white:

setconsoletextattribute(getstdhandle(std_output_handle),background_intensity |

foreground_intensity | background_red | background_green | background_blue);

red on white:

setconsoletextattribute(getstdhandle(std_output_handle),background_intensity |

foreground_intensity | background_red | background_green | background_blue |

foreground_red);

等等。需要引入標頭檔案:

windows.h

函式原型:

bool setconsoletextattribute( handle hconsoleoutput, word wattributes ); 

wattributes 的取值含義對應如下:

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. 

common_lvb_leading_byte leading byte. 

common_lvb_trailing_byte trailing byte. 

common_lvb_grid_horizontal top horizontal. 

common_lvb_grid_lvertical left vertical. 

common_lvb_grid_rvertical right vertical. 

common_lvb_reverse_video reverse foreground and background attributes. 

common_lvb_underscore underscore.

c 關於設定設定控制台背景及字型顏色

在包含裡面加上 include 然後呼叫system color 3f 顏色屬性由兩個十六進製制數字指定 第乙個為背景,第二個則為前景。每個數字可以為以下任何值之一 0 黑色 8 灰色 1 藍色 9 淡藍色 2 綠色 a 淡綠色 3 湖藍色 b 淡淺綠色 4 紅色 c 淡紅色 5 紫色 d 淡紫色 ...

bash 顏色控制

i.ansi控制碼 e 0m 關閉所有屬性 e 1m 粗體 e 4m 下劃線 e 5m 閃爍 e 7m 反顯 e 8m 消隱 e 22m 非粗體 e 24m 關閉下劃線 e 25m 關閉閃爍 e 27m 關閉反顯 e 30m e 37m 設定前景色 e 40m e 47m 設定背景色 0 黑 1 紅...

Shell 控制台顏色控制

輸出特效格式控制 033 0m 關閉所有屬性 033 1m 設定高亮度 03 4m 下劃線 033 5m 閃爍 033 7m 反顯 033 8m 消隱 033 30m 033 37m 設定前景色 033 40m 033 47m 設定背景色 游標位置等的格式控制 033 na 游標上移n行 03 nb...