Debian Codegraph @

common/arch/win32/messagebox.cpp

raw
1 /*
2 * This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
3 * It is copyright by its individual contributors, as recorded in the
4 * project's Git history. See COPYING.txt at the top level for license
5 * terms and a link to the Git history.
6 */
7 /*
8 * messagebox.c
9 * d1x-rebirth
10 *
11 * Display an error or warning messagebox using the OS's window server.
12 *
13 */
14
15 #include <windows.h>
16 #include "window.h"
17 #include "event.h"
18 #include "messagebox.h"
19
20 namespace dcx {
21
22 static void display_win32_alert(const char *message, int error)
23 {
24 // Handle Descent's windows properly
25 if (const auto wind = window_get_front())
26 wind->send_event(d_event{event_type::window_deactivated});
27
28 int fullscreen = (grd_curscreen && gr_check_fullscreen());
29 if (fullscreen)
30 gr_toggle_fullscreen();
31
32 MessageBox(NULL, message, error?"Sorry, a critical error has occurred.":"Attention!", error?MB_OK|MB_ICONERROR:MB_OK|MB_ICONWARNING);
33
34 if (const auto wind = window_get_front())
35 wind->send_event(d_event{event_type::window_activated});
36 if (!error && fullscreen)
37 gr_toggle_fullscreen();
38 }
39
40 void msgbox_warning(const std::span<const char> message)
41 {
42 display_win32_alert(message.data(), 0);
43 }
44
45 void msgbox_error(const char *message)
46 {
47 display_win32_alert(message, 1);
48 }
49
50 }