Skip to main content

pacenotes_installer\ui/
message_box.rs

1const IDYES: i32 = 6;
2
3/// A failure the user must know about.
4pub fn message_box_error(owner: windows_sys::Win32::Foundation::HWND, text: &str) {
5    show(
6        owner,
7        text,
8        windows_sys::Win32::UI::WindowsAndMessaging::MB_OK
9            | windows_sys::Win32::UI::WindowsAndMessaging::MB_ICONERROR,
10    );
11}
12
13/// Something to correct before the wizard can move on.
14pub fn message_box_warning(owner: windows_sys::Win32::Foundation::HWND, text: &str) {
15    show(
16        owner,
17        text,
18        windows_sys::Win32::UI::WindowsAndMessaging::MB_OK
19            | windows_sys::Win32::UI::WindowsAndMessaging::MB_ICONWARNING,
20    );
21}
22
23pub fn message_box_info(owner: windows_sys::Win32::Foundation::HWND, text: &str) {
24    show(
25        owner,
26        text,
27        windows_sys::Win32::UI::WindowsAndMessaging::MB_OK
28            | windows_sys::Win32::UI::WindowsAndMessaging::MB_ICONINFORMATION,
29    );
30}
31
32/// Yes/No; true on Yes.
33pub fn confirm(owner: windows_sys::Win32::Foundation::HWND, text: &str) -> bool {
34    show(
35        owner,
36        text,
37        windows_sys::Win32::UI::WindowsAndMessaging::MB_YESNO
38            | windows_sys::Win32::UI::WindowsAndMessaging::MB_ICONQUESTION,
39    ) == IDYES
40}
41
42/// Yes/No over an error icon, offering a way to act on something that has
43/// already gone wrong; true on Yes.
44pub fn ask_error(owner: windows_sys::Win32::Foundation::HWND, text: &str) -> bool {
45    show(
46        owner,
47        text,
48        windows_sys::Win32::UI::WindowsAndMessaging::MB_YESNO
49            | windows_sys::Win32::UI::WindowsAndMessaging::MB_ICONERROR,
50    ) == IDYES
51}
52
53/// Every box carries the localized application title.
54fn show(owner: windows_sys::Win32::Foundation::HWND, text: &str, style: u32) -> i32 {
55    let body = crate::i18n::to_wide(text);
56    let title = crate::i18n::to_wide(&crate::i18n::load_string(crate::i18n::IDS_APP_TITLE));
57    unsafe {
58        windows_sys::Win32::UI::WindowsAndMessaging::MessageBoxW(
59            owner,
60            body.as_ptr(),
61            title.as_ptr(),
62            style,
63        )
64    }
65}