控制台程序單調的黑色底調,白色字給人一種壓抑的感覺,但是系統是提供給我們
api來顯示不同的顏色。下面是一段代碼。
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils, Windows;
var
consolehwnd : THandle;
i : Integer;
begin
consolehwnd := GetStdHandle(STD_OUTPUT_HANDLE);//取得輸出句柄- STD_INPUT_HANDLE輸入
SetConsoleTitle('http://www.pggpjj.com');//設置console windowtitle
SetConsoleTextAttribute(consolehwnd,FOREGROUND_BLUE);//設置輸出字體顏色--
Writeln('我是P哥!!');
SetConsoleTextAttribute(consolehwnd,FOREGROUND_RED);
Writeln('我的人生格言');
SetconsoleTextAttribute(consolehwnd,FOREGROUND_GREEN);
Writeln('自己的命運自己把握');
SetConsoleTextAttribute(consolehwnd,FOREGROUND_BLUE);
for i := 1 to 10 do
case i of
1: Writeln(' * ');
2: Writeln(' ***');
3: Writeln(' *****');
4: Writeln(' *******');
5: Writeln('[]D [] []/[] []D');
6: Writeln(' *******');
7: Writeln(' *****');
8: Writeln(' ***');
9: Writeln(' *');
10:writeln('走自己的路讓別人去說吧!');
end;
SetConsoleTextAttribute(consolehwnd,RGB(100,200,255));//這是底色
Writeln('--潘國光---浙江海洋學院--A02電氣(1)-QQ:68848864');
Readln;
end.
----------------
自己可以看一下,自己用一下面的api
function SetConsoleActiveScreenBuffer; external kernel32 name 'SetConsoleActiveScreenBuffer';
function SetConsoleCP; external kernel32 name 'SetConsoleCP';
function SetConsoleCtrlHandler; external kernel32 name 'SetConsoleCtrlHandler';
function SetConsoleCursorInfo; external kernel32 name 'SetConsoleCursorInfo';
function SetConsoleCursorPosition; external kernel32 name 'SetConsoleCursorPosition';
function SetConsoleMode; external kernel32 name 'SetConsoleMode';
function SetConsoleOutputCP; external kernel32 name 'SetConsoleOutputCP';
function SetConsoleScreenBufferSize; external kernel32 name 'SetConsoleScreenBufferSize';
function SetConsoleTextAttribute; external kernel32 name 'SetConsoleTextAttribute';
function SetConsoleTitle; external kernel32 name 'SetConsoleTitleA';
function SetConsoleTitleA; external kernel32 name 'SetConsoleTitleA';
function SetConsoleTitleW; external kernel32 name 'SetConsoleTitleW';
function SetConsoleWindowInfo; external kernel32 name 'SetConsoleWindowInfo';