Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

244 lines
4.5 KiB

  1. /*++
  2. Copyright(C) Microsoft Corporation 1997 - 1999
  3. File:
  4. uttime.cpp
  5. Abstract:
  6. Timer management utility API
  7. History:
  8. 02/22/99 FredCh Created
  9. --*/
  10. #include <adcg.h>
  11. #include <uttime.h>
  12. #define TRC_GROUP TRC_GROUP_UTILITIES
  13. #undef TRC_FILE
  14. #define TRC_FILE "uttime"
  15. extern "C"
  16. {
  17. #include <atrcapi.h>
  18. }
  19. #include "autil.h"
  20. //-----------------------------------------------------------------------------
  21. //
  22. // UT_Timer structure returned as application timer handle
  23. //
  24. //-----------------------------------------------------------------------------
  25. typedef struct _UT_Timer
  26. {
  27. HWND hWnd;
  28. DCUINT EventId;
  29. DCUINT ElaspeTime;
  30. INT_PTR hTimer;
  31. } UT_TIMER;
  32. typedef UT_TIMER * PUT_TIMER;
  33. typedef PUT_TIMER LPUT_TIMER;
  34. //-----------------------------------------------------------------------------
  35. //
  36. // Function:
  37. //
  38. // UTCreateTimer
  39. //
  40. // Description:
  41. //
  42. // Create a timer handle
  43. //
  44. // Parameters:
  45. //
  46. // hWnd - Window handle to receive timer notification.
  47. // nIDEvent - Timer ID to identify this timer event
  48. // uElaspe - Elaspe time before a timer notification is sent
  49. //
  50. // Return:
  51. //
  52. // A non-NULL handle if successful. Returns NULL if failed.
  53. //
  54. //
  55. //-----------------------------------------------------------------------------
  56. HANDLE
  57. CUT::UTCreateTimer(
  58. HWND hWnd,
  59. DCUINT nIDEvent,
  60. DCUINT uElapse )
  61. {
  62. PUT_TIMER
  63. pNewTimer;
  64. pNewTimer = ( PUT_TIMER )UTMalloc( sizeof( UT_TIMER ) );
  65. if( NULL == pNewTimer )
  66. {
  67. return( NULL );
  68. }
  69. pNewTimer->hWnd = hWnd;
  70. pNewTimer->EventId = nIDEvent;
  71. pNewTimer->ElaspeTime = uElapse;
  72. pNewTimer->hTimer = 0;
  73. return( ( HANDLE )pNewTimer );
  74. }
  75. //-----------------------------------------------------------------------------
  76. //
  77. // Function:
  78. //
  79. // UTStartTimer
  80. //
  81. // Description:
  82. //
  83. // Start the identified by the given timer handle
  84. //
  85. // Parameter:
  86. //
  87. // Timer handle identifying a timer that was previously created by
  88. // UTCreateTimer
  89. //
  90. // Return:
  91. //
  92. // TRUE if the timer is started successfully or FALSE otherwise.
  93. //
  94. //-----------------------------------------------------------------------------
  95. DCBOOL
  96. CUT::UTStartTimer(
  97. HANDLE hTimer )
  98. {
  99. PUT_TIMER
  100. pTimer = ( PUT_TIMER )hTimer;
  101. if( NULL == pTimer )
  102. {
  103. return( FALSE );
  104. }
  105. if( pTimer->hTimer )
  106. {
  107. //
  108. // stop the old timer
  109. //
  110. UTStopTimer( hTimer );
  111. }
  112. //
  113. // start a new timer
  114. //
  115. pTimer->hTimer = SetTimer(
  116. pTimer->hWnd,
  117. pTimer->EventId,
  118. pTimer->ElaspeTime,
  119. NULL );
  120. if( 0 == pTimer )
  121. {
  122. return( FALSE );
  123. }
  124. return( TRUE );
  125. }
  126. //-----------------------------------------------------------------------------
  127. //
  128. // Function:
  129. //
  130. // UTStopTimer
  131. //
  132. // Description:
  133. //
  134. // Stops a timer.
  135. //
  136. // Parameters:
  137. //
  138. // hTimer - Timer handle identifying a timer that was started.
  139. //
  140. // Return:
  141. //
  142. // TRUE if the timer is stopped successfully or FALSE otherwise.
  143. //
  144. //-----------------------------------------------------------------------------
  145. DCBOOL
  146. CUT::UTStopTimer(
  147. HANDLE hTimer )
  148. {
  149. PUT_TIMER
  150. pTimer = ( PUT_TIMER )hTimer;
  151. if( NULL == pTimer )
  152. {
  153. return( FALSE );
  154. }
  155. if( 0 == pTimer->hTimer )
  156. {
  157. return( FALSE );
  158. }
  159. if( KillTimer( pTimer->hWnd, pTimer->hTimer ) )
  160. {
  161. pTimer->hTimer = 0;
  162. return( TRUE );
  163. }
  164. return( FALSE );
  165. }
  166. //-----------------------------------------------------------------------------
  167. //
  168. // Function:
  169. //
  170. // UTDeleteTimer
  171. //
  172. // Description:
  173. //
  174. // Deletes a timer. The timer handle can no longer be used after it has
  175. // been deleted.
  176. //
  177. // Parameters:
  178. //
  179. // hTimer - Timer handle identifying the timer to be deleted.
  180. //
  181. // Return:
  182. //
  183. // TRUE if the timer is deleted successfully or FALSE otherwise.
  184. //
  185. //-----------------------------------------------------------------------------
  186. DCBOOL
  187. CUT::UTDeleteTimer(
  188. HANDLE hTimer )
  189. {
  190. if( NULL == ( PUT_TIMER )hTimer )
  191. {
  192. return( FALSE );
  193. }
  194. UTStopTimer( hTimer );
  195. UTFree( ( PDCVOID )hTimer );
  196. return( TRUE );
  197. }