#include <stdio.h>#include <conio.h>#include <time.h>#include <stdlib.h>#include <windows.h>#define DELAY 3#define LEN_STD_STR 3char stdandardStr[LEN_STD_STR] = "123"; DWORD ChildMain(); int main(){ INT giThreadNumber = 1; DWORD dwThreadId; HANDLE hThread; DWORD dwCreationFlags = 0; time_t *t1 = NULL; time_t *t2 = NULL; int oldTime = 0, curTime = 0; oldTime = time(t1); hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ChildMain, (LPVOID)giThreadNumber, dwCreationFlags, &dwThreadId); for(;;){ curTime = time(t2); if(curTime - oldTime >= DELAY){ printf("Time up!\n"); /* other function as follow */ printf("Other function!\n"); CloseHandle(hThread); /*关掉不再使用的线程*/ return 0; } } system("pause"); return 0;} DWORD ChildMain(giThreadNumber){ int i = 0; char inputStr[LEN_STD_STR] = {0}; char ch; while(1){ ch = getche(); if(ch == 27){ printf("\nExit!\n"); goto Exit; }else{ inputStr[i] = ch; } inputStr[3] = '\0'; if(strcmp(stdandardStr, inputStr) == 0){ printf("\nMatch!\n"); break; } i++; if(i == 3){ i = 0; } } /* other function as follow */Exit: printf("Other function!\n"); return 0 ;} 在 QQ845765 的 有人实现的!!! 可以在 CFREE 中或者 VC++ 下编译通过

评论