c++ 自定义类中如何使用settimer定时器
#include<windows.h>
#include
using namespace std;
#define ID_TIMER 100
void CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime );
int main()
{
int ret = SetTimer(NULL,ID_TIMER,1000,(TIMERPROC)TimerProc);
MSG msg;
while (1)
{
GetMessage(&msg, NULL, 0, 0);
DispatchMessage(&msg);
}
return 0;
}
void CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime )
{
KillTimer(NULL,idEvent); //如果你只想输出一次的话
cout << “hahahaha”;
}

本文介绍在C++自定义类中如何利用Windows API的SetTimer函数创建定时器,通过实例展示了如何设置和使用回调函数TimerProc来执行定时操作,如输出字符串。
314

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



