C++ 定时器的问题

来源:百度知道 编辑:UC知道 时间:2024/06/06 07:38:24
求一程序实现启动定时器及回调函数。

在应用程序中用SetTimer启动定时器,2秒后回调函数输出“hello!”

越简单越好,谢谢!
还有在2秒内要撤消定时器该怎么办?
或者2秒内重启定时器该怎么办?

#include <stdio.h>
#include <windows.h>

void CALLBACK timer(HWND hwnd, UINT uMsg,UINT idEvent,DWORD dwTime)
{
printf("hello!\n");
return;
}
void main()
{

MSG msg;
int send = SetTimer(NULL, 0, 1000, (TIMERPROC)timer);
GetMessage (&msg, NULL, 0, 0);
TranslateMessage(&msg);
DispatchMessage(&msg);
KillTimer(NULL, send);
}
撤销定时器这个我弄不了哦~~