• Popular Now

• 9
• 13
• 9
• 18
• 19

Archived

This topic is now archived and is closed to further replies.

How do you make a basic timer?

This topic is 5138 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

this is what I found
#define TIMER_ID_1SEC 1
#define TIMER_ID_3SEC 2

SetTimer(hwnd, Timer_ID_1SEC, 1000,NULL);
SetTimer(hwnd, TImer_ID_3SEC, 3000,NULL);

case WM_TIMER:
{
switch(wparam)
{
case TIMER_ID_1Sec:
{
}
case Timer_ID_3Sec:
{
}break;
default:break;
}
return(0);
}break;

case WM_DESTROY:
[
KillTimer(hwnd, TIMER_ID_1SEC);
KillTimer(hwnd, TIMER_ID_3SEC);
PostQuiteMessage(0);
}break;

but this dont look like It will do what I want then there is this one
DWORD GetTickCount(void);

DWORD start_time = GetTickCount();
while ((GetTickCount() - start_time) < 33);

this the onw I ma using but it is hard to change it very easly and it is not that precise. Got any ideas?

Share on other sites
I also found this one

#include <stdio.h> #include <time.h> int main ( void ){  clock_t start, end;  /* Start the timer */  start = clock();  printf ( "Please wait a few moments and hit return\n" );  getchar();  /* End the timer */  end = clock();  /* Print out the difference */  printf ( "The interval was: %f seconds\n",    (double)( end - start ) / (double)CLOCKS_PER_SEC );  return 0;}

I am still trying to figure out how to use it for what I need.

sudo code is

images moves down 1 unit waits for timer to hit one second and then moves down another unit. after 10 lines are cleared then
it repeats but moves after timer hits 500 milliseconds
and repeats
ect

Share on other sites
I dont have my timer code with me but I can try to remember it

class CTimer
{

protected:

INT64 m_Frequency;

INT64 m_StartTime;
INT64 m_EndTime;

float m_Elapsed;

public:

// Call once at init
void Init()
{
QueryPerformanceFrequency(&m_Frequency);
QueryPerformanceCounter(&m_StartTime);
}

// Call once per frame
void Update()
{
QueryPerformanceCounter(&m_EndTime);

m_Elapsed = (m_EndTime - m_StartTime) / m_Frequency;

QueryPerformanceCounter(&m_StartTime);
}

// Time elapsed between frames
float GetElapsed() { return m_Elapsed; }

};

Share on other sites
Sorry I don’t think I am asking the right question.

Because I just tried a timer and I can get it to print stuff every second but I am missing on how to print out things when it is called only when the time hits a second.
It would be like a wait command to wait for timer to equal 1 second

Does that make sense?

Share on other sites
I think you will want to learn how to handle WM_TIMER messages

Using Timers (Windows User Interface)
http://msdn.microsoft.com/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/Timers/UsingTimers.asp

Share on other sites
case WM_DESTROY:[KillTimer(hwnd, TIMER_ID_1SEC);KillTimer(hwnd, TIMER_ID_3SEC);PostQuiteMessage(0);}break:

should be:

case WM_DESTROY:{KillTimer(hwnd, TIMER_ID_1SEC);KillTimer(hwnd, TIMER_ID_3SEC);PostQuiteMessage(0);break:}

Share on other sites
you7 used [ instead of {

Share on other sites
does any one have good examples or a good tutorial
for WM_TIMER i cant find anything any good

Share on other sites
this is what I found out through my research
////////////////////////////////////////
WM_TIMER
GetTickCount()
Clock()
Time()
timeGetTime()
SetTimer();
sysdelay();
QueryPerformanceCounter();

This is all of the functions I could find

Is there any others;

And which one would I use for my function?

Share on other sites
I gave you this link before

http://msdn.microsoft.com/library/en-us/winui/WinUI/WindowsUserInterface/Windowing/Timers/UsingTimers.asp

it tells u exactly how to use WM_TIMER
I guess your too lazy to look at it
Im bored so I will try to explain how to use WM_TIMER

// This creates a timer that goes off every five seconds
SetTimer(hwnd, IDT_TIMER1, 5000, (TIMERPROC) NULL);

// Here is how to handle the WM_TIMER message
case WM_TIMER:  {    switch( wParam )    {    case IDT_TIMER1:      {        // Print Something To The Screen Every 5 seconds        // FunctionToPrintToTheScreen("Hello");        return 0;      }    }    return 0;  }

// And finally you can destroy the timer
KillTimer(hwnd, IDT_TIMER1);