Re: [語法] 用c++寫閃爍

看板C_and_CPP (C/C++)作者 (小虎)時間18年前 (2006/12/22 23:35), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
MSVC CRT限用 #include <windows.h> #include <stdio.h> char spacebuf[128] =" "; #define MAXBUFSIZE 4096 int printf (const char *format, ...) { int n_chars,count=0; char output[MAXBUFSIZE]; HANDLE stdout_handle; va_list argptr; va_start (argptr, format); stdout_handle = GetStdHandle (STD_OUTPUT_HANDLE); n_chars = vsprintf (output, format, argptr); while(n_chars>count) { int num; unsigned long written; if(*(output+count)==0x1b&&*(output+count+1)=='[') { int new_attr; CONSOLE_SCREEN_BUFFER_INFO info; GetConsoleScreenBufferInfo (stdout_handle, &info); new_attr = info.wAttributes; count++; AGAIN: count++; for(num=0;*(output+count)>='0'&&*(output+count)<='9';count++) num=(num*10)+(*(output+count)-0x30); if(num>=40) { num-=40; new_attr=(new_attr&0x8f)+((num&1)<<6)+((num&2)<<4)+((num&4)<<2); } else if(num>=30) { num-=30; new_attr=(new_attr&0xf8)+((num&1)<<2)+((num&2) )+((num&4)>>2); } else switch(num) { case 5: new_attr|=BACKGROUND_INTENSITY; break; case 1: new_attr|=FOREGROUND_INTENSITY; break; case 0: new_attr=(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE); break; } if (*(output+count)==';') goto AGAIN; else if (*(output+count)=='m') SetConsoleTextAttribute (stdout_handle, new_attr); else if (*(output+count)=='J'&&num==2) {} //cls code... else if (*(output+count)=='K') WriteConsole(stdout_handle,spacebuf,info.dwSize.X-info.dwCursorPosition.X-1,&written,0); else goto NOANSI; count++; } NOANSI: for(num=0;*(output+count+num)!=0x1b&&*(output+count+num)!=0;num++); WriteConsole(stdout_handle,output+count,num,&written,0); count+=num; } return n_chars; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.120.96.114
文章代碼(AID): #15Y_jVCQ (C_and_CPP)
文章代碼(AID): #15Y_jVCQ (C_and_CPP)