Skip to main content

pacenotes_installer\ui/
combo_box.rs

1const CB_ADDSTRING: u32 = 0x0143;
2const CB_SETCURSEL: u32 = 0x014E;
3const CB_GETCURSEL: u32 = 0x0147;
4const CB_RESETCONTENT: u32 = 0x014B;
5
6pub unsafe fn combo_reset(dialog: windows_sys::Win32::Foundation::HWND, control: u16) {
7    windows_sys::Win32::UI::WindowsAndMessaging::SendDlgItemMessageW(
8        dialog,
9        control as i32,
10        CB_RESETCONTENT,
11        0,
12        0,
13    );
14}
15
16pub unsafe fn combo_add(dialog: windows_sys::Win32::Foundation::HWND, control: u16, text: &str) {
17    let wide = crate::i18n::to_wide(text);
18    windows_sys::Win32::UI::WindowsAndMessaging::SendDlgItemMessageW(
19        dialog,
20        control as i32,
21        CB_ADDSTRING,
22        0,
23        wide.as_ptr() as windows_sys::Win32::Foundation::LPARAM,
24    );
25}
26
27pub unsafe fn combo_select(
28    dialog: windows_sys::Win32::Foundation::HWND,
29    control: u16,
30    index: usize,
31) {
32    windows_sys::Win32::UI::WindowsAndMessaging::SendDlgItemMessageW(
33        dialog,
34        control as i32,
35        CB_SETCURSEL,
36        index,
37        0,
38    );
39}
40
41/// `None` when nothing is selected.
42pub unsafe fn combo_selection(
43    dialog: windows_sys::Win32::Foundation::HWND,
44    control: u16,
45) -> Option<usize> {
46    let selection = windows_sys::Win32::UI::WindowsAndMessaging::SendDlgItemMessageW(
47        dialog,
48        control as i32,
49        CB_GETCURSEL,
50        0,
51        0,
52    );
53    usize::try_from(selection).ok()
54}