LogCtrl.h
上传用户:sesekoo
上传日期:2020-07-18
资源大小:21543k
文件大小:5k
源码类别:

界面编程

开发平台:

Visual C++

  1. // LogCtrl.h : interface of the CLogCtrl class
  2. //
  3. /////////////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_CHILDVIEW_H__7627BE0E_E398_44DE_B281_3696A9A0C8BA__INCLUDED_)
  5. #define AFX_CHILDVIEW_H__7627BE0E_E398_44DE_B281_3696A9A0C8BA__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. /////////////////////////////////////////////////////////////////////////////
  10. // CLogCtrl window
  11. #define ID_TIMER_DELAYED_UPDATE 1
  12. #define ELAPSE_TIMER_DELAYED_UPDATE 50
  13. #define ID_TIMER_DELAYED_DESTROY 2
  14. #define ID_TIMER_EVENT_SOURCE 3
  15. #define ELAPSE_TIMER_EVENT_SOURCE 50
  16. #define WM_USR_WRITE_LOG_TEXT (WM_USER + 0x1234)
  17. class CLogCtrl : public CRichEditCtrl
  18. {
  19. DWORD m_dwHelperThreadID;
  20. struct _MthMessageDataFor_WM_USR_WRITE_LOG_TEXT
  21. {
  22. bool m_bBold:1;
  23. COLORREF m_clrText;
  24. LPCTSTR m_sText;
  25. _MthMessageDataFor_WM_USR_WRITE_LOG_TEXT(
  26. bool bBold,
  27. COLORREF clrText,
  28. LPCTSTR sText
  29. )
  30. : m_bBold( bBold )
  31. , m_clrText( clrText )
  32. , m_sText( sText )
  33. {
  34. }
  35. operator LPARAM () const
  36. {
  37. return reinterpret_cast < LPARAM > ( this );
  38. }
  39. static _MthMessageDataFor_WM_USR_WRITE_LOG_TEXT &
  40. FromLPARAM(
  41. LPARAM lParam
  42. )
  43. {
  44. _MthMessageDataFor_WM_USR_WRITE_LOG_TEXT * pData =
  45. reinterpret_cast < _MthMessageDataFor_WM_USR_WRITE_LOG_TEXT * > ( lParam );
  46. ASSERT( pData != NULL );
  47. return * pData;
  48. }
  49. }; // _MthMessageDataFor_WM_USR_WRITE_LOG_TEXT
  50. // Construction
  51. public:
  52. CLogCtrl();
  53. // Attributes
  54. public:
  55. LONG m_nLineCountMax;
  56. // Operations
  57. public:
  58. BOOL Create(
  59. CWnd * pWndParent,
  60. UINT nID = UINT(IDC_STATIC),
  61. CRect rect = CRect(0,0,0,0),
  62. DWORD dwWindowStyles =
  63. WS_CHILD|WS_VISIBLE
  64. |WS_HSCROLL|WS_VSCROLL
  65. |ES_AUTOHSCROLL|ES_AUTOVSCROLL
  66. |ES_LEFT|ES_MULTILINE|ES_NOHIDESEL
  67. |ES_READONLY
  68. )
  69. {
  70. m_dwHelperThreadID = ::GetCurrentThreadId();
  71. return
  72. CRichEditCtrl::Create(
  73. dwWindowStyles,
  74. rect,
  75. pWndParent,
  76. nID
  77. );
  78. }
  79. void WriteText(
  80. bool bBold,
  81. COLORREF clrText,
  82. LPCTSTR sText
  83. );
  84. // Overrides
  85. // ClassWizard generated virtual function overrides
  86. //{{AFX_VIRTUAL(CLogCtrl)
  87. public:
  88. protected:
  89. virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  90. //}}AFX_VIRTUAL
  91. // Implementation
  92. public:
  93. virtual ~CLogCtrl();
  94. protected:
  95. void _InitRichEditProps();
  96. bool _CanUpdate();
  97. // Generated message map functions
  98. protected:
  99. //{{AFX_MSG(CLogCtrl)
  100. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  101. afx_msg void OnTimer(__EXT_MFC_UINT_PTR nIDEvent);
  102. afx_msg void OnEditCopy();
  103. afx_msg void OnUpdateEditCopy(CCmdUI* pCmdUI);
  104. //}}AFX_MSG
  105. afx_msg LRESULT On_WM_USR_WRITE_LOG_TEXT( WPARAM wParam, LPARAM lParam );
  106. DECLARE_MESSAGE_MAP()
  107. };
  108. /////////////////////////////////////////////////////////////////////////////
  109. // CDemoEventSourceWnd window
  110. class CDemoEventSourceWnd : public CWnd
  111. {
  112. // Construction
  113. public:
  114. CLogCtrl * m_pWndLogCtrl;
  115. CDemoEventSourceWnd();
  116. // Attributes
  117. public:
  118. private:
  119. int m_nDemoOutputLineIndex;
  120. // Operations
  121. public:
  122. // Overrides
  123. // ClassWizard generated virtual function overrides
  124. //{{AFX_VIRTUAL(CDemoEventSourceWnd)
  125. protected:
  126. //}}AFX_VIRTUAL
  127. // Implementation
  128. public:
  129. virtual ~CDemoEventSourceWnd();
  130. // Generated message map functions
  131. protected:
  132. //{{AFX_MSG(CDemoEventSourceWnd)
  133. afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  134. afx_msg void OnTimer(__EXT_MFC_UINT_PTR nIDEvent);
  135. //}}AFX_MSG
  136. DECLARE_MESSAGE_MAP()
  137. };
  138. /////////////////////////////////////////////////////////////////////////////
  139. // CDemoEventSourceThread
  140. class CDemoEventSourceThread : public CWinThread
  141. {
  142. CWnd * m_pWndParent;
  143. public:
  144. CDemoEventSourceWnd m_wndDemoEventSource;
  145. CDemoEventSourceThread()
  146. : m_pWndParent( NULL )
  147. {
  148. m_bAutoDelete = FALSE;
  149. }
  150. CDemoEventSourceThread(
  151. CWnd * pWndParent
  152. )
  153. : m_pWndParent( pWndParent )
  154. {
  155. m_bAutoDelete = FALSE;
  156. ASSERT_VALID( m_pWndParent );
  157. ASSERT( m_pWndParent->GetSafeHwnd() != NULL );
  158. ASSERT( ::IsWindow(m_pWndParent->GetSafeHwnd()) );
  159. ASSERT( m_wndDemoEventSource.GetSafeHwnd() == NULL );
  160. }
  161. BOOL CreateThread(
  162. CWnd * pWndParent
  163. )
  164. {
  165. m_pWndParent = pWndParent;
  166. ASSERT_VALID( m_pWndParent );
  167. ASSERT( m_pWndParent->GetSafeHwnd() != NULL );
  168. ASSERT( ::IsWindow(m_pWndParent->GetSafeHwnd()) );
  169. ASSERT( m_wndDemoEventSource.GetSafeHwnd() == NULL );
  170. return CWinThread::CreateThread();
  171. }
  172. virtual BOOL InitInstance()
  173. {
  174. CRect rect;
  175. m_pWndParent->GetClientRect( &rect );
  176. if( !m_wndDemoEventSource.Create(
  177. ::AfxRegisterWndClass(0),
  178. _T("Demo Event Source Windop"),
  179. WS_CHILD,
  180. CRect( 0, 0, 0, 0 ),
  181. m_pWndParent,
  182. UINT(IDC_STATIC)
  183. )
  184. )
  185. {
  186. ASSERT( FALSE );
  187. TRACE0("Failed to create m_wndDemoEventSourcen");
  188. return FALSE;
  189. }
  190. m_pMainWnd = &m_wndDemoEventSource;
  191. return TRUE;
  192. }
  193. }; // class CDemoEventSourceThread
  194. /////////////////////////////////////////////////////////////////////////////
  195. //{{AFX_INSERT_LOCATION}}
  196. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  197. #endif // !defined(AFX_CHILDVIEW_H__7627BE0E_E398_44DE_B281_3696A9A0C8BA__INCLUDED_)