VC有没有等待函数
让程序什么也不作,等待几秒钟再执行下面的程序 问题点数:20、回复次数:9Top
1 楼HelloIvan2005()回复于 2006-01-04 16:45:44 得分 0
sleep();Top
2 楼HelloIvan2005()回复于 2006-01-04 16:48:24 得分 0
void Sleep(
DWORD dwMilliseconds
);Top
3 楼pomelowu(羽战士)回复于 2006-01-04 16:53:39 得分 0
Sleep(3000); // sleep for 3 secondsTop
4 楼Seu_why(Newbie)回复于 2006-01-04 16:57:58 得分 0
VOID Sleep(
DWORD dwMilliseconds // sleep time in milliseconds
);
Top
5 楼rageliu(天气好了就去长白山看水怪去了,嘿嘿...)回复于 2006-01-04 20:29:35 得分 0
for()
while()
sleep()Top
6 楼xxfyath(〖水滴石穿〗)回复于 2006-01-07 10:24:34 得分 0
Sleep(1000) ; ////等待1秒。
或
long lStartTime ;
lStartTime = GetTickCount() ;
for(;;)
if( GetTickCount() - lStartTime > 1000 ) break;
Top
7 楼vcmute(BCare4 H1Rest Good9!)回复于 2006-01-07 10:47:31 得分 0
Using Waitable Timer Objects
The following example creates a timer that will be signaled after a 10 second delay. First, the code uses the CreateWaitableTimer function to create a waitable timer object. Then it uses the SetWaitableTimer function to set the timer. The code uses the WaitForSingleObject function to determine when the timer has been signaled.
#include <windows.h>
#include <stdio.h>
int main()
{
HANDLE hTimer = NULL;
LARGE_INTEGER liDueTime;
liDueTime.QuadPart=-100000000;
// Create a waitable timer.
hTimer = CreateWaitableTimer(NULL, TRUE, "WaitableTimer");
if (!hTimer)
{
printf("CreateWaitableTimer failed (%d)\n", GetLastError());
return 1;
}
printf("Waiting for 10 seconds...\n");
// Set a timer to wait for 10 seconds.
if (!SetWaitableTimer(
hTimer, &liDueTime, 0, NULL, NULL, 0))
{
printf("SetWaitableTimer failed (%d)\n", GetLastError());
return 2;
}
// Wait for the timer.
if (WaitForSingleObject(hTimer, INFINITE) != WAIT_OBJECT_0)
printf("WaitForSingleObject failed (%d)\n", GetLastError());
else printf("Timer was signaled.\n");
return 0;
}
Top
8 楼CUG122032(烫烫烫烫烫烫?烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫?烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫)回复于 2006-01-07 11:18:52 得分 0
比较常用的有timer和Sleep,用Sleep的好处是比较方便,它适用于对时间精度要求不高,而且时间间隔比较小的地方。timer用起来没有Sleep方便,它需要先安装计时器,不过Timer比Sleep功能更多一点。
对于你的问题,你说想让程序“什么都不做”,那就用Sleep。。。我想你要清楚你说的话,什么都不做,也包括不响应各种消息,也就是说你的任何操作都是无效的。比如你当时点了关闭按键,也要等Sleep结束才能响应。。。
所以还是用Timer 比较好,我觉得。...我只在调试的时候用Sleep,比如说你要编个人工智能的类,一开始的时候只有接口,内部还没有写,这时就在内部让它Sleep几秒,模仿它将来要运算所花的时间。。。。Top
9 楼SoLike(思危)回复于 2006-01-07 11:31:02 得分 0
Sleep可以挂起当前线程Top




