|
《Windows游戏编程大师技巧》(第二版)第11章(23) // DEMO11_5.CPP - Creates a single thread that prints // simultaneously while the Primary thread prints. // INCLUDES //////////////////////////////////////////////// #define WIN32_LEAN_AND_MEAN // make sure win headers // are included correctly #include <windows.h> // include the standard windows stuff #include <windowsx.h> // include the 32 bit stuff #include <conio.h> #include <stdlib.h> #include <stdarg.h> #include <stdio.h> #include <math.h> #include <io.h> #include <fcntl.h> // DEFINES //////////////////////////////////////////////// // PROTOTYPES ////////////////////////////////////////////// DWORD WINAPI Printer_Thread(LPVOID data); // GLOBALS ///////////////////////////////////////////////// // FUNCTIONS /////////////////////////////////////////////// DWORD WINAPI Printer_Thread(LPVOID data) { // this thread function simply prints out data // 25 times with a slight delay for (int index=0; index<25; index++) { printf("%d ",data); // output a single character Sleep(100); // sleep a little to slow things down } // end for index // just return the data sent to the thread function
return((DWORD)data); } // end Printer_Thread // MAIN /////////////////////////////////////////////////////////////// void main(void) { HANDLE thread_handle; // this is the handle to the thread DWORD thread_id; // this is the id of the thread // start with a blank line printf("\nStarting threads...\n"); // create the thread, IRL we would check for errors
|