Click here to Skip to main content
13,149,427 members (55,942 online)
Click here to Skip to main content
Add your own
alternative version


29 bookmarked
Posted 11 Mar 2003

A simple use of the Multimedia Timer

, 11 Mar 2003
Rate this:
Please Sign up or sign in to vote.
Demonstrates the simple use of a multimedia timer in user classes
<!-- Add the rest of your HTML here -->


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 <clock.h>file and then instantiate a variable like this


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.SetDelay(100,TIME_ONE_SHOT); // in ms for a one shot timer

// start the clock


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... :-)


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


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
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
espinc7-Sep-10 4:13
memberespinc7-Sep-10 4:13 
QuestionPrecision of this algorithm? Pin
LMCer30-May-07 7:33
memberLMCer30-May-07 7:33 
QuestionHow to reset timer? Pin
firstluv8125-Sep-06 9:38
memberfirstluv8125-Sep-06 9:38 
Questionquestion? Pin
Electro 17-Oct-05 11:37
memberElectro 17-Oct-05 11:37 
Generalexternal errors Pin
Felimar19-Feb-04 13:55
memberFelimar19-Feb-04 13:55 
GeneralRe: external errors Pin
Felimar19-Feb-04 15:01
memberFelimar19-Feb-04 15:01 
GeneralWord of caution: MultimediaTimer = Multithreading Pin
Damir Valiulin18-Mar-03 5:26
memberDamir Valiulin18-Mar-03 5:26 
GeneralRe: Word of caution: MultimediaTimer = Multithreading Pin
The Monz24-Mar-03 1:56
memberThe Monz24-Mar-03 1:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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 | Terms of Use | Mobile
Web04 | 2.8.170924.2 | Last Updated 12 Mar 2003
Article Copyright 2003 by Nicolas Etienne
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid