TracePage.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /****************************************************************/
  2. /* */
  3. /* TracePage.cpp */
  4. /* */
  5. /* Implementation of the CTracePage class. */
  6. /* This class is a part of the FTP Server Application */
  7. /* */
  8. /* Programmed by LYFZ van der Meer */
  9. /* Copyright LYFZ Software Solutions 2002 */
  10. /* http://www.LYFZvandermeer.nl */
  11. /* */
  12. /* Last updated: 10 july 2002 */
  13. /* */
  14. /****************************************************************/
  15. #include "stdafx.h"
  16. #include "DBServer.h"
  17. #include "TracePage.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. IMPLEMENT_DYNCREATE(CTracePage, CDialog)
  24. CTracePage::CTracePage() : CDialog(CTracePage::IDD)
  25. {
  26. //{{AFX_DATA_INIT(CTracePage)
  27. // NOTE: the ClassWizard will add member initialization here
  28. //}}AFX_DATA_INIT
  29. }
  30. CTracePage::~CTracePage()
  31. {
  32. while(!m_LogQueue.IsEmpty())
  33. {
  34. CLogMsg *pLogMsg = (CLogMsg *)m_LogQueue.RemoveHead();
  35. delete pLogMsg;
  36. }
  37. }
  38. void CTracePage::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CDialog::DoDataExchange(pDX);
  41. //{{AFX_DATA_MAP(CTracePage)
  42. DDX_Control(pDX, IDC_TRACE, m_TraceList);
  43. //}}AFX_DATA_MAP
  44. }
  45. BEGIN_MESSAGE_MAP(CTracePage, CDialog)
  46. //{{AFX_MSG_MAP(CTracePage)
  47. ON_WM_SIZE()
  48. ON_COMMAND(ID_TRACE_CLEAR, OnTraceClear)
  49. ON_WM_CONTEXTMENU()
  50. //}}AFX_MSG_MAP
  51. ON_MESSAGE(WM_ADDTRACELINE, OnAddTraceLine)
  52. END_MESSAGE_MAP()
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CTracePage message handlers
  55. void CTracePage::AddTraceLine(int nLevel, LPCTSTR pstrFormat, ...)
  56. {
  57. CString str;
  58. // format and write the data we were given
  59. va_list args;
  60. va_start(args, pstrFormat);
  61. str.FormatV(pstrFormat, args);
  62. try
  63. {
  64. // create new message
  65. CLogMsg *pLogMsg = new CLogMsg;
  66. GetLocalTime(&pLogMsg->m_sysTime);
  67. pLogMsg->m_nLevel = nLevel;
  68. pLogMsg->m_strText = str;
  69. m_QueueLock.Lock();
  70. m_LogQueue.AddTail(pLogMsg);
  71. m_QueueLock.Unlock();
  72. // schedule log action
  73. PostMessage(WM_ADDTRACELINE);
  74. }
  75. catch(...)
  76. {
  77. }
  78. }
  79. LRESULT CTracePage::OnAddTraceLine(WPARAM, LPARAM)
  80. {
  81. CLogMsg *pLogMsg;
  82. try
  83. {
  84. // get first message in the queue
  85. // m_QueueLock.Lock();
  86. pLogMsg = (CLogMsg *)m_LogQueue.RemoveHead();
  87. // m_QueueLock.Unlock();
  88. switch(pLogMsg->m_nLevel)
  89. {
  90. case 1:
  91. m_TraceList.AddString(pLogMsg->m_strText, RGB(0,130,0));
  92. break;
  93. case 2:
  94. m_TraceList.AddString(pLogMsg->m_strText, RGB(0,0,255));
  95. break;
  96. case 3:
  97. m_TraceList.AddString(pLogMsg->m_strText, RGB(255,0,0));
  98. break;
  99. default:
  100. m_TraceList.AddString(pLogMsg->m_strText, RGB(0,0,0));
  101. break;
  102. }
  103. /* CString strDateTime;
  104. strDateTime.Format("%02d/%02d/%02d %02d:%02d:%02d.%03d ",
  105. pLogMsg->m_sysTime.wDay, pLogMsg->m_sysTime.wMonth, pLogMsg->m_sysTime.wYear,
  106. pLogMsg->m_sysTime.wHour, pLogMsg->m_sysTime.wMinute, pLogMsg->m_sysTime.wSecond,
  107. pLogMsg->m_sysTime.wMilliseconds);
  108. switch(pLogMsg->m_nLevel)
  109. {
  110. case 1:
  111. m_LogFile << error_lvl << strDateTime << pLogMsg->m_strText << endl;
  112. break;
  113. case 2:
  114. m_LogFile << warning_lvl << strDateTime << pLogMsg->m_strText << endl;
  115. break;
  116. case 3:
  117. default:
  118. m_LogFile << trace_lvl << strDateTime << pLogMsg->m_strText << endl;
  119. break;
  120. } */
  121. delete pLogMsg;
  122. }
  123. catch(...)
  124. {
  125. // something is wrong...
  126. }
  127. return TRUE;
  128. }
  129. void CTracePage::OnSize(UINT nType, int cx, int cy)
  130. {
  131. CDialog::OnSize(nType, cx, cy);
  132. if (IsWindow(::GetDlgItem(m_hWnd, IDC_TRACE)))
  133. {
  134. CRect rect;
  135. GetClientRect(rect);
  136. // rect.DeflateRect(5,5,10,10);
  137. m_TraceList.MoveWindow(rect);
  138. }
  139. }
  140. void CTracePage::OnTraceClear()
  141. {
  142. m_TraceList.ResetContent();
  143. }
  144. void CTracePage::OnContextMenu(CWnd* pWnd, CPoint point)
  145. {
  146. CMenu menu;
  147. menu.LoadMenu(MAKEINTRESOURCE(IDR_TRACE_MENU));
  148. menu.GetSubMenu(0)->TrackPopupMenu(0, point.x, point.y, this, NULL);
  149. }