1 #include"stdio.h" 2 #include"stdlib.h" 3 #include"windows.h" 4 //note1<可通过mode 来设置命令窗口大小,其中参数范围lines(1~168),cols(13~9001);命令 mode con cols=9001 lines=168> 5 //note2<对于调用CMD命令中的参数,可包含在格式化的字符串中,即用sprintf()函数将CMD命令行格式化成字符串传给system()> 6 //note3<sprintf(char *buffer,"字符串格式",[argument]),buffer是字符串缓冲区,传给system()的地址,[argument]是指参数列表> 7 //note4<注意头文件:sprintf()[stdio.h] pause[stdlib.h] system()[windows.h]> 8 //note5<pause会输出“按任意键继续...”的提示,pause>nul 可以实现屏蔽其实的作用;echo 提示 &pause>nul 实现暂停并显示自定义的提示> 9 /* 10 void winSize(int lines,int cols) 11 自定义命令窗口大小 12 */ 13 void winSize(int lines_height,int cols_width) 14 { 15 char cmd[100]; 16 if((lines_height<1)||(lines_height>168)||(cols_width<13)||(cols_width>9001)) 17 { 18 printf("\nWarnning from winSize(): 1<=lines_height<=168 13<=cols_width<=9001 \n"); 19 lines_height=168; 20 cols_width=9001; 21 } 22 sprintf(cmd,"mode con cols=%d lines=%d",lines_height,cols_width); 23 system(cmd); 24 } 25 void main() 26 { 27 system("echo The size of this window will be CHANGED! Press any key ... & pause>nul"); 28 winSize(80,40); 29 system("echo The size of this window will RECOVER! Press any key... & pause>nul"); 30 winSize(168,9001); 31 }