Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

The Timer

1,183 views

Published on

Published in: Technology, Education
  • Be the first to comment

  • Be the first to like this

The Timer

  1. 1. <ul><li>Gaurav Paliwal(007)‏ </li></ul><ul><li>Deepak Jain(054)‏ </li></ul><ul><li>Mayank Varshney(056)‏ </li></ul><ul><li>Amarjeet Chauhan(067)‏ </li></ul>
  2. 2. <ul><li>The Microsoft Windows timer is an input device that periodically notifies an application when a specified interval of time has elapsed. </li></ul><ul><li>Your program tells Windows the interval, in effect saying, for example, &quot;Give me a nudge every 10 seconds.&quot; Windows then sends your program recurrent WM_TIMER messages to signal the intervals. </li></ul>
  3. 3. <ul><li>Multitasking Sometimes it is more efficient for a program to return control to Windows as quickly as possible after processing a message. If a program must do a large amount of processing, it can divide the job into smaller pieces and process each piece upon receipt of a WM_TIMER message. </li></ul><ul><li>The timer is as a guarantee that a program can regain control sometime in the future afterexiting the window procedure. </li></ul><ul><li>Maintaining an updated status report A program can use the timer to display &quot;real-time&quot; updates of continuously changing information, such as a display of system resources or the progress of a certain task. </li></ul><ul><li>Implementing an &quot; autosave &quot; feature The timer can prompt a Windows program to save a user's work to disk whenever a specified period of time has elapsed. </li></ul>
  4. 4. <ul><li>Terminating &quot;dem o &quot; versions of programs Some demonstration versions of programs are designed to t erminate, say, 30 minutes after they begin. The timer can signal such applications when the time is up. </li></ul><ul><li>Pacing movement Graphical objects in a game or successive displays in a computer-assisted instruction program might need to proceed at a set rate. Using the timer eliminates the inconsistencies that might result from variations in microprocessor speed. </li></ul><ul><li>Multimedia Progr ams that play CD audio, sound, or music often let the audio data play in the background . A program can use the timer to periodically determine how much of the audio has played and to coordinate on-screen visual information. </li></ul>
  5. 5. <ul><li>SetTimer function : You can allocate a timer for your Windows program by calling it. SetTimer includes an unsigned integer argument specifying a time-out interval that can range (in theory) from 1 msec (millisecond) to 50 days(=4,294,967,295 msec). The value indicates the rate at which Windows sends your program WM_TIMER messages. </li></ul><ul><li>KillTimer function: It stops the timer messages. The KillTimer call purges the message queue of any pending WM_TIMER messages. No WM_TIMER messages can be received following a KillTimer call. </li></ul>
  6. 6. <ul><li>WM_TIMER : It is a normal message like any other window message that are sent to a window periodically through a message queue of that window. </li></ul><ul><li>It is a low priority message and a program will receive them only if there is no other message in the message queue. </li></ul><ul><li>Windows does not keep loading up the message queue with multiple WM_TIMER messages. Instead, Windows combines multiple WM_TIMER messages in the message queue into a single message. Therefore, the application won't get a bunch of them at once, although it might get two WM_TIMER messages in quick succession. </li></ul><ul><li>The WM_TIMER messages are not asynchronous. The WM_TIMER messages are placed in the normal queue. </li></ul>
  7. 7. <ul><li>Again using the timer basics her we have two steps: </li></ul><ul><li>1.call the SetTimer from WinMain function/ or processing the WM_CREATE message. </li></ul><ul><li>2.call the KillTimer on exiting WinMain/ or processing the WM_DESTROY message. </li></ul><ul><li>There are 3 methods to do so depending upon the arguments to the SetTimer function. </li></ul>
  8. 8. <ul><li>This method, the easiest, causes Windows to send WM_TIMER messages to the normal window procedure of the application. </li></ul><ul><li>The SetTimer call looks like this: </li></ul><ul><li>SetTimer (hwnd, 1, uiMsecInterval, NULL) ; </li></ul><ul><li>hwnd:handle to the window; </li></ul><ul><li>1 : Timer ID </li></ul><ul><li>uiMsecInterval: 32 bit intger variable for a time interval </li></ul><ul><li>You can stop the WM_TIMER messages at any time (even while processing a WM_TIMER message) by calling </li></ul><ul><li>KillTimer (hwnd, 1) ; </li></ul><ul><li>hwnd:handle to the window </li></ul><ul><li>1 :The same timer ID </li></ul>
  9. 9. <ul><li>With this second method, you can direct Windows to send the timer messages to another function within your program. </li></ul><ul><li>The function that receives these timer messages is termed a &quot;call-back&quot; function. This is a function in your program that is called from Windows. You tell Windows the address of this function, and Windows later calls the function. </li></ul><ul><li>The SetTimer call looks like this: </li></ul><ul><li> SetTimer (hwnd, iTimerID, iMsecInterval, TimerProc) ; </li></ul><ul><li>the fourth argument to SetTimer is instead the address of the </li></ul><ul><li>call-back function. </li></ul><ul><li>KillTimer (hwnd, 1) ; </li></ul><ul><li>This remains the same. </li></ul>
  10. 10. <ul><li>The third method of setting the timer is similar to the second method, except that the hwnd parameter to SetTimer is set to NULL and the second parameter (normally the timer ID) is ignored. Instead, the function returns a timer ID. </li></ul><ul><li>It might come in handy if you do a lot of SetTimer calls at different times in your program and don't want to keep track of which timer IDs you've already used. </li></ul><ul><li>The SetTimer call looks like this: </li></ul><ul><li> iTimerID = SetTimer (NULL, 0, wMsecInterval, TimerProc) ; </li></ul><ul><li>The iTimerID returned from SetTimer will be 0 in the rare event that no timer is available. </li></ul><ul><li>The first parameter to KillTimer (usually the window handle) must also be NULL. The timer ID must be the value returned from SetTimer. </li></ul><ul><li>KillTimer (NULL, iTimerID) ; </li></ul>
  11. 11. <ul><li>GetLocalTime function reports the local time,based on the time zone of the location of the computer. </li></ul><ul><li>GetSystemTime function reports the current Coordinated Universal Time (UTC), which is roughly the same as Greenwich mean time the date and time at Greenwich, England. </li></ul><ul><li>GetLocalTime , which takes as a single argument the SYSTEMTIME structure, defined in WINBASE.H like so: </li></ul><ul><li>typedef struct _SYSTEMTIME </li></ul><ul><li>{ </li></ul><ul><li>WORD wYear ; </li></ul><ul><li>WORD wMonth ; </li></ul><ul><li>WORD wDayOfWeek ; </li></ul><ul><li>WORD wDay ; </li></ul><ul><li>WORD wHour ; </li></ul><ul><li>WORD wMinute ; </li></ul><ul><li>WORD wSecond ; </li></ul><ul><li>WORD wMilliseconds ; </li></ul><ul><li>} </li></ul><ul><li>SYSTEMTIME, * PSYSTEMTIME ; </li></ul><ul><li>As is obvious, the SYSTEMTIME structure encodes the date as well as the time. </li></ul>

×