推薦軟硬體、網站

Google Adsense

aNobii網路書櫃

2008年3月31日 星期一

[C/C++] 彩色輸出(使用Windows API)

[轉貼]改變字體顏色

無意中找到的
2s-I*N/p5O7}6R-o&l#X&J9n%q%](}/w-B)i"h
1 #include "iostream.h" www.phate.tw3F3R!y"`;p(o;_%I.j(j#x
2 #include "windows.h"
/e9K*B&K!`,E-n'T,Q(I3 main() ;s:Y4]#I8~*e5i%B:~!T/S
4 { www.phate.tw5B/};?'U9R+Q2g4v4]
5 printf("以下為前景字顏色\n");
'x"A7v.h2T&j&N6 //紅色 |+o*@(w,z4}'`7}%t"I
7 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_RED); www.phate.tw:g!|%R9h8Y%R
8 printf("Hello(Red)\n");
;V7k&t%~%P7`'L;^+m-J0s.: Phate Technology :.9 //藍色
k8L-d;C3]4R:C/q8o10 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_GREEN);
3k2h${;J#m)R5i%`:@1w4x.: Phate Technology :.11 printf("Hello(Green)\n");
"i-]*Z$T7]/a4g3i)m1U(v.: Phate Technology :.12 //綠色
"M(? ]%{1]:Y9^ Z ^13 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_BLUE);
+T2|!X!W0Twww.phate.tw14 printf("Hello(Blue)\n"); ,|%D h(o&k:],F-z$U
15 //黃色=紅+綠 www.phate.tw1R2C(b9j5_%}
16 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
(q,r!N9L0H17 printf("Hello(Yellow)\n");
2m.L,{+_(U*Q2W18 //紫色=紅+藍 .a7_$Z;X!R5o7i,t6h
19 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE); .: Phate Technology :.#B0Q;v4o0t
20 printf("Hello(Purple)\n"); +Y3i:E)@ m&U
21 //青綠色=綠+藍
/a4c u.A0M22 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE); 5x,n"a$m$B!m(q
23 printf("Hello(Cyan)\n"); .: Phate Technology :.!x7x8^ k8_8X'L7@%~&p
24 //白色=紅+綠+藍 (`.g&^/F1y2`,f
25 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
*|9?$l'v6g8X1w;y*K.: Phate Technology :.26 printf("Hello(White)\n\n");
2U"V#S8L2c4_"o!F27 !P!f3j$D4M7Y4Q9k
28 printf("以下為背景顏色\n"); #Q4|*O1I9f
29 //背景紅色 "R+E*D,f#j:O!Z*Z
30 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY | FOREGROUND_INTENSITY | BACKGROUND_RED);
+a-X7l#^.B9F)m$w,s31 printf("Hello(Back_Red)\n");
9a%^,[8\+~.O:F32 //背景藍色
7\4`;c-k1M7U33 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY | FOREGROUND_INTENSITY | BACKGROUND_BLUE);
$m-x&m;H!p2_$b7h3w.u"C34 printf("Hello(Back_Blue)\n");
4b;|#o$S+A'X!f2I*e6E&E35 //背景綠色 +d'Y(g5e S
36 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY | FOREGROUND_INTENSITY | BACKGROUND_GREEN);
4y'f![0O5D4]-N5i37 printf("Hello(Back_Green)\n");
.j,E%[:Y6?!W$H4^%K*z-K0P4i38 //背景黃色=紅+綠 .: Phate Technology :..\9s;X6|'X(m9`"~
39 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY | FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN); www.phate.tw#?4\.c {8s:p2w:P7g0^(c
40 printf("Hello(Back_Yellow)\n"); 9t$K1e${*e2T
41 //背景紫色=紅+藍 +k'F2p:X8X*? T8P5E
42 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY | FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_BLUE); 8^8Q0^5R0F$u$F
43 printf("Hello(Back_Purple)\n");
*O%]:l7n5?&p'U;U"S"j"^44 //背景青綠色=綠+藍 ;b8W+Q7K%r$g#x'L;}2h
45 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY | FOREGROUND_INTENSITY | BACKGROUND_GREEN | BACKGROUND_BLUE);
&x(Z3r8{3H"B6b46 printf("Hello(Back_Cyan)\n");
#{;r0_)W0J*N)I%n47 //背景白色=紅+綠+藍 $e2s0^4n%B.K
48 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY | FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE);
*P:B!J8M7t$U#z49 printf("Hello(Back_White)\n"); .: Phate Technology :.7t.g3r9I!b y
50 getchar();
5n/e4Z5K5?-R;O51 }

沒有留言:

張貼留言

Powered By Blogger

Google Analytics