For creating timers you can use the api - SetTimer(). In SetTimer() you’ve to specify the time interval in milliseconds, a timer id as UINT, then TimerProc. For each tick of specified timer, windows will call the TimerProc. If you didn’t specify any TimerProc, then a WM_TIMER message will be posted to your window.
You can utilize the Timer ID to set multiple timers using the same TimeProc. You can use KillTimer() to remove the timer. Have a look at the code snippet. In the given code snippet, timer is handled by WM_TIMER message.
// Message Map
BEGIN_MESSAGE_MAP(CDlgDlg, CDialog)
...
ON_WM_TIMER()
END_MESSAGE_MAP()
...
// Timer ID constants.
const UINT ID_TIMER_SECONDS = 0x1009;
// Start the timers.
void CDlgDlg::StartTimer()
{
// Set timer for Seconds ; 500 milli seconds
SetTimer( ID_TIMER_SECONDS, 500, 0 );
}
// Stop the timers.
void CDlgDlg::StopTimer()
{
// Stop both timers.
KillTimer( ID_TIMER_SECONDS );
}
// Timer Handler.
void CDlgDlg::OnTimer( UINT nIDEvent )
{
// Per minute timer ticked.
if( nIDEvent == ID_TIMER_SECONDS )
{
// Do your seconds based tasks here.
}
}
References:
http://www.codeproject.com/KB/shell/systemtray.aspx