diff --git a/internal/win/user32.go b/internal/win/user32.go index bfd1369..eb9fb68 100644 --- a/internal/win/user32.go +++ b/internal/win/user32.go @@ -52,6 +52,8 @@ const ( WM_USER = 0x0400 EM_SETSEL = 0x00b1 LB_ADDSTRING = 0x0180 + LB_SETSEL = 0x0185 + LB_SETCURSEL = 0x0186 LB_GETCURSEL = 0x0188 LB_GETSELCOUNT = 0x0190 LB_GETSELITEMS = 0x0191 diff --git a/list.go b/list.go index fd099d2..732d1e5 100644 --- a/list.go +++ b/list.go @@ -52,7 +52,7 @@ const ( radioListKind ) -// DefaultItems returns an Option to set the items to initially select (macOS only). +// DefaultItems returns an Option to set the items to initially select (Windows and macOS only). func DefaultItems(items ...string) Option { return funcOption(func(o *options) { o.defaultItems = items }) } diff --git a/list_windows.go b/list_windows.go index 0023cab..3e2f24b 100644 --- a/list_windows.go +++ b/list_windows.go @@ -107,8 +107,17 @@ func (dlg *listDialog) setup(text string, opts options) ([]string, error) { 12, 206, 75, 24, dlg.wnd, win.IDNO, instance, nil) } - for _, item := range dlg.items { + for i, item := range dlg.items { win.SendMessagePointer(dlg.listCtl, win.LB_ADDSTRING, 0, unsafe.Pointer(strptr(item))) + for _, def := range opts.defaultItems { + if def == item { + if dlg.multiple { + win.SendMessage(dlg.listCtl, win.LB_SETSEL, 1, uintptr(i)) + } else { + win.SendMessage(dlg.listCtl, win.LB_SETCURSEL, uintptr(i), 0) + } + } + } } dlg.layout(getDPI(dlg.wnd))