精華區beta C_and_CPP 關於我們 聯絡資訊
multiThread用法很簡單 就呼叫一個api而已 看是要用win sdk的CreateThread 還是用crt的_beginthread msdn都有範例 舉CreateThread來說 msdn的範例如下 (sorry 敝人有點懶 直接貼上來了) #include <windows.h> #include <conio.h> DWORD WINAPI ThreadFunc( LPVOID lpParam ) { char szMsg[80]; wsprintf( szMsg, "Parameter = %d.", *(DWORD*)lpParam ); MessageBox( NULL, szMsg, "ThreadFunc", MB_OK ); return 0; } VOID main( VOID ) { DWORD dwThreadId, dwThrdParam = 1; HANDLE hThread; char szMsg[80]; hThread = CreateThread( NULL, // default security attributes 0, // use default stack size ThreadFunc, // thread function &dwThrdParam, // argument to thread function 0, // use default creation flags &dwThreadId); // returns the thread identifier // Check the return value for success. if (hThread == NULL) { wsprintf( szMsg, "CreateThread failed." ); MessageBox( NULL, szMsg, "main", MB_OK ); } else { _getch(); CloseHandle( hThread ); } } 如上 希望對你有所幫助 助好運 ※ 引述《aroha (果然是個宅男 Orz)》之銘言: : 我是用VC來寫程式的 : 我用程式去跑一些大量的計算 : 想邊跑邊顯示目前的進度 : 可是因為程式太忙了 : 佔用100%的CPU : 所以只有剛開始跑會顯示 : 之後就停住了 : 就算我在程式中強制重畫,也是沒有辦法 : 請問一般都是怎麼克服這種情形的呀? : 我聽說好像用multithread可以克服 : 可是聽說有點麻煩,我怕會搞這個的時間遠大於寫程式的時間 : 這樣就不符合經濟效益了 : 想請問還有別的解決方法嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.133.97.122