Skip to main content

pacenotes_installer\wizard\page/
notification.rs

1use windows_sys::Win32::Foundation::{HWND, LPARAM};
2use windows_sys::Win32::UI::Controls as ctl;
3
4/// The first slot of a dialog's extra window memory; windows-sys does not export it.
5const DWLP_MSGRESULT: i32 = 0;
6
7/// The code of an incoming `WM_NOTIFY`.
8pub unsafe fn notify_code(lparam: LPARAM) -> Option<u32> {
9    let header = lparam as *const ctl::NMHDR;
10    header.as_ref().map(|header| header.code)
11}
12
13/// Answers a `PSN_*` notification with `result`.
14pub unsafe fn reply(dialog: HWND, result: isize) -> isize {
15    windows_sys::Win32::UI::WindowsAndMessaging::SetWindowLongPtrW(dialog, DWLP_MSGRESULT, result);
16    1
17}
18
19/// Refuses to leave the page.
20pub unsafe fn stay(dialog: HWND) -> isize {
21    reply(dialog, ctl::PSNRET_INVALID_NOCHANGEPAGE as isize)
22}
23
24/// Cancel asks first; a nonzero reply vetoes the close.
25pub unsafe fn query_cancel(dialog: HWND) -> isize {
26    let confirmed = crate::ui::confirm(
27        dialog,
28        &crate::i18n::load_string(crate::i18n::IDS_CANCEL_CONFIRM),
29    );
30    reply(dialog, isize::from(!confirmed))
31}