CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: timegettime

  1. #1
    Guest

    timegettime

    Can someone help me figure out how to use TimeGetTime(); ?? Please.


  2. #2
    Join Date
    May 1999
    Location
    Republic of Korea
    Posts
    74

    Re: timegettime

    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



  3. #3
    Join Date
    May 1999
    Posts
    14

    Re: timegettime



    // 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;
    }







  4. #4
    Join Date
    Apr 1999
    Posts
    8

    Re: timegettime

    Add winmm.lib to linker settings if necessary

    ,,,^..^,,,
    Michel

  5. #5
    Guest

    Re: timegettime

    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)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured