Source code of Windows XP (NT5)
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.

100 lines
3.1 KiB

  1. #ifndef _UEVTTMR_H
  2. #define _UEVTTMR_H
  3. #include "dpa.h"
  4. typedef struct
  5. {
  6. HWND hWnd;
  7. UINT uCallbackMessage;
  8. ULONG uUserEventTimerID;
  9. UINT uTimerElapse;
  10. UINT uIntervalCountdown;
  11. IUserEventTimerCallback * pUserEventTimerCallback;
  12. BOOL bFirstTime;
  13. }
  14. USEREVENTINFO;
  15. #define MIN_TIMER_THRESHOLD 0.1
  16. #define MAX_TIMER_THRESHOLD 0.01
  17. class CUserEventTimer : public IUserEventTimer
  18. {
  19. public:
  20. // *** IUnknown ***
  21. STDMETHODIMP QueryInterface(REFIID riid, void ** ppvObj);
  22. STDMETHODIMP_(ULONG) AddRef();
  23. STDMETHODIMP_(ULONG) Release();
  24. // *** IUserEventTimer ***
  25. STDMETHODIMP SetUserEventTimer( HWND hWnd,
  26. UINT uCallbackMessage,
  27. UINT uTimerElapse,
  28. IUserEventTimerCallback * pUserEventTimerCallback,
  29. ULONG * puUserEventTimerID);
  30. STDMETHODIMP KillUserEventTimer(HWND hWnd, ULONG uUserEventTimerID);
  31. STDMETHODIMP GetUserEventTimerElapsed(HWND hWnd, ULONG uUserEventTimerID, UINT * puTimerElapsed);
  32. STDMETHODIMP InitTimerTickInterval(UINT uTimerTickIntervalMs);
  33. CUserEventTimer();
  34. virtual ~CUserEventTimer();
  35. HRESULT Init();
  36. static STDMETHODIMP_(int) s_DeleteCB(LPVOID pData1, LPVOID pData2);
  37. LRESULT v_WndProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
  38. protected:
  39. static const UINT_PTR TIMER_ID = 1000;
  40. static const UINT TIMER_ELAPSE = 5000; // 5 seconds
  41. static const ULONG MIN_TIMER_ID = 0x00001000;
  42. static const ULONG MAX_TIMER_ID = 0xDDDD1000;
  43. // static const DWORD MIN_TIMER_LENGTH = 4500; // 4.5 seconds
  44. // static const DWORD MAX_TIMER_LENGTH = 5002; // 5 seconds + 2 milliseconds
  45. static LRESULT CALLBACK s_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  46. BOOL _CreateWindow();
  47. void _Destroy();
  48. void _OnTimer();
  49. void _KillIntervalTimer();
  50. int _GetTimerDetailsIndex(HWND hWnd, ULONG uUserEventTimerID);
  51. HRESULT _SetUserEventTimer( HWND hWnd, UINT uCallbackMessage,
  52. UINT uNumIntervals, IUserEventTimerCallback * pUserEventTimerCallback,
  53. ULONG * puUserEventTimerID);
  54. HRESULT _ResetUserEventTimer(HWND hWnd, UINT uCallbackMessage, UINT uNumIntervals,
  55. int nIndex);
  56. ULONG _GetNextInternalTimerID(HWND hWnd);
  57. inline BOOL _IsAssignedTimerID(HWND hWnd, ULONG uUserEventTimerID)
  58. {
  59. return (_GetTimerDetailsIndex(hWnd, uUserEventTimerID) >= 0);
  60. }
  61. inline UINT _CalcNumIntervals(UINT uTimerElapse)
  62. {
  63. return (UINT)(uTimerElapse/m_uTimerTickInterval);
  64. }
  65. inline UINT _CalcMilliSeconds(UINT uIntervalCountdown)
  66. {
  67. return (UINT) (uIntervalCountdown*m_uTimerTickInterval);
  68. }
  69. LONG m_cRef;
  70. CDPA<USEREVENTINFO> _dpaUserEventInfo;
  71. UINT_PTR _uUserTimerID;
  72. HWND m_hWnd;
  73. DWORD m_dwUserStartTime;
  74. UINT m_uTimerTickInterval;
  75. };
  76. #endif // _UEVTTMR_H