A Class To Encapsulate MultiMedia Timers
Posted
by Simon Wood
on May 17th, 1999
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___ #includeThe source file, mmTimers.cppclass 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
#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;
}
Date Last Updated: May 17, 1999

Comments
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:02pmThat 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]|
Replyugg boots uzxgle
Posted by Mandyzwo on 02/18/2013 07:08ambeats 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
ReplyQuestion about callback
Posted by Legacy on 11/24/2003 12:00amOriginally posted by: Scott
Could you please describe the parameters and usage of the callback function.
Replya sample program for mmTimers
Posted by Legacy on 03/21/2003 12:00amOriginally 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
-
Reply
-
Reply
-
ReplyI need a sample
Posted by wuyanping on 07/04/2006 02:47amI need your sample code!
Posted by firebirdgo on 06/24/2005 12:01amNeed your sample program for mmTimers! from a c++ beginner
Posted by s-gm on 06/03/2004 09:55amDear 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
ReplyProblem with huge interval
Posted by Legacy on 02/11/2003 12:00amOriginally 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.
ReplyHave you got an idea ?
Thanks a lot
PLEASE HELP ME!
Posted by Legacy on 02/04/2003 12:00amOriginally posted by: Melissa
HI!
ReplyI 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
I understand but I can't use it
Posted by Legacy on 07/31/2002 12:00amOriginally posted by: Georgi
Callback problem!!!
ReplyYou can have too many timers
Posted by Legacy on 07/18/2002 12:00amOriginally posted by: Jim Moore
I just uncovered an interesting limitation of multimedia timers (timeSetEvent). I have an application that has multiple threads. Each thread makes use of a timer. The timer is used to sleep for a period of time. When the thread count is 17, timeSetEvent begins returning NULL (failure). So, if you have an inkling to use more than 16 multimedia timers, you better figure out another way to do this. I am running Windows 2000.
ReplySome questions
Posted by Legacy on 07/08/2002 12:00amOriginally posted by: yuval
What's the use of the resolution attribute in the constrcutor ?
What is the maximum intervals I can use (or how I can get this value) ?
Thanks
ReplyPlease do not use multimedia timer in Windows 9x/NT
Posted by Legacy on 12/10/2001 12:00amOriginally posted by: Edwin Zhang
Multimedia timer was designed for 16-bit Windows, such as Windows 3.1. It will cause serious problem in Windows 95 and above. You can see MSDN to ensure this.
ReplyLoading, Please Wait ...