Timing

to create a timer, use:

     UNIT SetTimer(HWND hWnd,      // window handle

                                UNIT nIDEvent,   // timer id

                                UNIT  uElapse,     // millisecond delay

                                TIMERPROC lpTimerFunc); // callback addr

 

·       if the timer creates successfully it returns timerID, else 0

·       to send msgs to WinProc, set callback to NULL

·       once created, timer will send WM_TIME msg every interval, wparam will contain timer ID

·       destroy what you create when you’re done

o      KillTimer(hwnd, nIDEvent,); // deallocate timer 

 

EX:

#define T1_SECOND 1

#define T3_SECOND 2

 

case WM_CREATE // create 1 & 3 second timer

{  SetTimer((hwnd, T1_SECOND, 1000, NULL);

    SetTimer((hwnd, T3_SECOND, 3000, NULL);

    // …

    return(0);

}

case WM_TIMER

{ switch(wparam)

   { case T1_SECOND:

      { …} break;

      case T3_SECOND:

      { …} break;

   }

}

case WM_DESTROY

{ KillTimer(hwnd, T1_SECOND,); // deallocate timer 

   KillTimer(hwnd, T3_SECOND,); // deallocate timer

}

manual timers can be created using:

     DWORD start = GetTickCount();

     // delay 100 ms

     while (GetTickCount() – start < 100);