Team Fortress 2 Source Code as on 22/4/2020
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.

78 lines
1.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. // WinIdle.h - Defines a class for sending idle messages to a window from a secondary thread
  9. #ifndef __WINIDLE_H__
  10. #define __WINIDLE_H__
  11. class CWinIdle
  12. {
  13. protected:
  14. HANDLE m_hIdleEvent, m_hStopEvent;
  15. HWND m_hWnd;
  16. UINT m_uMsg;
  17. WPARAM m_wParam;
  18. LPARAM m_lParam;
  19. DWORD m_dwDelay;
  20. HANDLE m_hIdleThread;
  21. // The thread calling stub
  22. static DWORD WINAPI ThreadStub(LPVOID pIdle);
  23. // The actual idle loop
  24. virtual DWORD RunIdle();
  25. public:
  26. CWinIdle();
  27. virtual ~CWinIdle();
  28. inline DWORD GetDelay() {return m_dwDelay;}
  29. inline void SetDelay(DWORD delay) {m_dwDelay = delay;}
  30. // Member access
  31. virtual HANDLE GetThreadHandle() const { return m_hIdleThread; };
  32. // Start idling, and define the message and window to use
  33. // Returns TRUE on success
  34. virtual BOOL StartIdle(HWND hWnd, UINT uMessage, WPARAM wParam = 0, LPARAM lParam = 0, DWORD dwDelay = 0);
  35. // Stop idling
  36. // Returns TRUE on success
  37. virtual BOOL EndIdle();
  38. // Notify the idle process that the message was received.
  39. // Note : If this function is not called, the idle thread will not send any messages
  40. virtual void NextIdle();
  41. };
  42. // Used to slow down the idle thread while dialogs are up.
  43. class IdleChanger
  44. {
  45. public:
  46. IdleChanger(CWinIdle *pIdle, DWORD msDelay)
  47. {
  48. m_pIdle = pIdle;
  49. m_OldDelay = pIdle->GetDelay();
  50. pIdle->SetDelay(msDelay);
  51. }
  52. ~IdleChanger()
  53. {
  54. m_pIdle->SetDelay(m_OldDelay);
  55. }
  56. CWinIdle *m_pIdle;
  57. DWORD m_OldDelay;
  58. };
  59. #endif //__WINIDLE_H__