除了sleep之外的延遲寫法
#include
#include
#include
#include
using namespace std;
bool CheckMessageQueue()
{
MSG msg;
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
if(msg.message==WM_QUIT) return false;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return true;
}
long Delay_DoEvents(int sec)
{
clock_t start_time; //delay,使用CLOCK function
long number_of_times=0;
start_time = clock();
while((clock() - start_time) < sec * CLOCKS_PER_SEC){
number_of_times= number_of_times+ (int)CheckMessageQueue();
}
return number_of_times;
}
int main(int argc, char *argv[])
{
Delay_DoEvents(5);
system("PAUSE");
return EXIT_SUCCESS;
}
全站熱搜
留言列表