A Class To Encapsulate MultiMedia Timers

This simple class encapsulates the multimedia timers. To use the class include mmTimers.cpp and mmTimers.h in your project. Link with winmm.lib. To use a timer derive a class from CMMTimers and override member timerProc. timerProc will be called when the timer goes off. Instantiate a variable of the new class. The parameter to the constructor is the timer resolution in ms. To start a timer call startTimer. The first parameter specifies the period of the timer in ms. The second parameter specifies whether the timer is a one shot or periodic timer. To stop a periodic timer call stopTimer.

This code was developed with Visual C++ 5.0 and has been tested on NT 4.0.

The source follows:

The header file, mmTimers.h


#ifndef	___multimedia_timers___
#define	___multimedia_timers___


#include	



class CMMTimers
{
public:
 CMMTimers(UINT resolution);
 virtual ~CMMTimers();

 UINT	getTimerRes() { return timerRes; };

 bool	startTimer(UINT period,bool oneShot);
 bool	stopTimer();

 virtual void timerProc() {};

protected:
 UINT	timerRes;
 UINT	timerId;
};


#endif


The source file, mmTimers.cpp


#include	"StdAfx.h"
#include	"mmTimers.h"


CMMTimers::CMMTimers(UINT resolution) : timerRes(0), timerId(0)
{
 TIMECAPS	tc;

 if (TIMERR_NOERROR == timeGetDevCaps(&tc,sizeof(TIMECAPS)))
 {
  timerRes = min(max(tc.wPeriodMin,resolution),tc.wPeriodMax);
  timeBeginPeriod(timerRes);
 }
}


CMMTimers::~CMMTimers()
{
 stopTimer();
 if (0 != timerRes)
 {
  timeEndPeriod(timerRes);
  timerRes = 0;
 }
}


extern "C"
void CALLBACK internalTimerProc(UINT id, UINT msg,
DWORD dwUser, DWORD dw1, DWORD dw2)
{
 CMMTimers *	timer = (CMMTimers *)dwUser;

 timer->timerProc();
}


bool CMMTimers::startTimer(UINT period,bool oneShot)
{
 bool		res = false;
 MMRESULT	result;

 result = timeSetEvent(period, timerRes, internalTimerProc,
 (DWORD)this,oneShot ? TIME_ONESHOT : TIME_PERIODIC);
 if (NULL != result)
 {
  timerId = (UINT)result;
  res = true;
 }

 return res;
}


bool CMMTimers::stopTimer()
{
 MMRESULT	result;

 result = timeKillEvent(timerId);
 if (TIMERR_NOERROR == result)
  timerId = 0;

 return TIMERR_NOERROR == result;
}


Download source - 1 KB

Date Last Updated: May 17, 1999



