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.

IntervalTimer.h 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. *
  3. * This is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This software is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this software; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  16. * USA.
  17. */
  18. // -=- IntervalTimer.h
  19. //
  20. // Simple wrapper for standard Win32 timers
  21. #ifndef __RFB_WIN32_INTERVAL_TIMER_H__
  22. #define __RFB_WIN32_INTERVAL_TIMER_H__
  23. namespace rfb {
  24. namespace win32 {
  25. struct IntervalTimer {
  26. IntervalTimer(HWND hwnd_, int id_)
  27. : hwnd(hwnd_), id(id_), active(false) {
  28. }
  29. IntervalTimer() : hwnd(0), id(0), active(false) {
  30. }
  31. ~IntervalTimer() {
  32. stop();
  33. }
  34. void start(int interval_) {
  35. if (!active || interval_ != interval) {
  36. interval = interval_;
  37. if (!SetTimer(hwnd, id, interval, 0))
  38. throw rdr::SystemException("SetTimer", GetLastError());
  39. active = true;
  40. }
  41. }
  42. void stop() {
  43. if (active)
  44. KillTimer(hwnd, id);
  45. active = false;
  46. }
  47. void setHWND(HWND hwnd_) {hwnd=hwnd_;}
  48. void setId(int id_) {id = id_;}
  49. int getId() const {return id;}
  50. bool isActive() const {return active;}
  51. private:
  52. HWND hwnd;
  53. int id;
  54. bool active;
  55. int interval;
  56. };
  57. }; // win32
  58. }; // rfb
  59. #endif // __RFB_WIN32_INTERVAL_TIMER_H__