控制台程序的 定时器 和 消息循环
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);
}
}
}
摘自网络!
posted on 2013-11-13 16:31 Waaaaaall-E 阅读(668) 评论(0) 编辑 收藏 举报