資源描述:
《控制顏色輸出.doc》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫(kù)。
1、改變整個(gè)控制臺(tái)的顏色用system("color0A");其中color后面的0是背景色代號(hào),A是前景色代號(hào)。各顏色代碼如下:0=黑色1=藍(lán)色2=綠色3=湖藍(lán)色4=紅色5=紫色6=黃色7=白色8=灰色9=淡藍(lán)色A=淡綠色B=淡淺綠色C=淡紅色D=淡紫色E=淡黃色F=亮白色改變下一個(gè)輸出或者輸入字體和背景的顏色采用SetConsoleTextAttribute函數(shù),如WhiteonBlack:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY
2、FOREGROUND_RED
3、FOREGROUND
4、_GREEN
5、FOREGROUND_BLUE);RedonBlack:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY
6、FOREGROUND_RED);GreenonBlack:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY
7、FOREGROUND_GREEN);YellowonBlack:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_H
8、ANDLE),FOREGROUND_INTENSITY
9、FOREGROUND_RED
10、FOREGROUND_GREEN);BlueonBlack:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY
11、FOREGROUND_BLUE);MagentaonBlack:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY
12、FOREGROUND_RED
13、FOREGROUND_BLUE);CyanonBl
14、ack:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY
15、FOREGROUND_GREEN
16、FOREGROUND_BLUE);BlackonGray:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY
17、BACKGROUND_INTENSITY);BlackonWhite:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACK
18、GROUND_INTENSITY
19、FOREGROUND_INTENSITY
20、BACKGROUND_RED
21、BACKGROUND_GREEN
22、BACKGROUND_BLUE);RedonWhite:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY
23、FOREGROUND_INTENSITY
24、BACKGROUND_RED
25、BACKGROUND_GREEN
26、BACKGROUND_BLUE
27、FOREGROUND_RED);等等。需要引入頭文件:windows.h函數(shù)原型:BOOLSetConsole
28、TextAttribute(HANDLEhConsoleOutput,WORDwAttributes);wAttributes的取值含義對(duì)應(yīng)如下:AttributeMeaningFOREGROUND_BLUETextcolorcontainsblue.FOREGROUND_GREENTextcolorcontainsgreen.FOREGROUND_REDTextcolorcontainsred.FOREGROUND_INTENSITYTextcolorisintensified.BACKGROUND_BLUEBackgroundcolorcontainsblue.BACKGROUND_GR
29、EENBackgroundcolorcontainsgreen.BACKGROUND_REDBackgroundcolorcontainsred.BACKGROUND_INTENSITYBackgroundcolorisintensified.COMMON_LVB_LEADING_BYTELeadingbyte.COMMON_LVB_TRAILING_BYTETrailingbyte.COMMON_LVB_G