-
Notifications
You must be signed in to change notification settings - Fork 534
/
Message.hpp
70 lines (60 loc) · 1.72 KB
/
Message.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#pragma once
#include "stdafx.h"
#include "Log.h"
class Message
{
enum MsgType
{
Error,
Warning,
Info,
Question,
};
public:
static void ShowError( HWND parent, const std::wstring& msg, const std::wstring& title = L"Error" )
{
Show( msg, title, Error, parent );
}
static void ShowWarning( HWND parent, const std::wstring& msg, const std::wstring& title = L"Warning" )
{
Show( msg, title, Warning, parent );
}
static void ShowInfo( HWND parent, const std::wstring& msg, const std::wstring& title = L"Info" )
{
Show( msg, title, Info, parent );
}
static bool ShowQuestion( HWND parent, const std::wstring& msg, const std::wstring& title = L"Question" )
{
return Show( msg, title, Question, parent ) == IDYES;
}
private:
static int Show(
const std::wstring& msg,
const std::wstring& title,
MsgType type,
HWND parent = NULL
)
{
UINT uType = MB_ICONERROR;
xlog::LogLevel::e logLevel = xlog::LogLevel::error;
if (type == Warning)
{
uType = MB_ICONWARNING;
logLevel = xlog::LogLevel::warning;
}
else if (type == Info)
{
uType = MB_ICONINFORMATION;
logLevel = xlog::LogLevel::normal;
}
else if (type == Question)
{
uType = MB_YESNO | MB_ICONQUESTION;
logLevel = xlog::LogLevel::verbose;
}
// Write to log
if (logLevel < xlog::LogLevel::verbose)
xlog::Logger::Instance().DoLog( logLevel, "%ls", msg.c_str() );
return MessageBoxW( parent, msg.c_str(), title.c_str(), uType );
}
};