#include "windows.h"
#include <iostream>
using namespace std;
void CALLBACK TimeProc(
HWND hwnd,
UINT message,
UINT idTimer,
DWORD dwTime);
int _tmain(int argc, _TCHAR* argv[])
{
SetTimer(NULL,1,1000,TimeProc);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
if(msg.message==WM_TIMER)
{
DispatchMessage(&msg);
}
}
scanf(&a);
return 0;
}
void CALLBACK TimeProc(
HWND hwnd,
UINT message,
UINT idTimer,
DWORD dwTime)
{
cout<<"a timer comming"<<endl;
}
本文展示了一个使用Windows API创建并处理定时器事件的C++示例。通过设置定时器并定义回调函数`TimeProc`来处理定时触发的事件,演示了如何在Windows环境下实现基本的定时任务。
5万+

被折叠的 条评论
为什么被折叠?



