Click here to Skip to main content
Licence 
First Posted 11 Mar 2003
Views 57,981
Bookmarked 26 times

A simple use of the Multimedia Timer

By | 11 Mar 2003 | Article
Demonstrates the simple use of a multimedia timer in user classes

Introduction

This article is about the use of a timer in every class you could write. When I want to use a timer in my applications, I always have the same problem.  The problem is that I'd like to be able to include a timer in a class which needs it without taking into account the fact that this class could be a CWnd, or a simple CDummyClass. The idea, which is quite simple is to use the template to perform such a work and also use MultiMediaTimer

The main trouble with the Multimedia timer is the callback routine that you are going to use to do the job, I've just tried to make it clear and simple. If this article sounds bad to your ears, I'll try to do better next time. Forgive me if this is so, as it's my first article ;-)

Using the code

It's very easy to use this class.  You only have to include the file and then instantiate a variable like this

CClock<THEMOTHERCLASS > myClock; 

For instance, if you intend to insert a clock in your CMyClass, you just add this CClock<CMYCLASS> myClock; The last thing you have to do to end the process is to create a function called TimerHappened(); This function will be called every time the timer is hit. This timer can be set with different value coming straight from the multimedia timers.

#include "clock.h"

//somewhere in your code

CClock<CMYCLASS> myClock;
myClock.SetCallBack(this);

myClock.SetDelay(100,TIME_ONE_SHOT); // in ms for a one shot timer

// start the clock

myClock.start();

void CMyClass::TimerHappened(int id)
{
   TRACE("I've been hit once in my life time\n");
}

of course , there are many method that you could call which are :

- pause()
- resume()

Points of Interest

Writing this code made me remember the use of the template... :-)

History

This is the V1.0 of this timer. I'll make change if I need it or if some asks for it...

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Nicolas Etienne



United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 5 Pinmemberespinc4:13 7 Sep '10  
QuestionPrecision of this algorithm? PinmemberLMCer7:33 30 May '07  
QuestionHow to reset timer? Pinmemberfirstluv819:38 25 Sep '06  
Questionquestion? PinmemberElectro 111:37 7 Oct '05  
Generalexternal errors PinmemberFelimar13:55 19 Feb '04  
GeneralRe: external errors PinmemberFelimar15:01 19 Feb '04  
GeneralWord of caution: MultimediaTimer = Multithreading PinmemberDamir Valiulin5:26 18 Mar '03  
GeneralRe: Word of caution: MultimediaTimer = Multithreading PinmemberThe Monz1:56 24 Mar '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web04 | 2.5.120517.1 | Last Updated 12 Mar 2003
Article Copyright 2003 by Nicolas Etienne
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid