Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

timeSetEvent(): can i change the timers limit?

win32 c++

This topic has been archived. This means that you cannot reply to this topic.
No replies to this topic

#1 cambalinho

cambalinho

    CC Lurker

  • Just Joined
  • Pip
  • 2 posts

Posted 16 May 2016 - 08:47 AM

see my Timer class:

class Timer
{

private:
    static unsigned int TimerCount;
    UINT_PTR timerid=0;
    UINT m_uResolution=0;
    unsigned int TimerID=0;
    DWORD intInterval=0;

    static void CALLBACK MultiMediaProcedure(UINT wTimerID, UINT msg, DWORD_PTR dwUser, DWORD dw1, DWORD dw2)
    {
        Timer* obj =(Timer*) dwUser;
        if(obj!=NULL && obj->timerprocedure!=NULL)
            obj->timerprocedure();
        else
            DebugText("MultiMediaProcedure: timer not activated");
    }

public:

    std::function<void()> timerprocedure=EmptyEvent;
    Timer(std::function<void()> tmrprocedure=EmptyEvent)
    {
        TimerCount+=1;
        TimerID=TimerCount-1;
        timerprocedure=tmrprocedure;
    }

    void Stop()
    {
        if(timerid!=0)
        {
            if(timeKillEvent(timerid)==MMSYSERR_INVALPARAM)
                DebugText("error on destroying the timer: " + to_string(GetLastError()));
            timeEndPeriod (m_uResolution);
            timerid=0;
        }
    }

    DWORD GetInterval()
    {
        return intInterval;
    }

    void SetInterval(DWORD uintInterval)
    {
        intInterval = uintInterval;
    }

    property <DWORD> Interval{GetProperty(Timer::GetInterval),SetProperty(Timer::SetInterval)};

    void Start()
    {
        Stop();
        TIMECAPS tc;
        timeGetDevCaps(&tc, sizeof(TIMECAPS));
        m_uResolution = tc.wPeriodMin;
        timeBeginPeriod(m_uResolution);
        timerid = timeSetEvent(intInterval, m_uResolution, Timer::MultiMediaProcedure, (DWORD_PTR)this, TIME_PERIODIC);
        if (timerid==NULL)
        {
            DebugText("No timer Started: " + to_string(GetLastError()));
        }
    }

    ~Timer()
    {
        if(timerid!=0)
            Stop();
        TimerCount-=1;
    }
};
unsigned int Timer::TimerCount=0;

these class works great. but, seems that, the timeSetEvent() can, only, activate 16 timers. can i change that limits?

(using a gif animation with a diferent interval between frames, i can't use SetTimer()-KillTimer())