home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 8090 / ModelEdit.7z / win_idle.h < prev   
Encoding:
C/C++ Source or Header  |  2006-03-08  |  1.5 KB  |  72 lines

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