#include <windows.h>
#include <iostream>
using namespace std;
void CALLBACK TimeProc(
HWND hwnd,
UINT message,
UINT idTimer,
DWORD dwTime);
int main()
{
SetTimer(NULL,1,1000,TimeProc);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
if(msg.message==WM_TIMER)
{
DispatchMessage(&msg);
}
}
return 0;
}
void CALLBACK TimeProc(
HWND hwnd,
UINT message,
UINT idTimer,
DWORD dwTime)
{
cout<<"a timer comming"<<endl;
}
#include <iostream>
using namespace std;
void CALLBACK TimeProc(
HWND hwnd,
UINT message,
UINT idTimer,
DWORD dwTime);
int main()
{
SetTimer(NULL,1,1000,TimeProc);
MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
if(msg.message==WM_TIMER)
{
DispatchMessage(&msg);
}
}
return 0;
}
void CALLBACK TimeProc(
HWND hwnd,
UINT message,
UINT idTimer,
DWORD dwTime)
{
cout<<"a timer comming"<<endl;
}
一定要有GetMessage和DispatchMessage,否则timer会被挂起
本文展示了一个简单的Windows定时器示例程序,通过SetTimer函数设置一个每秒触发一次的定时器,并使用回调函数TimeProc处理定时器事件。示例中强调了GetMessage和DispatchMessage的重要性,以确保定时器正常工作。
5758

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



