Click to See Complete Forum and Search --> : timegettime


May 14th, 1999, 09:00 PM
Can someone help me figure out how to use TimeGetTime(); ?? Please.

Jaeyeon Lee
May 14th, 1999, 10:05 PM
You can use timeGetTime to get the duration between execution points as follows.

DWORD start = timeGetTime();
...... Do Some Job ......
DWORD end = timeGetTime();

DWORD ellapsed = end - start; // in milisecond unit

arf
May 17th, 1999, 02:16 PM
// CStopWatch.h
//

#ifndef CSTOPWATCH_H
#define CSTOPWATCH_H

#include <windows.h>
#include <mmsystem.h>

//////////////////////////////////////////////////////////////////////////////
// CStopWatch

class CStopWatch
{
public:
//
// construction/destruction
//
CStopWatch();
CStopWatch(int resolution);


//
// operators
//

void Start(); // start stopwatch
float Stop(); // stop stopwatch, return = number of seconds

private:
int Resolution; // set timer resolution in milliseconds (only effective on WinNT)
int StartTime; // start time
};

#endif // !#define CSTOPWATCH_H


// CStopWatch.cpp
//

#include "stdafx.h"
#include "CStopWatch.h"

#if _MSC_VER >= 1000
//
// include the multimedia library for linking
//
#pragma comment( lib, "winmm" )
#pragma once
#endif // _MSC_VER >= 1000


CStopWatch :: CStopWatch()
{
Resolution = 1;
StartTime = 0;
}

CStopWatch :: CStopWatch(int res)
{
Resolution = res;
StartTime = 0;
}

void CStopWatch :: Start()
{

#ifdef _WIN32
StartTime = timeBeginPeriod(Resolution);
if (StartTime != 0) throw(0,"Unable to set requested resolution","CStopWatch");
StartTime = timeGetTime();
#endif

}

float CStopWatch :: Stop()
{
float RT = 0.0;

#ifdef _WIN32
RT = (timeGetTime() - StartTime)/1000.0F;
StartTime = timeEndPeriod(Resolution);
#endif

return RT;
}

Michel Wassink
May 20th, 1999, 03:45 AM
Add winmm.lib to linker settings if necessary

,,,^..^,,,
Michel

May 21st, 1999, 09:06 PM
Note I would like this to work under MFC if at all possible. I would like it to function as a timer for a simple 2D animation. (I need more help understanding)