Settimerthe following example creates a timer (that isn't attached to a window) whose timer Procedure creates Boxes#include <windows.h>class foo_class { static int counter;public: static void __stdcall Timer_proc ( hwnd,unsigned int, unsigned int, unsigned long) { if (counter++ <) MessageBox (0, "Hello", "messagebox", 0); C7/>else postquitmessage (0); }; int foo_class::counter=0; WINAPI WinMain (hinstance,hinstance,lpstr,int) {int itimerid = settimer (0, 0, +, foo_class::timer_proc); MSG m; While (GetMessage (&m,0,0,0)) { translatemessage (&m); DispatchMessage (&m); } Return 1;} Createwaitabletimerthis example demonstrates how to use timers in Windows. A timer'll be set That's signalled for the first time 2 seconds after the first call to CreateWaitableTimer and then are Signalled every 3/4th of a second.#define _WIN32_WINNT 0x0400#include <windows.h> #include <process.h> #include <stdio.h>unsigned __ stdcall TF (void* arg) { HANDLE timer= (HANDLE) arg; While (1) { WaitForSingleObject (timer,infinite); printf (".");} } int main (int argc, char* argv[]) { HANDLE timer = createwaitabletimer ( 0, false,//false=>will be Automati Cally Reset 0); Name large_integer li; const INT unitspersecond=10*1000*1000; Nano seconds //Set The event the first time 2 seconds //after calling SetWaitableTimer li. quadpart=-(2*unitspersecond); SetWaitableTimer ( timer, &li, up , //Set the event every Milli Seconds 0, 0, false); _beginthreadex (0,0,tf, (void*) timer,0,0); Wait forever, while (1); Return 0;}
|