HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
dialog_win32_impl.hpp
1// Copyright Take Vos 2021-2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
8
9#include "dialog_intf.hpp"
10#include "../utility/utility.hpp"
11#include "../char_maps/module.hpp"
12#include "../macros.hpp"
13
14hi_export_module(hikogui.console.dialog : impl);
15
16namespace hi { inline namespace v1 {
17
18hi_export inline bool dialog(dialog_type type, std::string_view title, std::string_view text)
19{
20 UINT type_;
21
22 switch (type) {
23 case dialog_type::ok:
24 // Just "ok" can only be a notification, so it must be an error as well.
26 break;
27 case dialog_type::yes_no:
28 // Just "yes" / "no" is serious, so exclamation.
30 break;
31
32 case dialog_type::yes_no_cancel:
33 // If we can cancel it must be a warning.
35 break;
36
37 default: hi_no_default();
38 }
39
40 hilet title_ = hi::to_wstring(title);
41 hilet text_ = hi::to_wstring(text);
42 hilet r = MessageBoxW(nullptr, text_.c_str(), title_.c_str(), type_);
43
44 switch (r) {
45 case IDABORT:
46 case IDCANCEL: throw cancel_error("User pressed cancel");
47 case IDCONTINUE:
48 case IDOK:
49 case IDYES: return true;
50 case IDNO: return false;
51 default: hi_no_default();
52 }
53}
54
55}} // namespace hi::inline v1
Rules for working with win32 headers.
constexpr std::wstring to_wstring(std::u32string_view rhs) noexcept
Conversion from UTF-32 to wide-string (UTF-16/32).
Definition to_string.hpp:156
DOXYGEN BUG.
Definition algorithm.hpp:16
geometry/margins.hpp
Definition lookahead_iterator.hpp:5
hi_export bool dialog(dialog_type type, std::string_view title, std::string_view text)
Display a modal dialog.
Definition dialog_win32_impl.hpp:18
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
Cancel error is caused by user pressing cancel.
Definition exception_intf.hpp:217