Ir ao conteúdo

Posts recomendados

Postado

falando na timeSetEvent(): serve para usar como temporizador, seja de 1 unico chamamento(TIME_ONESHOT) ou em ciclo(TIME_PERIODIC).

ok... mas estou a ter resultados inesperados em varios sentidos que nao consigo corrigir :(

eis a minha pequena class Timer:

class Timer
{

private:
    UINT_PTR timerid=NULL;
    unsigned int intInterval=0;
    HWND windowtimer=NULL;
    //UINT m_uResolution=0;

    static void CALLBACK _TimerProc(UINT wTimerID, UINT msg, DWORD_PTR dwUser, DWORD dw1, DWORD dw2)
    {
        Timer* obj =(Timer*) dwUser;
        if(obj!=nullptr && obj->timerprocedure!=nullptr)
            obj->timerprocedure();
    }

public:

    std::function<void()> timerprocedure=NULL;
    Timer(std::function<void()> tmrprocedure=NULL)
    {
        timerprocedure=tmrprocedure;
    }

    void Stop()
    {
        if(timerid!=NULL)
        {

            timeKillEvent(timerid);
            //timeEndPeriod (m_uResolution);
            timerid=0;
        }
    }

    //não olhem muito para esta propriedade
	//é como ter o GetInterval e SetInterval.
    property <unsigned int> Interval
    {
        Get(unsigned int)
        {
            return intInterval;
        },
        Set(unsigned int uintInterval)
        {
            intInterval = uintInterval;
            //Start(blPeriodic);
        }
    };

    void Start()
    {
        Stop();
        /*TIMECAPS tc;
        timeGetDevCaps(&tc, sizeof(TIMECAPS));
        m_uResolution = tc.wPeriodMin;
        timeBeginPeriod(m_uResolution);*/
        UINT timeoptions=0;
		
        timeoptions=TIME_PERIODIC | TIME_CALLBACK_FUNCTION | TIME_KILL_SYNCHRONOUS;
        timerid = timeSetEvent(intInterval, intInterval/2, &Timer::_TimerProc, (DWORD_PTR)this,timeoptions);
    }

    ~Timer()
    {
        Stop();
    }
};

ao usar  timeSetEvent() com TIME_PERIODIC ou TIME_ONESHOT eu obtenho resultados diferentes sobre o que penso do que deveriam fazer :(

alguem me pode explicar melhor?

  • 2 semanas depois...
Postado

acho que ja entendi alguma coisa. eu estou a usar intervalos de 200ms ou menores. penso que posso estar a usar muitos recurso do window. talvez por isso, ao 6 temporizador, eu tenho erro. MMRESULT timeSetEvent. e le: "Returns an identifier for the timer event if successful or an error otherwise. This function returns NULL if it fails and the timer event was not created."

mas os enum do MMRESULT sao ignorados kkkk

alguem me pode explicar alguma coisa?

Visitante
Este tópico está impedido de receber novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

GRÁTIS: Aprenda a Ler Resistores e Capacitores

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!