Archived

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

SetTimer PROBLEM!!

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have to timers, one of them actualice the screen every second, and the second is for a clock alarm, when time decrease to 0 it must be print a alarm message, but it prints the message every second, how i can manage the two timers without problems between them? thanx [edited by - q2guy on September 10, 2002 12:44:07 PM]

Share this post


Link to post
Share on other sites
this is the code:

void CALLBACK alarm_msg(HWND hwnd,UINT ms,UINT id,DWORD time)
{
MessageBox(hwnd,"Alarm","alarm",MB_OK);
return;
}

wndproc:
SetTimer(hWnd,2,100,NULL); //actualice the text, go well
SetTimer(hWnd,3,(UINT)time*1000,alarm_msg);

case WM_TIMER:
InvalidateRect(hWnd,&rectWindow,TRUE);
break;

case WM_PAINT:
// put gdi text in window,actualiced every second

the second timer go bad, i want to put a message for example after (x time)seconds, but it put it every second, too much message box

Share this post


Link to post
Share on other sites
Double check for the id in your WndProc as well as in alarm_msg.
eg:

WM_TIMER:
switch(wparam)
{
case 2: // actualize text
case 3: // might not need this, will call alarm_msg instead
}

When you got the WM_TIMER event, or handle similar event, remember to stop the timer, otherwise the timer will still going.

Share this post


Link to post
Share on other sites
quote:
Original post by q2guy
i have had this, but make the same problem, where must be SetTimer be called? in wndproc, after before of swicth messages?


SetTimer initially (usually) called in WM_CREATE. Other subsequent call depends... for me... I might do this:

void CALLBACK TimerCallback(HWND hwnd,UINT ms,UINT id,DWORD time)
{
KillTimer(...);

// do something here

SetTimer(...);
}


[edited by - DerekSaw on September 11, 2002 2:30:35 AM]

Share this post


Link to post
Share on other sites