C C 控制台輸出時設定字型及背景顏色

2021-05-21 13:42:01 字數 3178 閱讀 9913

1.改變整個控制台的顏色

用system("color 0a");

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

0=黑色

1=藍色

2=綠色

3=湖藍色

4=紅色

5=紫色

6=黃色

7=白色

8=灰色

9=淡藍色

a=淡綠色

b=淡淺綠色

c=淡紅色

d=淡紫色

e=淡黃色

f=亮白色

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

函式原型:

boolsetconsoletextattribute(handlehconsoleoutput, wordwattributes);

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 C 控制台輸出時設定字型及背景顏色

0.設定控制台輸出行數和列數 system mode con cols 100 lines 20000 1.改變整個控制台的顏色 用 system color 0a 其中color後面的0是背景色代號,a是前景色代號。各顏色 如下 0 黑色 1 藍色 2 綠色 3 湖藍色 4 紅色 5 紫色 6 黃...

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

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

PowerShell控制台字型設定

1 開啟登錄檔 hkey current user console systemroot system32 windowspowershell v1.0 powershell.exe 2 找到鍵值 codepage 將資料改為 437 注意10進製 3 這樣就該後,只有直接開啟powershell....