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.

106 lines
2.7 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. #include "objectMsOnWindowLoggingService.h"
  2. CSTR wstr2str(wchar_t *wideStr){
  3. CSTR resultStr;
  4. resultStr = (CSTR)malloc(wcslen(wideStr) + 1);
  5. if (resultStr!= NULL) wsprintfA(resultStr, "%S", wideStr);
  6. return resultStr;
  7. };
  8. wchar_t *str2wstr(CSTR Str){
  9. wchar_t *resultStr;
  10. resultStr = (wchar_t *)malloc((strlen(Str) + 1) << 1);
  11. if (resultStr!=NULL) wsprintfW(resultStr, L"%s", Str);
  12. return resultStr;
  13. };
  14. objectMsOnWindowLoggingService::objectMsOnWindowLoggingService(size_t Lines, vectorCSTR *VCT, HWND wnd) : basicLoggingService(){
  15. m_nLineNumber = Lines;
  16. //m_pMutex = new basicMutex();
  17. m_hWND = wnd;
  18. m_pMessages = VCT;
  19. m_pMessages->clear();
  20. m_bLogging = true;
  21. };
  22. objectMsOnWindowLoggingService::~objectMsOnWindowLoggingService(){
  23. if (m_bLogging){
  24. m_bLogging = false;
  25. if (m_pMessages->size() > 0){
  26. //m_pMutex->lock();
  27. while (m_pMessages->size()){
  28. delete((LPWSTR)*m_pMessages->begin());
  29. m_pMessages->erase(m_pMessages->begin());
  30. };
  31. //m_pMutex->unlock();
  32. };
  33. };
  34. //if (m_pMutex) delete(m_pMutex);
  35. };
  36. void objectMsOnWindowLoggingService::logMessage( CSTR Msg ){
  37. logMessage( (const char *)Msg );
  38. };
  39. void objectMsOnWindowLoggingService::logMessage( const char *Msg ){
  40. if ( m_bLogging ){
  41. time_t LocalTime;
  42. tm *gmt_time;
  43. time( &LocalTime );
  44. gmt_time = gmtime( &LocalTime );
  45. CSTR temp;
  46. temp = (CSTR)malloc(CLOG);
  47. if (temp != NULL){
  48. 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);
  49. //m_pMutex->lock();
  50. m_pMessages->push_back(std::move(temp));
  51. if (m_pMessages->size() > m_nLineNumber){
  52. free(*m_pMessages->begin());
  53. m_pMessages->erase(m_pMessages->begin());
  54. };
  55. if (m_hWND != NULL){
  56. InvalidateRect(m_hWND, NULL, TRUE);
  57. UpdateWindow(m_hWND);
  58. }
  59. //m_pMutex->unlock();
  60. };
  61. };
  62. };
  63. wchar_t *objectMsOnWindowLoggingService::getWString(int id){
  64. if (m_bLogging){
  65. if (id < m_pMessages->size()){
  66. return str2wstr(m_pMessages->at(id));
  67. };
  68. };
  69. return NULL;
  70. };
  71. char *objectMsOnWindowLoggingService::getString(int id){
  72. if (m_bLogging){
  73. if (id < m_pMessages->size()){
  74. return m_pMessages->at(id);
  75. };
  76. };
  77. return NULL;
  78. };
  79. void objectMsOnWindowLoggingService::paint(HDC hdc){
  80. if (m_bLogging){
  81. if (m_pMessages->size() > 0){
  82. //m_pMutex->lock();
  83. for (int i = 0; i < m_pMessages->size(); i++){
  84. wchar_t *tval;
  85. tval = str2wstr(m_pMessages->at(i));
  86. if (tval != NULL){
  87. //TextOut(hdc, m_nX, m_nY + m_nStep * i, L"Test", 4);
  88. free(tval);
  89. };
  90. };
  91. //m_pMutex->unlock();
  92. };
  93. };
  94. };