Home
Tutorials
Code Snippets
Code Samples
Downloads
Links

The Blog
Our Projects
About
Contact

::Add RageStorm to Favorites!::

The Blog | Our Projects | Guest Book | About | Contact

 
Code Snippet - Multimedia Timers
Author:Arkon
Category:Win32API
File Size:967 Bytes
Uploaded at:27-Nov-02 03:10:46 pm
Description:
  Forget about the crappy SetTimer/KillTimer functions, here are more accurate timers routines.
  
// Don't forget to import winmm.lib!

#include <mmsystem.h>

void FAR PASCAL OnTimerShot(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2)
{
 MessageBox(NULL, (LPSTR)dwUser, "timerproc", MB_OK);
}

UINT KillTimerCallback(UINT timerID)
{
 return(timeKillEvent(timerID) == TIMERR_NOERROR);
}

UINT SetTimerCallback(DWORD npSeq, UINT msInterval, UINT tEvent)

 UINT wTimerID = timeSetEvent(msInterval, msInterval, OnTimerShot, (DWORD)npSeq, tEvent);
 return(wTimerID);
}

//Easy to use, more accurate!

 char buffer[26] = "Testing user defined data";
 //TIME_ONESHOT - the callback function will be called ONCE after msInterval passed.
 //TIME_PERIODIC - the callback function will be called every msInterval.
 UINT timerID = SetTimerCallback((DWORD)(char [26])buffer, 1000/*mili seconds*/, TIME_ONESHOT);
 MessageBox(NULL, "On Start", "No Timer", 0);
 //If you want to stop a TIME_PRIODIC event call KillTimerCallback(timerID);
User Contributed Comments(2)
 [1] wang | 2007-12-12 22:46:20

Thank you
very usfull
Do you know what the "NPSEQ" struct is
and where is it defined?
 [2] arkon | 2007-12-14 02:42:06

here it's the user defined pointer, it's not a structure in any way. although it seems the msdn uses the npseq structure and i can't find it in the headers, maybe it's some remnants from the code they ripped the samples from...
NOTE:
Comments that will hurt anyone in any way will be deleted.
Don't ask for features, advertise or curse.
If you want to leave a message to the author use the contacts,
if you have any question in relation to your comments please use the forum.
Comments which violate any of these requests will be deleted without further
notice. Use the comment system decently.

Post your comment:
Name:
email:
Comment:
::Top 5 Tutorials::
Embedded Python[106775]
2D Rotated Rectangles Collision Detection[79918]
Keyboard Hook[69063]
UDP[53058]
HTTP Proxy[36303]

::Top 5 Samples::
2D ColDet Rotated Rectangles[10638]
PS2 Mouse Driver[6122]
Wave Format Player[5005]
Reading FAT12[4893]
CodeGuru[4579]


All rights reserved to RageStorm © 2009