Click here to Skip to main content
Click here to Skip to main content

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 -->

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 Wink | ;-)

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

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

Share

About the Author

Nicolas Etienne

United States United States
No Biography provided

Comments and Discussions

 
QuestionPrecision of this algorithm? PinmemberLMCer30-May-07 7:33 

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.

| Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 12 Mar 2003
Article Copyright 2003 by Nicolas Etienne
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid