CopyThread.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #pragma once
  2. #include "ClipboardViewer.h"
  3. #include <afxmt.h>
  4. struct CCopyConfig
  5. {
  6. public:
  7. // WM_CLIPBOARD_COPIED is sent to this window when a copy is made.
  8. HWND m_hClipHandler;
  9. // true to use PostMessage (asynchronous)
  10. // false to use SendMessage (synchronous)
  11. bool m_bAsyncCopy;
  12. // true to create a copy of the clipboard contents when it changes
  13. // false to ignore changes in the clipboard
  14. bool m_bCopyOnChange;
  15. // the supported types which are copied from the clipboard when it changes.
  16. CClipTypes* m_pSupportedTypes; // ONLY accessed from CopyThread
  17. CCopyConfig( HWND hClipHandler = NULL,
  18. bool bAsyncCopy = false,
  19. bool bCopyOnChange = false,
  20. CClipTypes* pSupportedTypes = NULL )
  21. {
  22. m_hClipHandler = hClipHandler;
  23. m_bAsyncCopy = bAsyncCopy;
  24. m_bCopyOnChange = bCopyOnChange;
  25. m_pSupportedTypes = pSupportedTypes;
  26. }
  27. void DeleteTypes()
  28. {
  29. if( m_pSupportedTypes )
  30. {
  31. delete m_pSupportedTypes;
  32. m_pSupportedTypes = NULL;
  33. }
  34. }
  35. };
  36. class CCopyThread : public CWinThread
  37. {
  38. DECLARE_DYNCREATE(CCopyThread)
  39. public:
  40. CCopyThread();
  41. virtual ~CCopyThread();
  42. // Attributes
  43. public:
  44. // Operations
  45. public:
  46. bool m_bQuit;
  47. bool m_connectOnStartup;
  48. CCriticalSection m_cs;
  49. // CopyThread Local (accessed from this CopyThread)
  50. // window owned by this thread which handles clipboard viewer messages
  51. CClipboardViewer* m_pClipboardViewer; // permanent during lifetime of thread
  52. CCopyConfig m_LocalConfig;
  53. // Called within Copy Thread:
  54. void OnClipboardChange(CString activeWindow); // called by ClipboardViewer
  55. void SyncConfig(); // safely syncs m_LocalConfig with m_SharedConfig
  56. // Shared (use thread-safe access functions below)
  57. CCopyConfig m_SharedConfig;
  58. bool m_bConfigChanged; // true if m_SharedConfig was changed.
  59. // Called within Main thread:
  60. bool IsClipboardViewerConnected();
  61. bool GetConnectCV();
  62. void SetConnectCV(bool bConnect);
  63. void SetSupportedTypes(CClipTypes* pTypes); // CopyThread will own pTypes
  64. HWND SetClipHandler(HWND hWnd); // returns previous value
  65. HWND GetClipHandler();
  66. bool SetCopyOnChange(bool bVal); // returns previous value
  67. bool GetCopyOnChange();
  68. bool SetAsyncCopy(bool bVal); // returns previous value
  69. bool GetAsyncCopy();
  70. void Init(CCopyConfig cfg);
  71. bool Quit();
  72. virtual BOOL InitInstance();
  73. virtual int ExitInstance();
  74. };