-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdialog2.hpp
More file actions
142 lines (122 loc) · 3.44 KB
/
Copy pathdialog2.hpp
File metadata and controls
142 lines (122 loc) · 3.44 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#pragma once
namespace my
{
//
// このクラスは変数をバインドできるダイアログです。
//
struct Dialog2 : Dialog
{
struct Prop {
virtual void apply(Dialog* dialog) = 0;
};
template <typename T>
struct Text : Prop {
UINT id; T& value;
Text(Dialog* dialog, UINT id, T& value) : id(id), value(value) {
dialog->set_text(id, value);
}
void apply(Dialog* dialog) override {
value = dialog->get_text(id);
}
};
template <typename T>
struct Int : Prop {
UINT id; T& value;
Int(Dialog* dialog, UINT id, T& value) : id(id), value(value) {
dialog->set_int(id, value);
}
void apply(Dialog* dialog) override {
value = dialog->get_int(id);
}
};
template <typename T>
struct UInt : Prop {
UINT id; T& value;
UInt(Dialog* dialog, UINT id, T& value) : id(id), value(value) {
dialog->set_uint(id, value);
}
void apply(Dialog* dialog) override {
value = dialog->get_uint(id);
}
};
template <typename T>
struct Float : Prop {
UINT id; T& value;
Float(Dialog* dialog, UINT id, T& value, LPCTSTR format) : id(id), value(value) {
dialog->set_float(id, value, format);
}
void apply(Dialog* dialog) override {
value = dialog->get_float(id);
}
};
template <typename T>
struct Check : Prop {
UINT id; T& value;
Check(Dialog* dialog, UINT id, T& value) : id(id), value(value) {
dialog->set_check(id, value);
}
void apply(Dialog* dialog) override {
value = !!dialog->get_check(id);
}
};
template <typename T>
struct ComboBox : Prop {
UINT id; T& value;
ComboBox(Dialog* dialog, UINT id, T& value) : id(id), value(value) {
dialog->set_combobox_index(id, value);
}
template <typename... Tail>
ComboBox(Dialog* dialog, UINT id, T& value, Tail&&... tail) : id(id), value(value) {
dialog->init_combobox(id, std::forward<Tail>(tail)...);
dialog->set_combobox_index(id, value);
}
void apply(Dialog* dialog) override {
value = dialog->get_combobox_index(id);
}
};
std::vector<std::shared_ptr<Prop>> props;
template <typename T>
void bind_text(UINT id, T& value) {
props.emplace_back(std::make_shared<Text<T>>(this, id, value));
};
template <typename T>
void bind_int(UINT id, T& value) {
props.emplace_back(std::make_shared<Int<T>>(this, id, value));
};
template <typename T>
void bind_uint(UINT id, T& value) {
props.emplace_back(std::make_shared<UInt<T>>(this, id, value));
};
template <typename T>
void bind_float(UINT id, T& value, LPCTSTR format) {
props.emplace_back(std::make_shared<Float<T>>(this, id, value, format));
};
template <typename T>
void bind_check(UINT id, T& value) {
props.emplace_back(std::make_shared<Check<T>>(this, id, value));
};
template <typename T>
void bind_combobox_index(UINT id, T& value) {
props.emplace_back(std::make_shared<ComboBox<T>>(this, id, value));
};
template <typename T, typename... Tail>
void bind_combobox_index(UINT id, T& value, LPCTSTR text, Tail&&... tail) {
props.emplace_back(std::make_shared<ComboBox<T>>(this, id, value, text, std::forward<Tail>(tail)...));
};
void apply() {
for (auto& prop : props)
prop->apply(this);
}
int do_modal2(HWND parent)
{
::EnableWindow(parent, FALSE);
int ret_value = __super::do_modal();
::EnableWindow(parent, TRUE);
::SetActiveWindow(parent);
if (IDOK != ret_value)
return ret_value;
apply();
return ret_value;
}
};
}