SimpleWindow
载入中...
搜索中...
未找到
MsgBox.h
1#pragma once
2
3#include "Delegate.h"
4#include "WndBase.h"
5#include <Windows.h>
6#include <string>
7
8namespace sw
9{
13 using MsgBoxCallback = Action<>;
14
18 enum class MsgBoxButton {
19 AbortRetryIgnore = MB_ABORTRETRYIGNORE,
20 CancelRetryContinue = MB_CANCELTRYCONTINUE,
21 Ok = MB_OK,
22 OkCancel = MB_OKCANCEL,
23 RetryCancel = MB_RETRYCANCEL,
24 YesNo = MB_YESNO,
25 YesNoCancel = MB_YESNOCANCEL,
26 };
27
31 enum class MsgBoxIcon {
32 None = 0,
33 Warning = MB_ICONWARNING,
34 Information = MB_ICONINFORMATION,
35 Question = MB_ICONQUESTION,
36 Error = MB_ICONERROR,
37 };
38
42 enum class MsgBoxResult {
43 Abort = IDABORT,
44 Cancel = IDCANCEL,
45 Continue = IDCONTINUE,
46 Ignore = IDIGNORE,
47 No = IDNO,
48 Ok = IDOK,
49 Retry = IDRETRY,
50 TryAgain = IDTRYAGAIN,
51 Yes = IDYES,
52 };
53
61 MsgBoxResult result;
62
67
71 operator sw::MsgBoxResult() const;
72
77
82
87
92
97
102
107
112
118
122 template <MsgBoxResult RES>
124 {
125 if (this->result == RES) {
126 if (callback) callback();
127 }
128 return *this;
129 }
130 };
131
135 class MsgBox
136 {
137 private:
138 MsgBox() = delete;
139
140 public:
144 static MsgBoxResultHelper Show(const WndBase *owner, const std::wstring &text = L"", const std::wstring &caption = L"", MsgBoxButton button = MsgBoxButton::Ok, MsgBoxIcon icon = MsgBoxIcon::None);
145
149 static MsgBoxResultHelper Show(const WndBase &owner, const std::wstring &text = L"", const std::wstring &caption = L"", MsgBoxButton button = MsgBoxButton::Ok, MsgBoxIcon icon = MsgBoxIcon::None);
150
154 static MsgBoxResultHelper Show(const std::wstring &text = L"", const std::wstring &caption = L"", MsgBoxButton button = MsgBoxButton::Ok, MsgBoxIcon icon = MsgBoxIcon::None);
155
159 static MsgBoxResultHelper ShowInfo(const WndBase *owner, const std::wstring &text = L"", const std::wstring &caption = L"", MsgBoxButton button = MsgBoxButton::Ok);
160
164 static MsgBoxResultHelper ShowInfo(const WndBase &owner, const std::wstring &text = L"", const std::wstring &caption = L"", MsgBoxButton button = MsgBoxButton::Ok);
165
169 static MsgBoxResultHelper ShowInfo(const std::wstring &text = L"", const std::wstring &caption = L"", MsgBoxButton button = MsgBoxButton::Ok);
170
174 static MsgBoxResultHelper ShowError(const WndBase *owner, const std::wstring &text = L"", const std::wstring &caption = L"", MsgBoxButton button = MsgBoxButton::Ok);
175
179 static MsgBoxResultHelper ShowError(const WndBase &owner, const std::wstring &text = L"", const std::wstring &caption = L"", MsgBoxButton button = MsgBoxButton::Ok);
180
184 static MsgBoxResultHelper ShowError(const std::wstring &text = L"", const std::wstring &caption = L"", MsgBoxButton button = MsgBoxButton::Ok);
185
189 static MsgBoxResultHelper ShowWarning(const WndBase *owner, const std::wstring &text = L"", const std::wstring &caption = L"", MsgBoxButton button = MsgBoxButton::Ok);
190
194 static MsgBoxResultHelper ShowWarning(const WndBase &owner, const std::wstring &text = L"", const std::wstring &caption = L"", MsgBoxButton button = MsgBoxButton::Ok);
195
199 static MsgBoxResultHelper ShowWarning(const std::wstring &text = L"", const std::wstring &caption = L"", MsgBoxButton button = MsgBoxButton::Ok);
200
204 static MsgBoxResultHelper ShowQuestion(const WndBase *owner, const std::wstring &text = L"", const std::wstring &caption = L"", MsgBoxButton button = MsgBoxButton::YesNo);
205
209 static MsgBoxResultHelper ShowQuestion(const WndBase &owner, const std::wstring &text = L"", const std::wstring &caption = L"", MsgBoxButton button = MsgBoxButton::YesNo);
210
214 static MsgBoxResultHelper ShowQuestion(const std::wstring &text = L"", const std::wstring &caption = L"", MsgBoxButton button = MsgBoxButton::YesNo);
215 };
216}
Definition Delegate.h:21
消息框类
Definition MsgBox.h:136
static MsgBoxResultHelper ShowQuestion(const std::wstring &text=L"", const std::wstring &caption=L"", MsgBoxButton button=MsgBoxButton::YesNo)
显示一个含“问题”图标的消息框,将当前活动窗体作为Owner
static MsgBoxResultHelper ShowWarning(const WndBase *owner, const std::wstring &text=L"", const std::wstring &caption=L"", MsgBoxButton button=MsgBoxButton::Ok)
显示一个含“警告”图标的消息框
static MsgBoxResultHelper ShowWarning(const WndBase &owner, const std::wstring &text=L"", const std::wstring &caption=L"", MsgBoxButton button=MsgBoxButton::Ok)
显示一个含“警告”图标的消息框
static MsgBoxResultHelper ShowInfo(const WndBase *owner, const std::wstring &text=L"", const std::wstring &caption=L"", MsgBoxButton button=MsgBoxButton::Ok)
显示一个含“消息”图标的消息框
static MsgBoxResultHelper ShowInfo(const WndBase &owner, const std::wstring &text=L"", const std::wstring &caption=L"", MsgBoxButton button=MsgBoxButton::Ok)
显示一个含“消息”图标的消息框
static MsgBoxResultHelper Show(const WndBase &owner, const std::wstring &text=L"", const std::wstring &caption=L"", MsgBoxButton button=MsgBoxButton::Ok, MsgBoxIcon icon=MsgBoxIcon::None)
显示消息框
static MsgBoxResultHelper ShowQuestion(const WndBase *owner, const std::wstring &text=L"", const std::wstring &caption=L"", MsgBoxButton button=MsgBoxButton::YesNo)
显示一个含“问题”图标的消息框
static MsgBoxResultHelper ShowInfo(const std::wstring &text=L"", const std::wstring &caption=L"", MsgBoxButton button=MsgBoxButton::Ok)
显示一个含“消息”图标的消息框,将当前活动窗体作为Owner
static MsgBoxResultHelper ShowError(const WndBase *owner, const std::wstring &text=L"", const std::wstring &caption=L"", MsgBoxButton button=MsgBoxButton::Ok)
显示一个含“错误”图标的消息框
static MsgBoxResultHelper ShowQuestion(const WndBase &owner, const std::wstring &text=L"", const std::wstring &caption=L"", MsgBoxButton button=MsgBoxButton::YesNo)
显示一个含“问题”图标的消息框
static MsgBoxResultHelper Show(const std::wstring &text=L"", const std::wstring &caption=L"", MsgBoxButton button=MsgBoxButton::Ok, MsgBoxIcon icon=MsgBoxIcon::None)
显示消息框,将当前活动窗体作为Owner
static MsgBoxResultHelper ShowWarning(const std::wstring &text=L"", const std::wstring &caption=L"", MsgBoxButton button=MsgBoxButton::Ok)
显示一个含“警告”图标的消息框,将当前活动窗体作为Owner
static MsgBoxResultHelper ShowError(const std::wstring &text=L"", const std::wstring &caption=L"", MsgBoxButton button=MsgBoxButton::Ok)
显示一个含“错误”图标的消息框,将当前活动窗体作为Owner
static MsgBoxResultHelper Show(const WndBase *owner, const std::wstring &text=L"", const std::wstring &caption=L"", MsgBoxButton button=MsgBoxButton::Ok, MsgBoxIcon icon=MsgBoxIcon::None)
显示消息框
static MsgBoxResultHelper ShowError(const WndBase &owner, const std::wstring &text=L"", const std::wstring &caption=L"", MsgBoxButton button=MsgBoxButton::Ok)
显示一个含“错误”图标的消息框
表示一个Windows窗口,是所有窗口和控件的基类
Definition WndBase.h:41
处理消息框消息的帮助类
Definition MsgBox.h:57
MsgBoxResultHelper & OnNo(const MsgBoxCallback &callback)
指定按下“否”按钮时的处理函数
MsgBoxResultHelper & OnTryAgain(const MsgBoxCallback &callback)
指定按下“重试”按钮时的处理函数
MsgBoxResultHelper & OnContinue(const MsgBoxCallback &callback)
指定按下“继续”按钮时的处理函数
MsgBoxResultHelper & OnYes(const MsgBoxCallback &callback)
指定按下“是”按钮时的处理函数
MsgBoxResultHelper & OnAbort(const MsgBoxCallback &callback)
指定按下“中止”按钮时的处理函数
MsgBoxResult result
消息框的结果
Definition MsgBox.h:61
MsgBoxResultHelper & OnRetry(const MsgBoxCallback &callback)
指定按下“重试”按钮时的处理函数
MsgBoxResultHelper & OnCancel(const MsgBoxCallback &callback)
指定按下“取消”按钮时的处理函数
MsgBoxResultHelper & OnIgnore(const MsgBoxCallback &callback)
指定按下“忽略”按钮时的处理函数
MsgBoxResultHelper & OnOk(const MsgBoxCallback &callback)
指定按下“确定”按钮时的处理函数
MsgBoxResultHelper & On(const MsgBoxCallback &callback)
指定消息框结果的处理函数
Definition MsgBox.h:123
MsgBoxResultHelper(MsgBoxResult result)
构造MsgBoxResultHelper