MMTimer usage
How do i start and stop a multimedia timer ''properly''?
I have it working, but if I stop and start it 10 times, the timer stops working and i need to reboot.
Im using TimeSetEvent and startperiod (i think thats what they are called).
Downloads: ZeroOne Realm
timeSetEvent to start
timeKillEvent to stop
Usually there shouldn''t be any need but to start timer once in beginning of program and to stop it once when program terminates. Simply "de-activate" timer when it''s not needed;
void function_handler_however_it_is_defined(...)
{
if (timer_not_active) return;
// do neat stuff here
}
If you need to use timers in many points of program, consider using one global timer which gets it''s handler function as function pointer.
Hmm. If you didn''t remove timers with timeKillEvent but generated continuously more of them with timeSetEvent, you probably ran out of timers, and they all were still ticking there... And remember, each timer you start runs in it''s own thread...!
And why didn''t you read this from the docs?
timeKillEvent to stop
Usually there shouldn''t be any need but to start timer once in beginning of program and to stop it once when program terminates. Simply "de-activate" timer when it''s not needed;
void function_handler_however_it_is_defined(...)
{
if (timer_not_active) return;
// do neat stuff here
}
If you need to use timers in many points of program, consider using one global timer which gets it''s handler function as function pointer.
Hmm. If you didn''t remove timers with timeKillEvent but generated continuously more of them with timeSetEvent, you probably ran out of timers, and they all were still ticking there... And remember, each timer you start runs in it''s own thread...!
And why didn''t you read this from the docs?
~~~ "'impossible' is a word in the dictonary of fools" --Napoleon
Ive read the docs, but they dont explain how to use it in detail.
Ive coded according to the docs, but im getting the errors I mentioned above.
Am I doing it right? Here''s my code (but with error checking left out)....
//vars
DWORD mmTimerPeriod = 20;
DWORD uTimerID;
StartTimer()
{
timeBeginPeriod(mmTimerPeriod);
uTimerID = timeSetEvent(mmTimerPeriod,15,TimerCallBack,(DWORD)0,TIME_PERIODIC);
}
StopTimer()
{
timeKillEvent( uTimerID );
timeEndPeriod(mmTimerPeriod);
}
void CALLBACK TimeFunc( UINT uTimerID, UINT uMsg, etc...)
{
/// Code...
}
Ive coded according to the docs, but im getting the errors I mentioned above.
Am I doing it right? Here''s my code (but with error checking left out)....
//vars
DWORD mmTimerPeriod = 20;
DWORD uTimerID;
StartTimer()
{
timeBeginPeriod(mmTimerPeriod);
uTimerID = timeSetEvent(mmTimerPeriod,15,TimerCallBack,(DWORD)0,TIME_PERIODIC);
}
StopTimer()
{
timeKillEvent( uTimerID );
timeEndPeriod(mmTimerPeriod);
}
void CALLBACK TimeFunc( UINT uTimerID, UINT uMsg, etc...)
{
/// Code...
}
Downloads: ZeroOne Realm
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement