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.
|
|
#include "objectMsOnWindowLoggingService.h"
CSTR wstr2str(wchar_t *wideStr){ CSTR resultStr; resultStr = (CSTR)malloc(wcslen(wideStr) + 1); if (resultStr!= NULL) wsprintfA(resultStr, "%S", wideStr); return resultStr;};
wchar_t *str2wstr(CSTR Str){ wchar_t *resultStr; resultStr = (wchar_t *)malloc((strlen(Str) + 1) << 1); if (resultStr!=NULL) wsprintfW(resultStr, L"%s", Str); return resultStr;};
objectMsOnWindowLoggingService::objectMsOnWindowLoggingService(size_t Lines, vectorCSTR *VCT, HWND wnd) : basicLoggingService(){ m_nLineNumber = Lines; //m_pMutex = new basicMutex();
m_hWND = wnd; m_pMessages = VCT; m_pMessages->clear(); m_bLogging = true;};
objectMsOnWindowLoggingService::~objectMsOnWindowLoggingService(){ if (m_bLogging){ m_bLogging = false; if (m_pMessages->size() > 0){ //m_pMutex->lock();
while (m_pMessages->size()){ delete((LPWSTR)*m_pMessages->begin()); m_pMessages->erase(m_pMessages->begin()); }; //m_pMutex->unlock();
}; }; //if (m_pMutex) delete(m_pMutex);
};
void objectMsOnWindowLoggingService::logMessage( CSTR Msg ){ logMessage( (const char *)Msg );};
void objectMsOnWindowLoggingService::logMessage( const char *Msg ){ if ( m_bLogging ){ time_t LocalTime; tm *gmt_time; time( &LocalTime ); gmt_time = gmtime( &LocalTime ); CSTR temp; temp = (CSTR)malloc(CLOG); if (temp != NULL){ 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); //m_pMutex->lock();
m_pMessages->push_back(std::move(temp)); if (m_pMessages->size() > m_nLineNumber){ free(*m_pMessages->begin()); m_pMessages->erase(m_pMessages->begin()); }; if (m_hWND != NULL){ InvalidateRect(m_hWND, NULL, TRUE); UpdateWindow(m_hWND); } //m_pMutex->unlock();
}; };};
wchar_t *objectMsOnWindowLoggingService::getWString(int id){ if (m_bLogging){ if (id < m_pMessages->size()){ return str2wstr(m_pMessages->at(id)); }; }; return NULL;};
char *objectMsOnWindowLoggingService::getString(int id){ if (m_bLogging){ if (id < m_pMessages->size()){ return m_pMessages->at(id); }; }; return NULL;};
void objectMsOnWindowLoggingService::paint(HDC hdc){ if (m_bLogging){ if (m_pMessages->size() > 0){ //m_pMutex->lock();
for (int i = 0; i < m_pMessages->size(); i++){ wchar_t *tval; tval = str2wstr(m_pMessages->at(i)); if (tval != NULL){ //TextOut(hdc, m_nX, m_nY + m_nStep * i, L"Test", 4);
free(tval); }; }; //m_pMutex->unlock();
}; };};
|