You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
2.6 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "objectMsOnWindowLoggingService.h"
  2. CSTR wstr2str(wchar_t * wideStr)
  3. {
  4. CSTR resultStr;
  5. resultStr = (CSTR) malloc(wcslen(wideStr) + 1);
  6. if (resultStr != NULL)
  7. {
  8. wsprintfA(resultStr, "%S", wideStr);
  9. }
  10. return resultStr;
  11. }
  12. wchar_t * str2wstr(CSTR Str)
  13. {
  14. wchar_t * resultStr;
  15. resultStr = (wchar_t *) malloc((strlen(Str) + 1) << 1);
  16. if (resultStr != NULL)
  17. {
  18. wsprintfW(resultStr, L"%s", Str);
  19. }
  20. return resultStr;
  21. }
  22. objectMsOnWindowLoggingService::objectMsOnWindowLoggingService(size_t Lines, vectorCSTR * VCT, HWND wnd) :
  23. basicLoggingService()
  24. {
  25. m_nLineNumber = Lines;
  26. // m_pMutex = new basicMutex();
  27. m_hWND = wnd;
  28. m_pMessages = VCT;
  29. m_pMessages->clear();
  30. m_bLogging = true;
  31. }
  32. objectMsOnWindowLoggingService::~objectMsOnWindowLoggingService()
  33. {
  34. if (m_bLogging)
  35. {
  36. m_bLogging = false;
  37. if (m_pMessages->size() > 0)
  38. {
  39. // m_pMutex->lock();
  40. while (m_pMessages->size())
  41. {
  42. delete((LPWSTR) *m_pMessages->begin());
  43. m_pMessages->erase(m_pMessages->begin());
  44. };
  45. // m_pMutex->unlock();
  46. };
  47. };
  48. // if (m_pMutex) delete(m_pMutex);
  49. }
  50. void objectMsOnWindowLoggingService::logMessage(CSTR Msg)
  51. {
  52. logMessage((const char *) Msg);
  53. }
  54. void objectMsOnWindowLoggingService::logMessage(const char * Msg)
  55. {
  56. if (m_bLogging)
  57. {
  58. time_t LocalTime;
  59. tm * gmt_time;
  60. time(&LocalTime);
  61. gmt_time = gmtime(&LocalTime);
  62. CSTR temp;
  63. temp = (CSTR) malloc(CLOG);
  64. if (temp != NULL)
  65. {
  66. sprintf(temp, "%04d-%02d-%02d %02d:%02d:%02d %s\n", 1900 + gmt_time->tm_year, 1 + gmt_time->tm_mon, gmt_time->tm_mday, gmt_time->tm_hour, gmt_time->tm_min, gmt_time->tm_sec, Msg);
  67. // m_pMutex->lock();
  68. m_pMessages->push_back(std::move(temp));
  69. if (m_pMessages->size() > m_nLineNumber)
  70. {
  71. free(*m_pMessages->begin());
  72. m_pMessages->erase(m_pMessages->begin());
  73. };
  74. if (m_hWND != NULL)
  75. {
  76. InvalidateRect(m_hWND, NULL, TRUE);
  77. UpdateWindow(m_hWND);
  78. }
  79. // m_pMutex->unlock();
  80. };
  81. };
  82. }
  83. wchar_t * objectMsOnWindowLoggingService::getWString(int id)
  84. {
  85. if (m_bLogging)
  86. {
  87. if (id < m_pMessages->size())
  88. {
  89. return str2wstr(m_pMessages->at(id));
  90. };
  91. };
  92. return NULL;
  93. }
  94. char * objectMsOnWindowLoggingService::getString(int id)
  95. {
  96. if (m_bLogging)
  97. {
  98. if (id < m_pMessages->size())
  99. {
  100. return m_pMessages->at(id);
  101. };
  102. };
  103. return NULL;
  104. }
  105. void objectMsOnWindowLoggingService::paint(HDC hdc)
  106. {
  107. if (m_bLogging)
  108. {
  109. if (m_pMessages->size() > 0)
  110. {
  111. // m_pMutex->lock();
  112. for (int i = 0; i < m_pMessages->size(); i++)
  113. {
  114. wchar_t * tval;
  115. tval = str2wstr(m_pMessages->at(i));
  116. if (tval != NULL)
  117. {
  118. // TextOut(hdc, m_nX, m_nY + m_nStep * i, L"Test", 4);
  119. free(tval);
  120. };
  121. };
  122. // m_pMutex->unlock();
  123. };
  124. };
  125. }