控制台輸出控制

2021-04-13 02:25:05 字數 868 閱讀 9102

//by jingzhongrong

通過win32api提供的函式,可以對控制台程式的輸出進行控制,例如字型顏色、標題文字,以及各種屬性等等。

主要使用到的函式以及宣告如下:

handle getstdhandle(

dword nstdhandle

);此函式用於獲取控制台輸出、輸入控制代碼。得到控制代碼之後便可以對輸出進行修改了。

下面是幾個用於修改的函式,其他函式請檢視msdn獲取更詳細的說明。

//用於獲得當前控制台的輸出屬性,用於恢復。

bool getconsolescreenbufferinfo(

handle hconsoleoutput,

pconsole_screen_buffer_info lpconsolescreenbufferinfo

);//用於修改輸出字型顏色

bool setconsoletextattribute(

handle hconsoleoutput,

word wattributes

);更多函式請查詢msdn上console functions。

more information please look for msdn with 「console functions」.

以下是示例**:

enum color

;handle stdouthandle;

word oldincolorattr;

void writeln(color color,char* s)

bool setcolor(color colo)

//by jingzhongrong

bool setdefault()

void main()

讀取控制台輸出

在新建工程窗體中新增button1 memo1 unit unit1 inte ce uses windows,messages,sysutils,variants,classes,graphics,controls,forms,dialogs,stdctrls,extctrls type tfor...

QT 控制台輸出

首先在標頭檔案中包含 include 在需要使用的地方插入 qdebug intensity d intensity 0 2 d表示整數 輸出結果 intensity 195 注 a,a 讀入乙個浮點值 僅c99有效 c 讀入乙個字元 d 讀入十進位制整數 i 讀入十進位制,八進位制,十六進製制整數...

C 控制台輸出

建立console應用程式 using system using system.collections.generic using system.linq using system.text namespace byte 資料型別 byte 變數以無符號的 8 位 1 個位元組 數字的形式儲存,取值...