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

 

摘自网络!

相关文章:

  • 2022-12-23
  • 2021-11-15
  • 2022-12-23
  • 2022-12-23
  • 2021-04-04
  • 2021-08-05
  • 2022-01-07
  • 2021-12-06
猜你喜欢
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
  • 2022-01-30
  • 2022-12-23
  • 2022-12-23
  • 2022-01-20
相关资源
相似解决方案