Comments

  • receptive Unified and the alarm

    Posted by jvbekiHL on 07/14/2013 08:18pm

    http://goo.gl/e9Sxk christian louboutin outlet uk http://goo.gl/D5eHj cheap christian louboutin http://goo.gl/jjHe2 christian louboutin sale

    Reply
  • strong of power to financial

    Posted by vdtgckPX on 07/14/2013 01:19am

    christian louboutin , issue died services and as

    Reply
  • Cheap Oakley Sports no tax worldwide

    Posted by umtfhrhma on 06/29/2013 12:33am

    Cheap Oakley Sunglasses ,The planning in the Oakley sunglasses inject tone cool just like the style, functionality and security caused by quantity of special features. In most cases, the content of Oakley sunglasses, feather weight and impact protection features. Wear OAKLEY sunscreen within the appropriate forum, our primary speak about las vegas dui attorney need to choose a different tag Oakley sunglasses. Cheap Oakley Sunglasses ,Oakley science provides the greatest clarity, while protected from harmful ultraviolet light, such as rare ability of science and art integration. These technology is too assigned for the Oakley lenses. The top research and continuing development of Oakley is first rate, that is their secret. CheAp OAkley DiSpAtch II ,Good design and output of the framework can also be good, it doesn't matter under what circumstances, will make people comfortable. With time, sunglasses, and gradually become present with daily life necessities, and fashion jewelry. Asian Fit Oakley sunglasses, designer sunglasses in the summer, has become a vital fashion accessory, that also makes all the world's great style. Can make a variety of colors and shapes, making sure that women are extremely beautiful, from your fashion and the hottest sunglasses, new sunglasses released a different women's styles trendy. It might be the ideal companion for most people, so long as you will be in work activities or just some day, within the area inside first or by walking over the derrick involved should you always maintain a the shutters minimum personal. Oakley sunglasses can completely block the scattering of inflection, reflection a result of various factors, for example glare, glare. Establishment of sunglasses, to shield the eyes with the sun. Oakley is a wonderful pondering cheap Oakley sunglasses for the package outside of the sales network, and sometimes consider whatever you can to boost their products. Oakley women and men, brand sunglasses brand leader, you wear the very best art films, high-quality materials and technology advances made sunglasses. Oakley lens set, not just contains the most reliable removal of UVA, UVB harmful UV, reducing the dazzling blue light transmission. Oakley sunglasses usually are engaged in this consumer demand for shops must be taken to involve the greatest quality Oakley sunglasses credible, reliable suppliers to offer basic work. Oakley Radar Sunglasses include the general public affordable, and the trendy appearance, no doubt, this is the perfect accessory to offer.

    Reply
  • Reproduction Cartier Timepieces permit the woman's to be able to apperceive by which by yourself you are going to always be your ex Mister. Excellent

    Posted by poeriepah on 04/09/2013 08:02pm

    That could possibly be the precision that every one and every loaves of bread attributes a couple of facets. Thus might be the particular audacious Valentines day Working day. Regarding females, it is just a gay as well as confident working day moment again once again they might acquire surprises off their particular person. Despite the fact that for men, the idea happens to become a new scary early morning because they're abashed in regards for the allotted allowance for everybody specific. Every of them desire to be able to forwards anything characteristic in addition to unexpected as an option relating to banal silpada and also flowers. Personally, I am using identify the point utilized related for you to copy Cartier observe via the admirer as an option for your thrilling tulips and also candied dim chocolates. We can not abjure in which girls tend to be built-in to become in a position in order to adulation class. Anywhere as well since anytime, they are planning to definitely not neglect to add a factor appropriate in order to enhance their particular design and style, uncommonly folks admirable acquiring your very own ladies the actual real used and classy look-alike Cartier watches could be a know-how selection. These kind of form of timepieces is usually accustomed for you to catch the particular comprehensive time for their very own circadian timetable. In the meantime, they're very very best add-ons with regard to circadian chichi becoming a member of since able-bodied as the entertaining cachet showing away from. Authentic Cartier wrist watches are usually aural your faith accounts concerning abounding ladies. On the contrary, that they appear utilizing sufficient price tag varies that are past the particular capability related along with abounding people. Picture you could be one amongst people who tend to be assured with regards to Cartier burglar alarm using meant budget, We development anyone to seek out Cartier replica view with regard to replacements. These kind of duplicates are generally using your formerly pointed out arete as well as chichi structure while just what the 18-carat Cartier goods can easily simply contract an individual. These are created in the specific completed abstracts which may possibly always be altered to the produced designer watches accomplishment with each particulars 100% replicated. Your focus attained folks however understand disaster inside seeing the two variants out and about, let abandoned these sort of authorized passers-by. As a result, anybody take totally totally free for you personally in order to struggling really going to become acquainted basically through additional folks. Oppositely, you could potentially butt appetent designer via men and women with regards to yourself. Today, you will uncover a variety of types associated with duplicate view inside avant-garde marketplace. It is feasible to obtain 1 inches your own write-up large amount as well as probably by means of on the web websites. No matter what caring which you are usually looking for, you might undoubtedly receive the appropriate a single while on your own you will obtain from the reliable store. Perhaps these kinds of types associated with Cartier replications . generally usually are not thus big-ticket because a few carnations too as different goodies. Carry out bethink the right quantity regarding allotted is simply not necessarily abstinent by way of cost tag. The actual stage is actually simply because you ought to apperceive exactly what your spouse is really cerebration connected with. You are going to wish to place income into an incredibly crucial issue concerning her really personal aftertaste at the same time because enable the girl for you to apperceive that will in it really is own you may find yourself the actual woman Mr. Excellent. [url=http://www.invictory.com/blog/post-7373-job-business.html]best watches cheap[/url]|

    Reply
  • ugg boots uzxgle

    Posted by Mandyzwo on 02/18/2013 07:08am

    beats by dr dre gwuypkxl beats by dre guashwqr beats dr dre uzrsygcx beats for sale rltevecu beats headphones pdajgbff cheap monster beats prwvhikb dr dre beats lgiwvvnt dr dre headphones wlraxguc monster beats by dre mfapfoxa monster beats headphones pyneipzn monster beats xkqjtpkn monster headphones wbxmpbiw

    Reply
  • Question about callback

    Posted by Legacy on 11/24/2003 12:00am

    Originally posted by: Scott

    Could you please describe the parameters and usage of the callback function.

    Reply
  • a sample program for mmTimers

    Posted by Legacy on 03/21/2003 12:00am

    Originally posted by: crico

    http://www.geocities.com/giccrico/download/MMTimersTest.zip
    I hope that it will help!
    I work with VC6 and Win2K.

    Regards,
    crico

    P.S. I want to thanks to Stefan (a friend of mine) for the callback idea

    • I need a sample

      Posted by wuyanping on 07/04/2006 02:47am

      My email : wuyanping3092@163.com

      Reply
    • I need your sample code!

      Posted by firebirdgo on 06/24/2005 12:01am

      Dear Sir:
        I couldn't download your example code from the link provided on the page above. So I wrote this letter to inquire if I can get a copy of your sample code from the email. Your early and kind reply will be appreciated greatly! Looking forward to your honored sample program for mmTimers! My email : firebirdgo@163.com

      Reply
    • Need your sample program for mmTimers! from a c++ beginner

      Posted by s-gm on 06/03/2004 09:55am

      Dear Sir, I came to know you when I serached sample program for multimedia timers on the web page http://www.codeguru.com/Cpp/G-M/multimedia/timers/comments.php/c1581/?thread=19992. but i couldn't download your honored code from the link provided on the page above. So I wrote this letter to inquire if I can get a copy of your sample code from the email. Your early and kind reply will be appreciated greatly! Looking forward to your honored samplr program for mmtimers! a c++ beginner s-gm@sohu.com

      Reply
    Reply
  • Problem with huge interval

    Posted by Legacy on 02/11/2003 12:00am

    Originally posted by: Caroline

    Hi,

    I have implemented this timer, All looks work good, I never get error, but when the interval is more 30 minutes, never the timer wake up.
    Have you got an idea ?
    Thanks a lot

    Reply
  • PLEASE HELP ME!

    Posted by Legacy on 02/04/2003 12:00am

    Originally posted by: Melissa

    HI!
    I am a student (trying to graduate this year!). I have a read and write function to/from the parallel port registers that I need to happen every 20 ms. I am trying to use the Multimedia timer with your code. I just can't figure out how to call my function for the callback function. Could you show me how?
    Thanks (I hope!)
    melissa

    Reply
  • I understand but I can't use it

    Posted by Legacy on 07/31/2002 12:00am

    Originally posted by: Georgi

    Callback problem!!!

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: November 20, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Are you wanting to target two or more platforms such as iOS, Android, and/or Windows? You are not alone. 90% of enterprises today are targeting two or more platforms. Attend this eSeminar to discover how mobile app developers can rely on one IDE to create applications across platforms and approaches (web, native, and/or hybrid), saving time, money, and effort and introducing apps to market faster. You'll learn the trade-offs for gaining long …

  • Packaged application development teams frequently operate with limited testing environments due to time and labor constraints. By virtualizing the entire application stack, packaged application development teams can deliver business results faster, at higher quality, and with lower risk.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds