Timer Implementation In C++

can anyone please help me out on the timer issue?

I know that we have WM_Timer in the MFC which is good enough to use for the timer applications . But how to use the timers without using the MFC.


I already did using the sleep (); and then calling the function after the specified interval of time.


But I need a similar kind of implementation like the WM_Timer in C++.....

Advance thanks...
closed account (z05DSL3A)
Something like the following?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <windows.h>
#include <iostream>

#define POLL_TIMER   1
#define END_TIMER    2

UINT PollingTimerId (0);
UINT EndTimerId (0);

VOID CALLBACK PollingTimerProc(HWND /*hWnd*/, UINT /*nMsg*/, UINT /*nIDEvent*/, DWORD /*dwTime*/) 
{
    std::cout << "Polling..." << std::endl;
}

VOID CALLBACK EndTimerProc(HWND /*hWnd*/, UINT /*nMsg*/, UINT /*nIDEvent*/, DWORD /*dwTime*/)
{
    std::cout << "Ending..." << std::endl;
    KillTimer(NULL, PollingTimerId);
    KillTimer(NULL, EndTimerId);
    PostQuitMessage (0) ;
}

int main(int /*argc*/, char /**argv[]*/) 
{
    PollingTimerId = SetTimer(NULL, POLL_TIMER, 1000, &PollingTimerProc);
        
    EndTimerId = SetTimer(NULL, END_TIMER, 10000, &EndTimerProc);
    
    MSG Msg;
    while (GetMessage(&Msg, NULL, 0, 0)) 
    {
        DispatchMessage(&Msg);
    }
    
    return 0;
}
Topic archived. No new replies allowed.