user-0 提问: VC定时器的问题

回复:
user: user-1
content: 引用 2 楼 u014274707 的回复:[quote=引用 1 楼 from2015 的回复:]  #include <stdio.h> #include <windows.h>  int main(int argc, char* argv[]) { 	int sleepCount = 0; 	int pre = 0; 	int num = 0; 	printf("Hello World!\n");     while(1)     { 		scanf("%d", &num); // 取值 		if (pre - num > 100 || num - pre > 100) 		{ 			printf("do something.\n"); 		}  		else 		{ 			printf("congtinue.\n"); 		} 		 		Sleep(1000); // 等待1秒     } // while(1); 	 	 	return 0; }  这样行不行？你是新手吧。首先你写的那个是个死循环，其次线程休眠和定时器是不同的[/quote]  嗯。向各位学习。

user: user-2
content: 下载这个看看http://www.codefans.net/soft/23871.shtml

user: user-3
content: 仅供参考#pragma comment(lib,"user32") #include <stdio.h> #include <time.h> #include <sys/timeb.h> #include <windows.h> char datestr[16]; char timestr[16]; char mss[4]; void log(char *s) {     struct tm *now;     struct timeb tb;      ftime(&tb);     now=localtime(&tb.time);     sprintf(datestr,"%04d-%02d-%02d",now->tm_year+1900,now->tm_mon+1,now->tm_mday);     sprintf(timestr,"%02d:%02d:%02d",now->tm_hour     ,now->tm_min  ,now->tm_sec );     sprintf(mss,"%03d",tb.millitm);     printf("%s %s.%s %s",datestr,timestr,mss,s); } VOID CALLBACK myTimerProc1(   HWND hwnd, // handle of window for timer messages   UINT uMsg, // WM_TIMER message   UINT idEvent, // timer identifier   DWORD dwTime // current system time ) {  log("In myTimerProc1\n"); } VOID CALLBACK myTimerProc2(   HWND hwnd, // handle of window for timer messages   UINT uMsg, // WM_TIMER message   UINT idEvent, // timer identifier   DWORD dwTime // current system time ) {  log("In myTimerProc2\n"); } int main() {     int i;     MSG msg;      SetTimer(NULL,0,1000,myTimerProc1);     SetTimer(NULL,0,2000,myTimerProc2);     for (i=0;i<20;i++) {         Sleep(500);         log("In main\n");         if (GetMessage(&msg,NULL,0,0)) {             TranslateMessage(&msg);             DispatchMessage(&msg);         }      }     return 0; } //2012-07-26 17:29:06.375 In main //2012-07-26 17:29:06.875 In myTimerProc1 //2012-07-26 17:29:07.375 In main //2012-07-26 17:29:07.875 In myTimerProc2 //2012-07-26 17:29:08.375 In main //2012-07-26 17:29:08.375 In myTimerProc1 //2012-07-26 17:29:08.875 In main //2012-07-26 17:29:08.875 In myTimerProc1 //2012-07-26 17:29:09.375 In main //2012-07-26 17:29:09.890 In myTimerProc2 //2012-07-26 17:29:10.390 In main //2012-07-26 17:29:10.390 In myTimerProc1 //2012-07-26 17:29:10.890 In main //2012-07-26 17:29:10.890 In myTimerProc1 //2012-07-26 17:29:11.390 In main //2012-07-26 17:29:11.890 In myTimerProc2 //2012-07-26 17:29:12.390 In main //2012-07-26 17:29:12.390 In myTimerProc1 //2012-07-26 17:29:12.890 In main //2012-07-26 17:29:12.890 In myTimerProc1 //2012-07-26 17:29:13.390 In main //2012-07-26 17:29:13.890 In myTimerProc2 //2012-07-26 17:29:14.390 In main //2012-07-26 17:29:14.390 In myTimerProc1 //2012-07-26 17:29:14.890 In main //2012-07-26 17:29:14.890 In myTimerProc1 //2012-07-26 17:29:15.390 In main //2012-07-26 17:29:15.890 In myTimerProc2 //2012-07-26 17:29:16.390 In main //2012-07-26 17:29:16.390 In myTimerProc1 //2012-07-26 17:29:16.890 In main //2012-07-26 17:29:16.890 In myTimerProc1 //2012-07-26 17:29:17.390 In main //2012-07-26 17:29:17.890 In myTimerProc2 //2012-07-26 17:29:18.390 In main //2012-07-26 17:29:18.390 In myTimerProc1 //2012-07-26 17:29:18.890 In main //2012-07-26 17:29:18.890 In myTimerProc1 //2012-07-26 17:29:19.390 In main //2012-07-26 17:29:19.890 In myTimerProc2

user: user-0
content: 引用 1 楼 from2015 的回复: #include <stdio.h> #include <windows.h>  int main(int argc, char* argv[]) { 	int sleepCount = 0; 	int pre = 0; 	int num = 0; 	printf("Hello World!\n");     while(1)     { 		scanf("%d", &num); // 取值 		if (pre - num > 100 || num - pre > 100) 		{ 			printf("do something.\n"); 		}  		else 		{ 			printf("congtinue.\n"); 		} 		 		Sleep(1000); // 等待1秒     } // while(1); 	 	 	return 0; }  这样行不行？你是新手吧。首先你写的那个是个死循环，其次线程休眠和定时器是不同的

user: user-1
content: #include <stdio.h> #include <windows.h>  int main(int argc, char* argv[]) { 	int sleepCount = 0; 	int pre = 0; 	int num = 0; 	printf("Hello World!\n");     while(1)     { 		scanf("%d", &num); // 取值 		if (pre - num > 100 || num - pre > 100) 		{ 			printf("do something.\n"); 		}  		else 		{ 			printf("congtinue.\n"); 		} 		 		Sleep(1000); // 等待1秒     } // while(1); 	 	 	return 0; }  这样行不行？