WindowThread.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #ifndef __WindowThread_h__
  2. #define __WindowThread_h__
  3. #if _MSC_VER > 1000
  4. #pragma once
  5. #endif // _MSC_VER > 1000
  6. #include <..\TCLib\WindowThreadImpl.h>
  7. /////////////////////////////////////////////////////////////////////////////
  8. // Description:
  9. class TCWindowCreatorBase
  10. {
  11. // Overrides
  12. public:
  13. virtual HWND Create(TCWindowThreadBase::XArgs& args) = 0;
  14. };
  15. /////////////////////////////////////////////////////////////////////////////
  16. // Description:
  17. template <class T>
  18. class TCWindowImplCreator : public TCWindowCreatorBase
  19. {
  20. // Construction
  21. public:
  22. TCWindowImplCreator(CWindowImpl<T>* pwi) :
  23. m_pwi(pwi)
  24. {
  25. assert(m_pwi);
  26. }
  27. // Overrides
  28. public:
  29. virtual HWND Create(TCWindowThreadBase::XArgs& args)
  30. {
  31. RECT rcPos = {args.x, args.y, args.x + args.cx, args.y + args.cy};
  32. return m_pwi->Create(args.hwndParent, rcPos, args.pszWindowName,
  33. args.dwStyle, args.dwExStyle, args.nIdOrMenu);
  34. }
  35. // Data Members
  36. protected:
  37. CWindowImpl<T>* m_pwi;
  38. };
  39. /////////////////////////////////////////////////////////////////////////////
  40. // Description:
  41. class TCContainedWindowCreator : public TCWindowCreatorBase
  42. {
  43. // Construction
  44. public:
  45. TCContainedWindowCreator(CContainedWindow* pcw) :
  46. m_pcw(pcw)
  47. {
  48. assert(m_pcw);
  49. }
  50. // Overrides
  51. public:
  52. virtual HWND Create(TCWindowThreadBase::XArgs& args)
  53. {
  54. RECT rcPos = {args.x, args.y, args.x + args.cx, args.y + args.cy};
  55. return m_pcw->Create(args.hwndParent, rcPos, args.pszWindowName,
  56. args.dwStyle, args.dwExStyle, args.nIdOrMenu);
  57. }
  58. // Data Members
  59. protected:
  60. CContainedWindow* m_pcw;
  61. };
  62. /////////////////////////////////////////////////////////////////////////////
  63. // Description:
  64. template <class T>
  65. class TCDialogImplCreator : public TCWindowCreatorBase
  66. {
  67. // Construction
  68. public:
  69. TCDialogImplCreator(CDialogImpl<T>* pdi) :
  70. m_pdi(pdi)
  71. {
  72. assert(m_pdi);
  73. }
  74. // Overrides
  75. public:
  76. virtual HWND Create(TCWindowThreadBase::XArgs& args)
  77. {
  78. RECT rcPos = {args.x, args.y, args.x + args.cx, args.y + args.cy};
  79. return m_pdi->Create(args.hwndParent);
  80. }
  81. // Data Members
  82. protected:
  83. CDialogImpl<T>* m_pdi;
  84. };
  85. /////////////////////////////////////////////////////////////////////////////
  86. // Description: Implements a thread with a message loop that can create
  87. // windows owned by the thread.
  88. //
  89. // See Also: TCWndThread (MFC equivalent - doesn't exist yet)
  90. //
  91. class TCWindowThread : public TCWindowThreadImpl<TCWindowThread>
  92. {
  93. // Group=Overrides
  94. public:
  95. HWND DoCreateWindowOnThread(XArgs& args);
  96. };
  97. /////////////////////////////////////////////////////////////////////////////
  98. // Group=Overrides
  99. inline HWND TCWindowThread::DoCreateWindowOnThread(
  100. TCWindowThread::XArgs& args)
  101. {
  102. // Delegate to the base class method when pvParam is NULL
  103. if (!args.pvParam)
  104. return TCWindowThreadImplBase::DoCreateWindowOnThread(args);
  105. // Reinterpret the parameter as an TCWindowCreatorBase*
  106. TCWindowCreatorBase* pc = (TCWindowCreatorBase*)(args.pvParam);
  107. // Create the window as specified
  108. return pc->Create(args);
  109. }
  110. /////////////////////////////////////////////////////////////////////////////
  111. // Description:
  112. template <class T>
  113. class TCWindowImpl : public CWindowImpl<T>
  114. {
  115. // Group=Operations
  116. public:
  117. HWND CreateOnThread(TCWindowThread& wth, HWND hwndParent, RECT& rcPos,
  118. LPCTSTR szWindowName = NULL, DWORD dwStyle = WS_CHILD | WS_VISIBLE,
  119. DWORD dwExStyle = 0, UINT nID = 0, int* pnError = NULL,
  120. bool bSizeIsClient = false, bool bXlateDlgMsgs = false,
  121. HACCEL hAccel = NULL);
  122. };
  123. /////////////////////////////////////////////////////////////////////////////
  124. // Description:
  125. class TCContainedWindow : public CContainedWindow
  126. {
  127. // Group=Construction
  128. public:
  129. TCContainedWindow(LPTSTR pszClassName, CMessageMap* pObject,
  130. DWORD dwMsgMapID = 0);
  131. // Group=Operations
  132. public:
  133. HWND CreateOnThread(TCWindowThread& wth, HWND hwndParent, RECT& rcPos,
  134. LPCTSTR szWindowName = NULL, DWORD dwStyle = WS_CHILD | WS_VISIBLE,
  135. DWORD dwExStyle = 0, UINT nID = 0, int* pnError = NULL,
  136. bool bSizeIsClient = false, bool bXlateDlgMsgs = false,
  137. HACCEL hAccel = NULL);
  138. };
  139. /////////////////////////////////////////////////////////////////////////////
  140. // Description:
  141. template <class T>
  142. class TCDialogImpl : public CDialogImpl<T>
  143. {
  144. // Group=Operations
  145. public:
  146. HWND CreateOnThread(TCWindowThread& wth, HWND hwndParent,
  147. int* pnError = NULL);
  148. };
  149. /////////////////////////////////////////////////////////////////////////////
  150. // Group=Construction
  151. inline TCContainedWindow::TCContainedWindow(LPTSTR pszClassName,
  152. CMessageMap* pObject, DWORD dwMsgMapID) :
  153. CContainedWindow(pszClassName, pObject, dwMsgMapID)
  154. {
  155. }
  156. /////////////////////////////////////////////////////////////////////////////
  157. // Group=Operations
  158. template <class T>
  159. inline HWND TCWindowImpl<T>::CreateOnThread(TCWindowThread& wth,
  160. HWND hwndParent, RECT& rcPos, LPCTSTR szWindowName, DWORD dwStyle,
  161. DWORD dwExStyle, UINT nID, int* pnError, bool bSizeIsClient,
  162. bool bXlateDlgMsgs, HACCEL hAccel)
  163. {
  164. TCWindowImplCreator<T> wic(this);
  165. return wth.CreateWindowExOnThread(dwExStyle, NULL, szWindowName, dwStyle,
  166. rcPos.left, rcPos.top, rcPos.right - rcPos.left,
  167. rcPos.bottom - rcPos.top, hwndParent, nID, NULL, &wic, pnError,
  168. bSizeIsClient, bXlateDlgMsgs, hAccel);
  169. }
  170. inline HWND TCContainedWindow::CreateOnThread(TCWindowThread& wth,
  171. HWND hwndParent, RECT& rcPos, LPCTSTR szWindowName, DWORD dwStyle,
  172. DWORD dwExStyle, UINT nID, int* pnError, bool bSizeIsClient,
  173. bool bXlateDlgMsgs, HACCEL hAccel)
  174. {
  175. TCContainedWindowCreator cwc(this);
  176. return wth.CreateWindowExOnThread(dwExStyle, NULL, szWindowName, dwStyle,
  177. rcPos.left, rcPos.top, rcPos.right - rcPos.left,
  178. rcPos.bottom - rcPos.top, hwndParent, nID, NULL, &cwc, pnError,
  179. bSizeIsClient, bXlateDlgMsgs, hAccel);
  180. }
  181. template <class T>
  182. inline HWND TCDialogImpl<T>::CreateOnThread(TCWindowThread& wth,
  183. HWND hwndParent, int* pnError)
  184. {
  185. TCDialogImplCreator<T> dic(this);
  186. return wth.CreateWindowOnThread(NULL, NULL, 0, 0, 0, 0, 0, hwndParent, 0,
  187. NULL, &dic, pnError, false, true, NULL);
  188. }
  189. /////////////////////////////////////////////////////////////////////////////
  190. #endif // !__WindowThread_h__