控制台程序的 定时器 和 消息循环


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); 
        } 
    } 
}

摘自网络!

原文地址:https://www.cnblogs.com/ant-wjf/p/3421664.html