HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
winuser.hpp
1// Copyright Take Vos 2023.
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#include "../macros.hpp"
9#include "win32_error_intf.hpp"
10#include <expected>
11#include <string>
12#include <string_view>
13#include <system_error>
14
15hi_export_module(hikogui.win32 : winuser);
16
17namespace hi { inline namespace v1 {
18
19inline std::expected<UINT, win32_error> win32_MessageBox(HWND handle, std::string_view text, std::string_view caption, UINT type) noexcept
20{
21 auto const wtext = win32_MultiByteToWideChar(text);
22 if (not wtext) {
23 return std::unexpected{wtext.error()};
24 }
25
26 auto const wcaption = win32_MultiByteToWideChar(caption);
27 if (not wcaption) {
28 return std::unexpected{wcaption.error()};
29 }
30
31 auto const r = MessageBoxW(handle, wtext->c_str(), wcaption->c_str(), type);
32 if (r == 0) {
33 return std::unexpected{win32_GetLastError()};
34 }
35
36 return r;
37}
38
39}}
Rules for working with win32 headers.
The HikoGUI namespace.
Definition array_generic.hpp:20
std::expected< std::wstring, win32_error > win32_MultiByteToWideChar(std::string_view s, unsigned int code_page=CP_UTF8, uint32_t flags=0) noexcept
Convert a win32-API compatible std::wstring to a multi-byte std::string.
Definition stringapiset.hpp:58
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
T unexpected(T... args)