blob: b82f382f9b4fbe8daef457907f49fdfc60e94688 (
plain)
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
|
// Adapted from https://github.com/aaronmjacobs/Boxer/blob/master/src/boxer_win.cpp
#include "Dialog.hpp"
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
namespace Dialog {
namespace {
UINT GetIcon(Style style) {
switch (style) {
case Style::Info:
return MB_ICONINFORMATION;
case Style::Warning:
return MB_ICONWARNING;
case Style::Error:
return MB_ICONERROR;
case Style::Question:
return MB_ICONQUESTION;
default:
return MB_ICONINFORMATION;
}
}
UINT GetButtons(Buttons buttons) {
switch (buttons) {
case Buttons::OK:
case Buttons::Quit: // There is no 'Quit' button on Windows :(
return MB_OK;
case Buttons::OKCancel:
return MB_OKCANCEL;
case Buttons::YesNo:
return MB_YESNO;
default:
return MB_OK;
}
}
Selection GetSelection(int response, Buttons buttons) {
switch (response) {
case IDOK:
return buttons == Buttons::Quit ? Selection::Quit : Selection::OK;
case IDCANCEL:
return Selection::Cancel;
case IDYES:
return Selection::Yes;
case IDNO:
return Selection::No;
default:
return Selection::None;
}
}
} // namespace
Selection Show(const char* message, const char* title, Style style, Buttons buttons) {
UINT flags = MB_TASKMODAL;
flags |= GetIcon(style);
flags |= GetButtons(buttons);
return GetSelection(MessageBox(nullptr, message, title, flags), buttons);
}
} // namespace Dialog
|