使用C++语言编写,如果想改成C语言,手动以GetProcAddress的方式来调用相关函数即可。
1 #include <windows.h> 2 #include <mmsystem.h> 3 #include <stdio.h> 4 5 #pragma comment(lib, "winmm.lib") 6 7 8 #define DATAFILE "BADAPPLE.txt" 9 10 #define FRAME_WIDTH 80 11 #define FRAME_HEIGHT 32 12 13 #define DATA_TOKEN_SIZE ( 5 + 1 ) // $0000 14 #define DATA_PITCH_SIZE ( FRAME_WIDTH + 1 ) // ###... 15 #define DATA_FRAME_SIZE ( DATA_TOKEN_SIZE + ( DATA_PITCH_SIZE * FRAME_HEIGHT ) ) 16 17 #define FRAME_COUNT 3271 18 19 #define VIDEO_TIME 218000.0f // 3:38 (218000ms) 20 21 22 void main(void) 23 { 24 HANDLE hOutput; 25 26 hOutput = GetStdHandle( STD_OUTPUT_HANDLE ); 27 28 CONSOLE_CURSOR_INFO coc = { 1, FALSE }; 29 COORD co = { FRAME_WIDTH, FRAME_HEIGHT }; 30 SMALL_RECT rc = { 0, 0, FRAME_WIDTH - 1, FRAME_HEIGHT - 1 }; 31 32 SetConsoleCursorInfo( hOutput, &coc ); 33 SetConsoleScreenBufferSize( hOutput, co ); 34 SetConsoleWindowInfo( hOutput, TRUE, &rc ); 35 36 SetConsoleTitle( "Bad Apple By Crsky @2016" ); 37 38 FILE *fp; 39 int size; 40 char *buf; 41 char *cur; 42 int start; 43 44 buf = NULL; 45 46 fp = fopen( DATAFILE, "rb" ); 47 48 if ( !fp ) 49 { 50 printf( "%s not found. ", DATAFILE ); 51 goto err; 52 } 53 54 size = DATA_FRAME_SIZE * FRAME_COUNT; 55 56 buf = new char[ size ]; 57 58 if ( fread( buf, size - 1, 1, fp ) != 1 ) 59 { 60 printf( "Failed to read in data file. " ); 61 goto err; 62 } 63 64 buf[ size - 1 ] = '