Added MB_SYSTEMMODAL flag to MessageBox function in the CLogger class.
This commit is contained in:
@@ -28,14 +28,17 @@
|
|||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <strsafe.h>
|
#include <strsafe.h>
|
||||||
|
|
||||||
inline wchar_t* CLogger::GetTimeStamp() {
|
inline wchar_t* CLogger::GetTimeStamp()
|
||||||
|
{
|
||||||
GetLocalTime(<);
|
GetLocalTime(<);
|
||||||
StringCchPrintfW(logTimeBuffer, _countof(logTimeBuffer), L"%d-%02d-%02d %02d:%02d:%02d.%03d | ", lt.wYear, lt.wMonth, lt.wDay, lt.wHour, lt.wMinute, lt.wSecond, lt.wMilliseconds);
|
StringCchPrintfW(logTimeBuffer, _countof(logTimeBuffer), L"%d-%02d-%02d %02d:%02d:%02d.%03d | ", lt.wYear, lt.wMonth, lt.wDay, lt.wHour, lt.wMinute, lt.wSecond, lt.wMilliseconds);
|
||||||
return logTimeBuffer;
|
return logTimeBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLogger::Out(const wchar_t* fmt, ...) {
|
void CLogger::Out(const wchar_t* fmt, ...)
|
||||||
if (fsLogFile.is_open()) {
|
{
|
||||||
|
if (fsLogFile.is_open())
|
||||||
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
EnterCriticalSection(&cs);
|
EnterCriticalSection(&cs);
|
||||||
@@ -46,16 +49,19 @@ void CLogger::Out(const wchar_t* fmt, ...) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CLogger::Init() {
|
void CLogger::Init()
|
||||||
|
{
|
||||||
wchar_t szPath[MAX_PATH] = { 0 };
|
wchar_t szPath[MAX_PATH] = { 0 };
|
||||||
DWORD dwPathLength = GetModuleFileNameW(NULL, szPath, MAX_PATH);
|
DWORD dwPathLength = GetModuleFileNameW(NULL, szPath, MAX_PATH);
|
||||||
DWORD dwError = GetLastError();
|
DWORD dwError = GetLastError();
|
||||||
if (ERROR_INSUFFICIENT_BUFFER == dwError) {
|
if (ERROR_INSUFFICIENT_BUFFER == dwError)
|
||||||
MessageBoxW(NULL, L"Warning!\nPath to log file is too long! Working without logging.", szAppTitle.c_str(), MB_OK | MB_ICONWARNING);
|
{
|
||||||
|
MessageBoxW(NULL, L"Warning!\nPath to log file is too long! Working without logging.", szAppTitle.c_str(), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (NULL == dwPathLength) {
|
if (NULL == dwPathLength)
|
||||||
MessageBoxW(NULL, L"Warning!\nCan't get application's filename! Working without logging.", szAppTitle.c_str(), MB_OK | MB_ICONWARNING);
|
{
|
||||||
|
MessageBoxW(NULL, L"Warning!\nCan't get application's filename! Working without logging.", szAppTitle.c_str(), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,26 +75,31 @@ void CLogger::Init() {
|
|||||||
log_path = L"D:\\test.log";
|
log_path = L"D:\\test.log";
|
||||||
#endif
|
#endif
|
||||||
fsLogFile.open(log_path, std::ios::trunc);
|
fsLogFile.open(log_path, std::ios::trunc);
|
||||||
if (fsLogFile.is_open()) {
|
if (fsLogFile.is_open())
|
||||||
|
{
|
||||||
InitializeCriticalSection(&cs);
|
InitializeCriticalSection(&cs);
|
||||||
fsLogFile << "\xEF\xBB\xBF"; // (0xEF, 0xBB, 0xBF) - UTF-8 BOM
|
fsLogFile << "\xEF\xBB\xBF"; // (0xEF, 0xBB, 0xBF) - UTF-8 BOM
|
||||||
fsLogFile.imbue(std::locale("en-US.utf8"));
|
fsLogFile.imbue(std::locale("en-US.utf8"));
|
||||||
fsLogFile << GetTimeStamp() << "[ " << szAppTitleVer.c_str() << " ] Start log." << std::endl;
|
fsLogFile << GetTimeStamp() << "[ " << szAppTitleVer.c_str() << " ] Start log." << std::endl;
|
||||||
fsLogFile << GetTimeStamp() << "Logfile: \"" << log_path.native() << "\"" << std::endl;
|
fsLogFile << GetTimeStamp() << "Logfile: \"" << log_path.native() << "\"" << std::endl;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
MessageBoxW(NULL, L"Warning!\nCan't create log file! Working without logging.", szAppTitle.c_str(), MB_OK | MB_ICONWARNING);
|
{
|
||||||
|
MessageBoxW(NULL, L"Warning!\nCan't create log file! Working without logging.", szAppTitle.c_str(), MB_OK | MB_ICONWARNING | MB_SYSTEMMODAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CLogger::CLogger(const wchar_t* _appTitle) {
|
CLogger::CLogger(const wchar_t* _appTitle)
|
||||||
|
{
|
||||||
szAppTitle = _appTitle;
|
szAppTitle = _appTitle;
|
||||||
szAppTitleVer = _appTitle;
|
szAppTitleVer = _appTitle;
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
CLogger::~CLogger() {
|
CLogger::~CLogger()
|
||||||
if (fsLogFile) {
|
{
|
||||||
|
if (fsLogFile)
|
||||||
|
{
|
||||||
fsLogFile << GetTimeStamp() << "Stop log." << std::endl;
|
fsLogFile << GetTimeStamp() << "Stop log." << std::endl;
|
||||||
fsLogFile.close();
|
fsLogFile.close();
|
||||||
DeleteCriticalSection(&cs);
|
DeleteCriticalSection(&cs);
|
||||||
|
|||||||
Reference in New Issue
Block a user