CMD 控制台 程式設計 例子

2021-05-22 05:11:24 字數 3065 閱讀 4863

很酷的程式

讓我想起dos下的遊戲程式設計 呵呵

code from internet

//#include "stdafx.h"

// for winxp

/* bounce - creates a new thread each time the letter 'a' is typed.

* all threads are terminated when the letter 'q' is entered.

* * this program requires the multithread library. for example, compile

* with the following command line:

* cl /mt bounce.c

*/#include #include #include #include #include #include #define max_threads 32

/* getrandom returns a random number between min and max, which must be in

* integer range.

*/#define getrandom( min, max ) ((rand() % (int)(((max) + 1) - (min))) + (min))

int main( void ); /* thread 1: main */

void kbdfunc( void ); /* keyboard input, thread dispatch */

void bounceproc( void * myid ); /* threads 2 to n: display */

void clearscreen( void ); /* screen clear */

void shutdown( void ); /* program shutdown */

void writetitle( int threadnum ); /* display title bar information */

handle hconsoleout; /* handle to the console */

handle hrunmutex; /* "keep running" mutex */

handle hscreenmutex; /* "screen update" mutex */

int threadnr; /* number of threads started */

console_screen_buffer_info csbiinfo; /* console information */

int main() /* thread one */

void shutdown( void ) /* shut down threads */

/* clean up display when done */

waitforsingleobject( hscreenmutex, infinite );

clearscreen();

}void kbdfunc( void ) /* dispatch and count threads. */

} while( tolower( keyinfo ) != 'q' );

shutdown();

}void bounceproc( void *myid )

; dword dummy;

/* generate update increments and initial display coordinates. */

srand( (unsigned) *(pchar)myid * 3 );

coords.x = getrandom( 0, csbiinfo.dwsize.x - 1 );

coords.y = getrandom( 0, csbiinfo.dwsize.y - 1 );

delta.x = getrandom( -3, 3 );

delta.y = getrandom( -3, 3 );

if( *(pchar)myid > 16)

mycell = 0x01; /* outline face */

else

mycell = 0x02; /* solid face */

myattrib = *(pchar)myid & 0x0f; /* force black background */

doif( coords.y < 0 || coords.y > csbiinfo.dwsize.y )

}/* repeat while runmutex is still taken. */

while ( waitforsingleobject( hrunmutex, 75l ) == wait_timeout );

}void writetitle( int threadnum )

void clearscreen( void )

; fillconsoleoutputcharacter( hconsoleout, ' ', csbiinfo.dwsize.x * csbiinfo.dwsize.y, home, &dummy );}

進一步研究 請

以下有用資訊

「控制台視窗介面的程式設計控制」

翻譯一篇文章introduction to multi-threaded code 多執行緒程式設計的一些**

使用 c 和 win32 進行多執行緒程式設計

windows 環境下的多執行緒程式設計原理小結

C 控制台CMD輔助類

using system using system.collections.generic using system.diagnostics using system.io using system.text using gh.commons.log namespace oracleimpexp.u...

eC 控制台程式設計

ecere 讀音像easy,簡稱ec 支援ec,c,c gcc,objc,控制台 即,cmd line console 好了 開始了 執行ec ide,project new 輸入工程名 如,ctest 取消create form前的勾,ok,alt zero跳到project view epj上右...

控制台 cmd 中文顯示為亂碼

臨時解決方案 在 cmd 中執行 chcp 936。永久解決方案 開啟不正常的 cmd 或命令提示符視窗後,單擊視窗左上角的圖示,選擇彈出的選單中的 預設值 開啟如下圖的對話方塊。單擊第乙個 選項 選項卡,將預設的 頁改為 936 後重啟 cmd。附 如果改了以後無法生效,視窗的 預設值 和 屬性 ...