SetTimer实现定时器,需要Windows消息循环!!!
#include <windows.h>
#include <iostream>
void CALLBACK TimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
{
std::cout<<"hello "<<std::endl;
}
void main()
{
int timerID = 1;
MSG msg;
SetTimer(NULL,timerID,1000,TimerProc);
while ((GetMessage(&msg, NULL, NULL, NULL) != 0) && (GetMessage(&msg, NULL, NULL, NULL) != -1))
{
if (msg.message == WM_TIMER)
{
std::cout<<"i got the message."<<std::endl;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
#include <iostream>
void CALLBACK TimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
{
std::cout<<"hello "<<std::endl;
}
void main()
{
int timerID = 1;
MSG msg;
SetTimer(NULL,timerID,1000,TimerProc);
while ((GetMessage(&msg, NULL, NULL, NULL) != 0) && (GetMessage(&msg, NULL, NULL, NULL) != -1))
{
if (msg.message == WM_TIMER)
{
std::cout<<"i got the message."<<std::endl;
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
}
摘自网络!