Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

timeSetEvent Example?

1,173 views
Skip to first unread message

Gary M. Trimble

unread,
Dec 4, 2000, 3:00:00 AM12/4/00
to
I need to set up a recurring periodic event in a Console application. I
started to use SetTimer but checked the application notes and they won't

work due to the incomplete implementation of some libraries regarding
Console Apps. The alternative multimedia timer timeSetEvent looks like
it will work but I'm having problems implementing it in my code. Can
someone post point me to an example of it's use (setup and response)?
Thanks!

Gary M. Trimble


Paolo Coletta

unread,
Dec 4, 2000, 3:00:00 AM12/4/00
to
Here is an example using the SetEvent mechanism.

Paolo Coletta

-----------------
#include <windows.h>

int main( int , char ** )
{
TIMECAPS tc;
timeGetDevCaps( &tc, sizeof( tc ) );
timeBeginPeriod( tc.wPeriodMin );
HANDLE hTimer = CreateEvent( NULL, FALSE, FALSE, NULL );
UINT uID = timeSetEvent( tc.wPeriodMin, 0, LPTIMECALLBACK( hTimer ), 0,
TIME_PERIODIC | TIME_CALLBACK_EVENT_SET );
while(true)
{
WaitForSingleObject( hTimer, INFINITE );

// Do something useful....

if( <<stop condition>> )
{
timeKillEvent( uID );
break;
}
}
timeEndPeriod( tc.wPeriodMin );
CloseHandle( hTimer );
return 0;
}

0 new messages