Calendar (windows).

This commit is contained in:
Nuno Cruces 2022-03-29 03:05:46 +01:00
parent 74cdc9ad9e
commit f47c02b6d1
13 changed files with 452 additions and 179 deletions

View File

@ -19,6 +19,12 @@ func init() {
}
}
const (
_CC_RGBINIT = 0x00000001
_CC_FULLOPEN = 0x00000002
_CC_PREVENTFULLOPEN = 0x00000004
)
func selectColor(opts options) (color.Color, error) {
// load custom colors
colorsMutex.Lock()
@ -30,14 +36,14 @@ func selectColor(opts options) (color.Color, error) {
args.CustColors = &customColors
if opts.color != nil {
args.Flags |= 0x1 // CC_RGBINIT
args.Flags |= _CC_RGBINIT
n := color.NRGBAModel.Convert(opts.color).(color.NRGBA)
args.RgbResult = uint32(n.R) | uint32(n.G)<<8 | uint32(n.B)<<16
}
if opts.showPalette {
args.Flags |= 0x4 // CC_PREVENTFULLOPEN
args.Flags |= _CC_PREVENTFULLOPEN
} else {
args.Flags |= 0x2 // CC_FULLOPEN
args.Flags |= _CC_FULLOPEN
}
defer setup()()

82
const_windows.go Normal file
View File

@ -0,0 +1,82 @@
package zenity
const (
_CW_USEDEFAULT = 0x80000000
_WS_TABSTOP = 0x00010000
_WS_GROUP = 0x00020000
_WS_SYSMENU = 0x00080000
_WS_VSCROLL = 0x00200000
_WS_DLGFRAME = 0x00400000
_WS_BORDER = 0x00800000
_WS_CLIPSIBLINGS = 0x04000000
_WS_DISABLED = 0x08000000
_WS_VISIBLE = 0x10000000
_WS_CHILD = 0x40000000
_WS_POPUP = 0x80000000
_WS_POPUPWINDOW = _WS_POPUP | _WS_BORDER | _WS_SYSMENU
_WS_EX_DLGMODALFRAME = 0x00000001
_WS_EX_WINDOWEDGE = 0x00000100
_WS_EX_CLIENTEDGE = 0x00000200
_WS_EX_CONTROLPARENT = 0x00010000
_BS_DEFPUSHBUTTON = 0x0001
_ES_AUTOHSCROLL = 0x0080
_ES_PASSWORD = 0x0020
_SS_NOPREFIX = 0x0080
_SS_EDITCONTROL = 0x2000
_SS_WORDELLIPSIS = 0xc000
_LBS_EXTENDEDSEL = 0x0800
_MCS_NOTODAY = 0x0010
_PBS_SMOOTH = 0x0001
_PBS_MARQUEE = 0x0008
_SW_NORMAL = 1
_SWP_NOMOVE = 0x0002
_SWP_NOZORDER = 0x0004
_MB_OKCANCEL = 0x00000001
_MB_YESNOCANCEL = 0x00000003
_MB_YESNO = 0x00000004
_MB_ICONERROR = 0x00000010
_MB_ICONQUESTION = 0x00000020
_MB_ICONWARNING = 0x00000030
_MB_ICONINFORMATION = 0x00000040
_MB_DEFBUTTON1 = 0x00000000
_MB_DEFBUTTON2 = 0x00000100
_MB_DEFBUTTON3 = 0x00000200
_IDOK = 1
_IDCANCEL = 2
_IDYES = 6
_IDNO = 7
_SC_CLOSE = 0xf060
_WM_DESTROY = 0x0002
_WM_CLOSE = 0x0010
_WM_SETFONT = 0x0030
_WM_NCCREATE = 0x0081
_WM_NCDESTROY = 0x0082
_WM_COMMAND = 0x0111
_WM_SYSCOMMAND = 0x0112
_WM_DPICHANGED = 0x02e0
_WM_USER = 0x0400
_EM_SETSEL = 0x00b1
_LB_ADDSTRING = 0x0180
_LB_GETCURSEL = 0x0188
_LB_GETSELCOUNT = 0x0190
_LB_GETSELITEMS = 0x0191
_MCM_GETCURSEL = 0x1001
_MCM_SETCURSEL = 0x1002
_PBM_SETPOS = _WM_USER + 2
_PBM_SETRANGE32 = _WM_USER + 6
_PBM_SETMARQUEE = _WM_USER + 10
_GWL_STYLE = -16
_PROGRESS_CLASS = "msctls_progress32"
_MONTHCAL_CLASS = "SysMonthCal32"
)

View File

@ -17,6 +17,7 @@ func Calendar(text string, options ...Option) (time.Time, error) {
// DefaultDate returns an Option to set the date.
func DefaultDate(year int, month time.Month, day int) Option {
return funcOption(func(o *options) {
o.year, o.month, o.day = &year, month, day
t := time.Date(year, month, day, 0, 0, 0, 0, time.UTC)
o.time = &t
})
}

View File

@ -9,19 +9,11 @@ import (
func calendar(text string, opts options) (time.Time, error) {
var date zenutil.Date
year, month, day := time.Now().Date()
if time.January <= opts.month && opts.month <= time.December {
month = opts.month
}
if 1 <= opts.day && opts.day <= 31 {
day = opts.day
}
if opts.year != nil {
year = *opts.year
}
date.Date = time.Date(year, month, day, 0, 0, 0, 0, time.UTC).Unix()
date.OK, date.Cancel, date.Extra = getAlertButtons(opts)
date.Format = "yyyy-MM-dd"
if opts.time != nil {
date.Date = opts.time.Unix()
}
if opts.title != nil {
date.Text = *opts.title

View File

@ -15,14 +15,11 @@ func calendar(text string, opts options) (time.Time, error) {
args = appendButtons(args, opts)
args = appendWidthHeight(args, opts)
args = appendIcon(args, opts)
if time.January <= opts.month && opts.month <= time.December {
args = append(args, "--month", strconv.Itoa(int(opts.month)))
}
if 1 <= opts.day && opts.day <= 31 {
args = append(args, "--day", strconv.Itoa(opts.day))
}
if opts.year != nil {
args = append(args, "--year", strconv.Itoa(*opts.year))
if opts.time != nil {
year, month, day := opts.time.Date()
args = append(args, "--month", strconv.Itoa(int(month)))
args = append(args, "--day", strconv.Itoa(day))
args = append(args, "--year", strconv.Itoa(year))
}
out, err := zenutil.Run(opts.ctx, args)

188
date_windows.go Normal file
View File

@ -0,0 +1,188 @@
package zenity
import (
"syscall"
"time"
"unsafe"
)
func calendar(text string, opts options) (time.Time, error) {
if opts.title == nil {
opts.title = stringPtr("")
}
if opts.okLabel == nil {
opts.okLabel = stringPtr("OK")
}
if opts.cancelLabel == nil {
opts.cancelLabel = stringPtr("Cancel")
}
dlg := &calendarDialog{}
return dlg.setup(text, opts)
}
type calendarDialog struct {
out time.Time
err error
wnd uintptr
textCtl uintptr
dateCtl uintptr
okBtn uintptr
cancelBtn uintptr
extraBtn uintptr
font font
}
func (dlg *calendarDialog) setup(text string, opts options) (time.Time, error) {
defer setup()()
dlg.font = getFont()
defer dlg.font.delete()
if opts.ctx != nil && opts.ctx.Err() != nil {
return time.Time{}, opts.ctx.Err()
}
instance, _, err := getModuleHandle.Call(0)
if instance == 0 {
return time.Time{}, err
}
cls, err := registerClass(instance, syscall.NewCallback(calendarProc))
if cls == 0 {
return time.Time{}, err
}
defer unregisterClass.Call(cls, instance)
dlg.wnd, _, _ = createWindowEx.Call(_WS_EX_CONTROLPARENT|_WS_EX_WINDOWEDGE|_WS_EX_DLGMODALFRAME,
cls, strptr(*opts.title),
_WS_POPUPWINDOW|_WS_CLIPSIBLINGS|_WS_DLGFRAME,
_CW_USEDEFAULT, _CW_USEDEFAULT,
281, 281, 0, 0, instance, uintptr(unsafe.Pointer(dlg)))
dlg.textCtl, _, _ = createWindowEx.Call(0,
strptr("STATIC"), strptr(text),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_SS_WORDELLIPSIS|_SS_EDITCONTROL|_SS_NOPREFIX,
12, 10, 241, 16, dlg.wnd, 0, instance, 0)
var flags uintptr = _WS_CHILD | _WS_VISIBLE | _WS_GROUP | _WS_TABSTOP | _MCS_NOTODAY
dlg.dateCtl, _, _ = createWindowEx.Call(0,
strptr(_MONTHCAL_CLASS),
0, flags,
12, 30, 241, 164, dlg.wnd, 0, instance, 0)
dlg.okBtn, _, _ = createWindowEx.Call(0,
strptr("BUTTON"), strptr(*opts.okLabel),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP|_BS_DEFPUSHBUTTON,
12, 206, 75, 24, dlg.wnd, _IDOK, instance, 0)
dlg.cancelBtn, _, _ = createWindowEx.Call(0,
strptr("BUTTON"), strptr(*opts.cancelLabel),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP,
12, 206, 75, 24, dlg.wnd, _IDCANCEL, instance, 0)
if opts.extraButton != nil {
dlg.extraBtn, _, _ = createWindowEx.Call(0,
strptr("BUTTON"), strptr(*opts.extraButton),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP,
12, 206, 75, 24, dlg.wnd, _IDNO, instance, 0)
}
if opts.time != nil {
var date _SYSTEMTIME
year, month, day := opts.time.Date()
date.year = uint16(year)
date.month = uint16(month)
date.day = uint16(day)
sendMessage.Call(dlg.dateCtl, _MCM_SETCURSEL, 0, uintptr(unsafe.Pointer(&date)))
}
dlg.layout(getDPI(dlg.wnd))
centerWindow(dlg.wnd)
setFocus.Call(dlg.dateCtl)
showWindow.Call(dlg.wnd, _SW_NORMAL, 0)
if opts.ctx != nil {
wait := make(chan struct{})
defer close(wait)
go func() {
select {
case <-opts.ctx.Done():
sendMessage.Call(dlg.wnd, _WM_SYSCOMMAND, _SC_CLOSE, 0)
case <-wait:
}
}()
}
if err := messageLoop(dlg.wnd); err != nil {
return time.Time{}, err
}
if opts.ctx != nil && opts.ctx.Err() != nil {
return time.Time{}, opts.ctx.Err()
}
return dlg.out, dlg.err
}
func (dlg *calendarDialog) layout(dpi dpi) {
font := dlg.font.forDPI(dpi)
sendMessage.Call(dlg.textCtl, _WM_SETFONT, font, 1)
sendMessage.Call(dlg.dateCtl, _WM_SETFONT, font, 1)
sendMessage.Call(dlg.okBtn, _WM_SETFONT, font, 1)
sendMessage.Call(dlg.cancelBtn, _WM_SETFONT, font, 1)
sendMessage.Call(dlg.extraBtn, _WM_SETFONT, font, 1)
setWindowPos.Call(dlg.wnd, 0, 0, 0, dpi.scale(281), dpi.scale(281), _SWP_NOZORDER|_SWP_NOMOVE)
setWindowPos.Call(dlg.textCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), _SWP_NOZORDER)
setWindowPos.Call(dlg.dateCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(164), _SWP_NOZORDER)
if dlg.extraBtn == 0 {
setWindowPos.Call(dlg.okBtn, 0, dpi.scale(95), dpi.scale(206), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
setWindowPos.Call(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(206), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
} else {
setWindowPos.Call(dlg.okBtn, 0, dpi.scale(12), dpi.scale(206), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
setWindowPos.Call(dlg.extraBtn, 0, dpi.scale(95), dpi.scale(206), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
setWindowPos.Call(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(206), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
}
}
func calendarProc(wnd uintptr, msg uint32, wparam uintptr, lparam *unsafe.Pointer) uintptr {
var dlg *calendarDialog
switch msg {
case _WM_NCCREATE:
saveBackRef(wnd, *lparam)
dlg = (*calendarDialog)(*lparam)
case _WM_NCDESTROY:
deleteBackRef(wnd)
default:
dlg = (*calendarDialog)(loadBackRef(wnd))
}
switch msg {
case _WM_DESTROY:
postQuitMessage.Call(0)
case _WM_CLOSE:
dlg.err = ErrCanceled
destroyWindow.Call(wnd)
case _WM_COMMAND:
switch wparam {
default:
return 1
case _IDOK, _IDYES:
var date _SYSTEMTIME
sendMessage.Call(dlg.dateCtl, _MCM_GETCURSEL, 0, uintptr(unsafe.Pointer(&date)))
dlg.out = time.Date(int(date.year), time.Month(date.month), int(date.day), 0, 0, 0, 0, time.UTC)
case _IDCANCEL:
dlg.err = ErrCanceled
case _IDNO:
dlg.err = ErrExtraButton
}
destroyWindow.Call(wnd)
case _WM_DPICHANGED:
dlg.layout(dpi(uint32(wparam) >> 16))
default:
res, _, _ := defWindowProc.Call(wnd, uintptr(msg), wparam, uintptr(unsafe.Pointer(lparam)))
return res
}
return 0
}

View File

@ -53,47 +53,46 @@ func (dlg *entryDialog) setup(text string, opts options) (string, error) {
}
defer unregisterClass.Call(cls, instance)
dlg.wnd, _, _ = createWindowEx.Call(0x10101, // WS_EX_CONTROLPARENT|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME
dlg.wnd, _, _ = createWindowEx.Call(_WS_EX_CONTROLPARENT|_WS_EX_WINDOWEDGE|_WS_EX_DLGMODALFRAME,
cls, strptr(*opts.title),
0x84c80000, // WS_POPUPWINDOW|WS_CLIPSIBLINGS|WS_DLGFRAME
0x80000000, // CW_USEDEFAULT
0x80000000, // CW_USEDEFAULT
_WS_POPUPWINDOW|_WS_CLIPSIBLINGS|_WS_DLGFRAME,
_CW_USEDEFAULT, _CW_USEDEFAULT,
281, 141, 0, 0, instance, uintptr(unsafe.Pointer(dlg)))
dlg.textCtl, _, _ = createWindowEx.Call(0,
strptr("STATIC"), strptr(text),
0x5002e080, // WS_CHILD|WS_VISIBLE|WS_GROUP|SS_WORDELLIPSIS|SS_EDITCONTROL|SS_NOPREFIX
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_SS_WORDELLIPSIS|_SS_EDITCONTROL|_SS_NOPREFIX,
12, 10, 241, 16, dlg.wnd, 0, instance, 0)
var flags uintptr = 0x50030080 // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP|ES_AUTOHSCROLL
var flags uintptr = _WS_CHILD | _WS_VISIBLE | _WS_GROUP | _WS_TABSTOP | _ES_AUTOHSCROLL
if opts.hideText {
flags |= 0x20 // ES_PASSWORD
flags |= _ES_PASSWORD
}
dlg.editCtl, _, _ = createWindowEx.Call(0x200, // WS_EX_CLIENTEDGE
dlg.editCtl, _, _ = createWindowEx.Call(_WS_EX_CLIENTEDGE,
strptr("EDIT"), strptr(opts.entryText),
flags,
12, 30, 241, 24, dlg.wnd, 0, instance, 0)
dlg.okBtn, _, _ = createWindowEx.Call(0,
strptr("BUTTON"), strptr(*opts.okLabel),
0x50030001, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP|BS_DEFPUSHBUTTON
12, 66, 75, 24, dlg.wnd, 1 /* IDOK */, instance, 0)
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP|_BS_DEFPUSHBUTTON,
12, 66, 75, 24, dlg.wnd, _IDOK, instance, 0)
dlg.cancelBtn, _, _ = createWindowEx.Call(0,
strptr("BUTTON"), strptr(*opts.cancelLabel),
0x50010000, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP
12, 66, 75, 24, dlg.wnd, 2 /* IDCANCEL */, instance, 0)
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP,
12, 66, 75, 24, dlg.wnd, _IDCANCEL, instance, 0)
if opts.extraButton != nil {
dlg.extraBtn, _, _ = createWindowEx.Call(0,
strptr("BUTTON"), strptr(*opts.extraButton),
0x50010000, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP
12, 66, 75, 24, dlg.wnd, 7 /* IDNO */, instance, 0)
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP,
12, 66, 75, 24, dlg.wnd, _IDNO, instance, 0)
}
dlg.layout(getDPI(dlg.wnd))
centerWindow(dlg.wnd)
setFocus.Call(dlg.editCtl)
showWindow.Call(dlg.wnd, 1 /* SW_SHOWNORMAL */, 0)
sendMessage.Call(dlg.editCtl, 0xb1 /* EM_SETSEL */, 0, intptr(-1))
showWindow.Call(dlg.wnd, _SW_NORMAL, 0)
sendMessage.Call(dlg.editCtl, _EM_SETSEL, 0, intptr(-1))
if opts.ctx != nil {
wait := make(chan struct{})
@ -101,7 +100,7 @@ func (dlg *entryDialog) setup(text string, opts options) (string, error) {
go func() {
select {
case <-opts.ctx.Done():
sendMessage.Call(dlg.wnd, 0x0112 /* WM_SYSCOMMAND */, 0xf060 /* SC_CLOSE */, 0)
sendMessage.Call(dlg.wnd, _WM_SYSCOMMAND, _SC_CLOSE, 0)
case <-wait:
}
}()
@ -118,58 +117,58 @@ func (dlg *entryDialog) setup(text string, opts options) (string, error) {
func (dlg *entryDialog) layout(dpi dpi) {
font := dlg.font.forDPI(dpi)
sendMessage.Call(dlg.textCtl, 0x0030 /* WM_SETFONT */, font, 1)
sendMessage.Call(dlg.editCtl, 0x0030 /* WM_SETFONT */, font, 1)
sendMessage.Call(dlg.okBtn, 0x0030 /* WM_SETFONT */, font, 1)
sendMessage.Call(dlg.cancelBtn, 0x0030 /* WM_SETFONT */, font, 1)
sendMessage.Call(dlg.extraBtn, 0x0030 /* WM_SETFONT */, font, 1)
setWindowPos.Call(dlg.wnd, 0, 0, 0, dpi.scale(281), dpi.scale(141), 0x6) // SWP_NOZORDER|SWP_NOMOVE
setWindowPos.Call(dlg.textCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), 0x4) // SWP_NOZORDER
setWindowPos.Call(dlg.editCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(24), 0x4) // SWP_NOZORDER
sendMessage.Call(dlg.textCtl, _WM_SETFONT, font, 1)
sendMessage.Call(dlg.editCtl, _WM_SETFONT, font, 1)
sendMessage.Call(dlg.okBtn, _WM_SETFONT, font, 1)
sendMessage.Call(dlg.cancelBtn, _WM_SETFONT, font, 1)
sendMessage.Call(dlg.extraBtn, _WM_SETFONT, font, 1)
setWindowPos.Call(dlg.wnd, 0, 0, 0, dpi.scale(281), dpi.scale(141), _SWP_NOZORDER|_SWP_NOMOVE)
setWindowPos.Call(dlg.textCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), _SWP_NOZORDER)
setWindowPos.Call(dlg.editCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(24), _SWP_NOZORDER)
if dlg.extraBtn == 0 {
setWindowPos.Call(dlg.okBtn, 0, dpi.scale(95), dpi.scale(66), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(66), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(dlg.okBtn, 0, dpi.scale(95), dpi.scale(66), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
setWindowPos.Call(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(66), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
} else {
setWindowPos.Call(dlg.okBtn, 0, dpi.scale(12), dpi.scale(66), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(dlg.extraBtn, 0, dpi.scale(95), dpi.scale(66), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(66), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(dlg.okBtn, 0, dpi.scale(12), dpi.scale(66), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
setWindowPos.Call(dlg.extraBtn, 0, dpi.scale(95), dpi.scale(66), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
setWindowPos.Call(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(66), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
}
}
func entryProc(wnd uintptr, msg uint32, wparam uintptr, lparam *unsafe.Pointer) uintptr {
var dlg *entryDialog
switch msg {
case 0x0081: // WM_NCCREATE
case _WM_NCCREATE:
saveBackRef(wnd, *lparam)
dlg = (*entryDialog)(*lparam)
case 0x0082: // WM_NCDESTROY
case _WM_NCDESTROY:
deleteBackRef(wnd)
default:
dlg = (*entryDialog)(loadBackRef(wnd))
}
switch msg {
case 0x0002: // WM_DESTROY
case _WM_DESTROY:
postQuitMessage.Call(0)
case 0x0010: // WM_CLOSE
case _WM_CLOSE:
dlg.err = ErrCanceled
destroyWindow.Call(wnd)
case 0x0111: // WM_COMMAND
case _WM_COMMAND:
switch wparam {
default:
return 1
case 1, 6: // IDOK, IDYES
case _IDOK, _IDYES:
dlg.out = getWindowString(dlg.editCtl)
case 2: // IDCANCEL
case _IDCANCEL:
dlg.err = ErrCanceled
case 7: // IDNO
case _IDNO:
dlg.err = ErrExtraButton
}
destroyWindow.Call(wnd)
case 0x02e0: // WM_DPICHANGED
case _WM_DPICHANGED:
dlg.layout(dpi(uint32(wparam) >> 16))
default:

View File

@ -70,50 +70,49 @@ func (dlg *listDialog) setup(text string, opts options) ([]string, error) {
}
defer unregisterClass.Call(cls, instance)
dlg.wnd, _, _ = createWindowEx.Call(0x10101, // WS_EX_CONTROLPARENT|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME
dlg.wnd, _, _ = createWindowEx.Call(_WS_EX_CONTROLPARENT|_WS_EX_WINDOWEDGE|_WS_EX_DLGMODALFRAME,
cls, strptr(*opts.title),
0x84c80000, // WS_POPUPWINDOW|WS_CLIPSIBLINGS|WS_DLGFRAME
0x80000000, // CW_USEDEFAULT
0x80000000, // CW_USEDEFAULT
_WS_POPUPWINDOW|_WS_CLIPSIBLINGS|_WS_DLGFRAME,
_CW_USEDEFAULT, _CW_USEDEFAULT,
281, 281, 0, 0, instance, uintptr(unsafe.Pointer(dlg)))
dlg.textCtl, _, _ = createWindowEx.Call(0,
strptr("STATIC"), strptr(text),
0x5002e080, // WS_CHILD|WS_VISIBLE|WS_GROUP|SS_WORDELLIPSIS|SS_EDITCONTROL|SS_NOPREFIX
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_SS_WORDELLIPSIS|_SS_EDITCONTROL|_SS_NOPREFIX,
12, 10, 241, 16, dlg.wnd, 0, instance, 0)
var flags uintptr = 0x50320000 // WS_CHILD|WS_VISIBLE|WS_VSCROLL|WS_GROUP|WS_TABSTOP
var flags uintptr = _WS_CHILD | _WS_VISIBLE | _WS_GROUP | _WS_TABSTOP | _WS_VSCROLL
if dlg.multiple {
flags |= 0x0800 // LBS_EXTENDEDSEL
flags |= _LBS_EXTENDEDSEL
}
dlg.listCtl, _, _ = createWindowEx.Call(0x200, // WS_EX_CLIENTEDGE
dlg.listCtl, _, _ = createWindowEx.Call(_WS_EX_CLIENTEDGE,
strptr("LISTBOX"), strptr(opts.entryText),
flags,
12, 30, 241, 164, dlg.wnd, 0, instance, 0)
dlg.okBtn, _, _ = createWindowEx.Call(0,
strptr("BUTTON"), strptr(*opts.okLabel),
0x50030001, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP|BS_DEFPUSHBUTTON
12, 206, 75, 24, dlg.wnd, 1 /* IDOK */, instance, 0)
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP|_BS_DEFPUSHBUTTON,
12, 206, 75, 24, dlg.wnd, _IDOK, instance, 0)
dlg.cancelBtn, _, _ = createWindowEx.Call(0,
strptr("BUTTON"), strptr(*opts.cancelLabel),
0x50010000, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP
12, 206, 75, 24, dlg.wnd, 2 /* IDCANCEL */, instance, 0)
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP,
12, 206, 75, 24, dlg.wnd, _IDCANCEL, instance, 0)
if opts.extraButton != nil {
dlg.extraBtn, _, _ = createWindowEx.Call(0,
strptr("BUTTON"), strptr(*opts.extraButton),
0x50010000, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP
12, 206, 75, 24, dlg.wnd, 7 /* IDNO */, instance, 0)
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP,
12, 206, 75, 24, dlg.wnd, _IDNO, instance, 0)
}
for _, item := range dlg.items {
sendMessage.Call(dlg.listCtl, 0x180 /* LB_ADDSTRING */, 0, strptr(item))
sendMessage.Call(dlg.listCtl, _LB_ADDSTRING, 0, strptr(item))
}
dlg.layout(getDPI(dlg.wnd))
centerWindow(dlg.wnd)
setFocus.Call(dlg.listCtl)
showWindow.Call(dlg.wnd, 1 /* SW_SHOWNORMAL */, 0)
showWindow.Call(dlg.wnd, _SW_NORMAL, 0)
if opts.ctx != nil {
wait := make(chan struct{})
@ -121,7 +120,7 @@ func (dlg *listDialog) setup(text string, opts options) ([]string, error) {
go func() {
select {
case <-opts.ctx.Done():
sendMessage.Call(dlg.wnd, 0x0112 /* WM_SYSCOMMAND */, 0xf060 /* SC_CLOSE */, 0)
sendMessage.Call(dlg.wnd, _WM_SYSCOMMAND, _SC_CLOSE, 0)
case <-wait:
}
}()
@ -138,75 +137,75 @@ func (dlg *listDialog) setup(text string, opts options) ([]string, error) {
func (dlg *listDialog) layout(dpi dpi) {
font := dlg.font.forDPI(dpi)
sendMessage.Call(dlg.textCtl, 0x0030 /* WM_SETFONT */, font, 1)
sendMessage.Call(dlg.listCtl, 0x0030 /* WM_SETFONT */, font, 1)
sendMessage.Call(dlg.okBtn, 0x0030 /* WM_SETFONT */, font, 1)
sendMessage.Call(dlg.cancelBtn, 0x0030 /* WM_SETFONT */, font, 1)
sendMessage.Call(dlg.extraBtn, 0x0030 /* WM_SETFONT */, font, 1)
setWindowPos.Call(dlg.wnd, 0, 0, 0, dpi.scale(281), dpi.scale(281), 0x6) // SWP_NOZORDER|SWP_NOMOVE
setWindowPos.Call(dlg.textCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), 0x4) // SWP_NOZORDER
setWindowPos.Call(dlg.listCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(164), 0x4) // SWP_NOZORDER
sendMessage.Call(dlg.textCtl, _WM_SETFONT, font, 1)
sendMessage.Call(dlg.listCtl, _WM_SETFONT, font, 1)
sendMessage.Call(dlg.okBtn, _WM_SETFONT, font, 1)
sendMessage.Call(dlg.cancelBtn, _WM_SETFONT, font, 1)
sendMessage.Call(dlg.extraBtn, _WM_SETFONT, font, 1)
setWindowPos.Call(dlg.wnd, 0, 0, 0, dpi.scale(281), dpi.scale(281), _SWP_NOZORDER|_SWP_NOMOVE)
setWindowPos.Call(dlg.textCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), _SWP_NOZORDER)
setWindowPos.Call(dlg.listCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(164), _SWP_NOZORDER)
if dlg.extraBtn == 0 {
setWindowPos.Call(dlg.okBtn, 0, dpi.scale(95), dpi.scale(206), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(206), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(dlg.okBtn, 0, dpi.scale(95), dpi.scale(206), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
setWindowPos.Call(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(206), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
} else {
setWindowPos.Call(dlg.okBtn, 0, dpi.scale(12), dpi.scale(206), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(dlg.extraBtn, 0, dpi.scale(95), dpi.scale(206), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(206), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(dlg.okBtn, 0, dpi.scale(12), dpi.scale(206), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
setWindowPos.Call(dlg.extraBtn, 0, dpi.scale(95), dpi.scale(206), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
setWindowPos.Call(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(206), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
}
}
func listProc(wnd uintptr, msg uint32, wparam uintptr, lparam *unsafe.Pointer) uintptr {
var dlg *listDialog
switch msg {
case 0x0081: // WM_NCCREATE
case _WM_NCCREATE:
saveBackRef(wnd, *lparam)
dlg = (*listDialog)(*lparam)
case 0x0082: // WM_NCDESTROY
case _WM_NCDESTROY:
deleteBackRef(wnd)
default:
dlg = (*listDialog)(loadBackRef(wnd))
}
switch msg {
case 0x0002: // WM_DESTROY
case _WM_DESTROY:
postQuitMessage.Call(0)
case 0x0010: // WM_CLOSE
case _WM_CLOSE:
dlg.err = ErrCanceled
destroyWindow.Call(wnd)
case 0x0111: // WM_COMMAND
case _WM_COMMAND:
switch wparam {
default:
return 1
case 1, 6: // IDOK, IDYES
case _IDOK, _IDYES:
if dlg.multiple {
if len, _, _ := sendMessage.Call(dlg.listCtl, 0x190 /* LB_GETSELCOUNT */, 0, 0); int32(len) >= 0 {
if len, _, _ := sendMessage.Call(dlg.listCtl, _LB_GETSELCOUNT, 0, 0); int32(len) >= 0 {
dlg.out = make([]string, len)
if len > 0 {
indices := make([]int32, len)
sendMessage.Call(dlg.listCtl, 0x191 /* LB_GETSELITEMS */, len, uintptr(unsafe.Pointer(&indices[0])))
sendMessage.Call(dlg.listCtl, _LB_GETSELITEMS, len, uintptr(unsafe.Pointer(&indices[0])))
for i, idx := range indices {
dlg.out[i] = dlg.items[idx]
}
}
}
} else {
if idx, _, _ := sendMessage.Call(dlg.listCtl, 0x188 /* LB_GETCURSEL */, 0, 0); int32(idx) >= 0 {
if idx, _, _ := sendMessage.Call(dlg.listCtl, _LB_GETCURSEL, 0, 0); int32(idx) >= 0 {
dlg.out = []string{dlg.items[idx]}
} else {
dlg.out = []string{}
}
}
case 2: // IDCANCEL
case _IDCANCEL:
dlg.err = ErrCanceled
case 7: // IDNO
case _IDNO:
dlg.err = ErrExtraButton
}
destroyWindow.Call(wnd)
case 0x02e0: // WM_DPICHANGED
case _WM_DPICHANGED:
dlg.layout(dpi(uint32(wparam) >> 16))
default:

View File

@ -16,40 +16,40 @@ func message(kind messageKind, text string, opts options) error {
switch {
case kind == questionKind && opts.extraButton != nil:
flags |= 0x3 // MB_YESNOCANCEL
flags |= _MB_YESNOCANCEL
case kind == questionKind:
flags |= 0x1 // MB_OKCANCEL
flags |= _MB_OKCANCEL
case opts.extraButton != nil:
flags |= 0x4 // MB_YESNO
flags |= _MB_YESNO
}
switch opts.icon {
case ErrorIcon:
flags |= 0x10 // MB_ICONERROR
flags |= _MB_ICONERROR
case QuestionIcon:
flags |= 0x20 // MB_ICONQUESTION
flags |= _MB_ICONQUESTION
case WarningIcon:
flags |= 0x30 // MB_ICONWARNING
flags |= _MB_ICONWARNING
case InfoIcon:
flags |= 0x40 // MB_ICONINFORMATION
flags |= _MB_ICONINFORMATION
case unspecifiedIcon:
switch kind {
case errorKind:
flags |= 0x10 // MB_ICONERROR
flags |= _MB_ICONERROR
case questionKind:
flags |= 0x20 // MB_ICONQUESTION
flags |= _MB_ICONQUESTION
case warningKind:
flags |= 0x30 // MB_ICONWARNING
flags |= _MB_ICONWARNING
case infoKind:
flags |= 0x40 // MB_ICONINFORMATION
flags |= _MB_ICONINFORMATION
}
}
if kind == questionKind && opts.defaultCancel {
if opts.extraButton == nil {
flags |= 0x100 // MB_DEFBUTTON2
flags |= _MB_DEFBUTTON2
} else {
flags |= 0x200 // MB_DEFBUTTON3
flags |= _MB_DEFBUTTON3
}
}
@ -74,11 +74,11 @@ func message(kind messageKind, text string, opts options) error {
return opts.ctx.Err()
}
switch s {
case 1, 6: // IDOK, IDYES
case _IDOK, _IDYES:
return nil
case 2: // IDCANCEL
case _IDCANCEL:
return ErrCanceled
case 7: // IDNO
case _IDNO:
return ErrExtraButton
default:
return err
@ -100,11 +100,11 @@ func hookMessageLabelsCallback(wnd uintptr, lparam *options) uintptr {
ctl, _, _ := getDlgCtrlID.Call(wnd)
var text *string
switch ctl {
case 1, 6: // IDOK, IDYES
case _IDOK, _IDYES:
text = lparam.okLabel
case 2: // IDCANCEL
case _IDCANCEL:
text = lparam.cancelLabel
case 7: // IDNO
case _IDNO:
text = lparam.extraButton
}
if text != nil {

View File

@ -82,13 +82,13 @@ func wtsMessage(text string, opts options) error {
switch opts.icon {
case ErrorIcon:
flags |= 0x10 // MB_ICONERROR
flags |= _MB_ICONERROR
case QuestionIcon:
flags |= 0x20 // MB_ICONQUESTION
flags |= _MB_ICONQUESTION
case WarningIcon:
flags |= 0x30 // MB_ICONWARNING
flags |= _MB_ICONWARNING
case InfoIcon:
flags |= 0x40 // MB_ICONINFORMATION
flags |= _MB_ICONINFORMATION
}
title := opts.title

View File

@ -69,7 +69,7 @@ func (d *progressDialog) Text(text string) error {
func (d *progressDialog) Value(value int) error {
select {
default:
sendMessage.Call(d.progCtl, 0x402 /* PBM_SETPOS */, uintptr(value), 0)
sendMessage.Call(d.progCtl, _PBM_SETPOS, uintptr(value), 0)
if value >= d.max {
enableWindow.Call(d.okBtn, 1)
}
@ -90,9 +90,9 @@ func (d *progressDialog) Done() <-chan struct{} {
func (d *progressDialog) Complete() error {
select {
default:
setWindowLong.Call(d.progCtl, intptr(-16) /* GWL_STYLE */, 0x50000001 /* WS_CHILD|WS_VISIBLE|PBS_SMOOTH */)
sendMessage.Call(d.progCtl, 0x406 /* PBM_SETRANGE32 */, 0, 1)
sendMessage.Call(d.progCtl, 0x402 /* PBM_SETPOS */, 1, 0)
setWindowLong.Call(d.progCtl, intptr(_GWL_STYLE), _WS_CHILD|_WS_VISIBLE|_PBS_SMOOTH)
sendMessage.Call(d.progCtl, _PBM_SETRANGE32, 0, 1)
sendMessage.Call(d.progCtl, _PBM_SETPOS, 1, 0)
enableWindow.Call(d.okBtn, 1)
enableWindow.Call(d.cancelBtn, 0)
return nil
@ -102,7 +102,7 @@ func (d *progressDialog) Complete() error {
}
func (d *progressDialog) Close() error {
sendMessage.Call(d.wnd, 0x0112 /* WM_SYSCOMMAND */, 0xf060 /* SC_CLOSE */, 0)
sendMessage.Call(d.wnd, _WM_SYSCOMMAND, _SC_CLOSE, 0)
<-d.done
if d.err == ErrCanceled {
return nil
@ -137,51 +137,50 @@ func (dlg *progressDialog) setup(opts options) error {
}
defer unregisterClass.Call(cls, instance)
dlg.wnd, _, _ = createWindowEx.Call(0x10101, // WS_EX_CONTROLPARENT|WS_EX_WINDOWEDGE|WS_EX_DLGMODALFRAME
dlg.wnd, _, _ = createWindowEx.Call(_WS_EX_CONTROLPARENT|_WS_EX_WINDOWEDGE|_WS_EX_DLGMODALFRAME,
cls, strptr(*opts.title),
0x84c80000, // WS_POPUPWINDOW|WS_CLIPSIBLINGS|WS_DLGFRAME
0x80000000, // CW_USEDEFAULT
0x80000000, // CW_USEDEFAULT
_WS_POPUPWINDOW|_WS_CLIPSIBLINGS|_WS_DLGFRAME,
_CW_USEDEFAULT, _CW_USEDEFAULT,
281, 133, 0, 0, instance, uintptr(unsafe.Pointer(dlg)))
dlg.textCtl, _, _ = createWindowEx.Call(0,
strptr("STATIC"), 0,
0x5002e080, // WS_CHILD|WS_VISIBLE|WS_GROUP|SS_WORDELLIPSIS|SS_EDITCONTROL|SS_NOPREFIX
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_SS_WORDELLIPSIS|_SS_EDITCONTROL|_SS_NOPREFIX,
12, 10, 241, 16, dlg.wnd, 0, instance, 0)
var flags uintptr = 0x50000001 // WS_CHILD|WS_VISIBLE|PBS_SMOOTH
var flags uintptr = _WS_CHILD | _WS_VISIBLE | _PBS_SMOOTH
if opts.maxValue < 0 {
flags |= 0x8 // PBS_MARQUEE
flags |= _PBS_MARQUEE
}
dlg.progCtl, _, _ = createWindowEx.Call(0,
strptr("msctls_progress32"), // PROGRESS_CLASS
strptr(_PROGRESS_CLASS),
0, flags,
12, 30, 241, 16, dlg.wnd, 0, instance, 0)
dlg.okBtn, _, _ = createWindowEx.Call(0,
strptr("BUTTON"), strptr(*opts.okLabel),
0x58030001, // WS_CHILD|WS_VISIBLE|WS_DISABLED|WS_GROUP|WS_TABSTOP|BS_DEFPUSHBUTTON
12, 58, 75, 24, dlg.wnd, 1 /* IDOK */, instance, 0)
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP|_BS_DEFPUSHBUTTON|_WS_DISABLED,
12, 58, 75, 24, dlg.wnd, _IDOK, instance, 0)
if !opts.noCancel {
dlg.cancelBtn, _, _ = createWindowEx.Call(0,
strptr("BUTTON"), strptr(*opts.cancelLabel),
0x50010000, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP
12, 58, 75, 24, dlg.wnd, 2 /* IDCANCEL */, instance, 0)
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP,
12, 58, 75, 24, dlg.wnd, _IDCANCEL, instance, 0)
}
if opts.extraButton != nil {
dlg.extraBtn, _, _ = createWindowEx.Call(0,
strptr("BUTTON"), strptr(*opts.extraButton),
0x50010000, // WS_CHILD|WS_VISIBLE|WS_GROUP|WS_TABSTOP
12, 58, 75, 24, dlg.wnd, 7 /* IDNO */, instance, 0)
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP,
12, 58, 75, 24, dlg.wnd, _IDNO, instance, 0)
}
dlg.layout(getDPI(dlg.wnd))
centerWindow(dlg.wnd)
showWindow.Call(dlg.wnd, 1 /* SW_SHOWNORMAL */, 0)
showWindow.Call(dlg.wnd, _SW_NORMAL, 0)
if opts.maxValue < 0 {
sendMessage.Call(dlg.progCtl, 0x40a /* PBM_SETMARQUEE */, 1, 0)
sendMessage.Call(dlg.progCtl, _PBM_SETMARQUEE, 1, 0)
} else {
sendMessage.Call(dlg.progCtl, 0x406 /* PBM_SETRANGE32 */, 0, uintptr(opts.maxValue))
sendMessage.Call(dlg.progCtl, _PBM_SETRANGE32, 0, uintptr(opts.maxValue))
}
dlg.init.Done()
done = true
@ -192,7 +191,7 @@ func (dlg *progressDialog) setup(opts options) error {
go func() {
select {
case <-opts.ctx.Done():
sendMessage.Call(dlg.wnd, 0x0112 /* WM_SYSCOMMAND */, 0xf060 /* SC_CLOSE */, 0)
sendMessage.Call(dlg.wnd, _WM_SYSCOMMAND, _SC_CLOSE, 0)
case <-wait:
}
}()
@ -209,28 +208,28 @@ func (dlg *progressDialog) setup(opts options) error {
func (d *progressDialog) layout(dpi dpi) {
font := d.font.forDPI(dpi)
sendMessage.Call(d.textCtl, 0x0030 /* WM_SETFONT */, font, 1)
sendMessage.Call(d.okBtn, 0x0030 /* WM_SETFONT */, font, 1)
sendMessage.Call(d.cancelBtn, 0x0030 /* WM_SETFONT */, font, 1)
sendMessage.Call(d.extraBtn, 0x0030 /* WM_SETFONT */, font, 1)
setWindowPos.Call(d.wnd, 0, 0, 0, dpi.scale(281), dpi.scale(133), 0x6) // SWP_NOZORDER|SWP_NOMOVE
setWindowPos.Call(d.textCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), 0x4) // SWP_NOZORDER
setWindowPos.Call(d.progCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(16), 0x4) // SWP_NOZORDER
sendMessage.Call(d.textCtl, _WM_SETFONT, font, 1)
sendMessage.Call(d.okBtn, _WM_SETFONT, font, 1)
sendMessage.Call(d.cancelBtn, _WM_SETFONT, font, 1)
sendMessage.Call(d.extraBtn, _WM_SETFONT, font, 1)
setWindowPos.Call(d.wnd, 0, 0, 0, dpi.scale(281), dpi.scale(133), _SWP_NOZORDER|_SWP_NOMOVE)
setWindowPos.Call(d.textCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), _SWP_NOZORDER)
setWindowPos.Call(d.progCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(16), _SWP_NOZORDER)
if d.extraBtn == 0 {
if d.cancelBtn == 0 {
setWindowPos.Call(d.okBtn, 0, dpi.scale(178), dpi.scale(58), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(d.okBtn, 0, dpi.scale(178), dpi.scale(58), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
} else {
setWindowPos.Call(d.okBtn, 0, dpi.scale(95), dpi.scale(58), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(d.cancelBtn, 0, dpi.scale(178), dpi.scale(58), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(d.okBtn, 0, dpi.scale(95), dpi.scale(58), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
setWindowPos.Call(d.cancelBtn, 0, dpi.scale(178), dpi.scale(58), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
}
} else {
if d.cancelBtn == 0 {
setWindowPos.Call(d.okBtn, 0, dpi.scale(95), dpi.scale(58), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(d.extraBtn, 0, dpi.scale(178), dpi.scale(58), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(d.okBtn, 0, dpi.scale(95), dpi.scale(58), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
setWindowPos.Call(d.extraBtn, 0, dpi.scale(178), dpi.scale(58), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
} else {
setWindowPos.Call(d.okBtn, 0, dpi.scale(12), dpi.scale(58), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(d.extraBtn, 0, dpi.scale(95), dpi.scale(58), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(d.cancelBtn, 0, dpi.scale(178), dpi.scale(58), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(d.okBtn, 0, dpi.scale(12), dpi.scale(58), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
setWindowPos.Call(d.extraBtn, 0, dpi.scale(95), dpi.scale(58), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
setWindowPos.Call(d.cancelBtn, 0, dpi.scale(178), dpi.scale(58), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
}
}
}
@ -238,37 +237,37 @@ func (d *progressDialog) layout(dpi dpi) {
func progressProc(wnd uintptr, msg uint32, wparam uintptr, lparam *unsafe.Pointer) uintptr {
var dlg *progressDialog
switch msg {
case 0x0081: // WM_NCCREATE
case _WM_NCCREATE:
saveBackRef(wnd, *lparam)
dlg = (*progressDialog)(*lparam)
case 0x0082: // WM_NCDESTROY
case _WM_NCDESTROY:
deleteBackRef(wnd)
default:
dlg = (*progressDialog)(loadBackRef(wnd))
}
switch msg {
case 0x0002: // WM_DESTROY
case _WM_DESTROY:
postQuitMessage.Call(0)
case 0x0010: // WM_CLOSE
case _WM_CLOSE:
dlg.err = ErrCanceled
destroyWindow.Call(wnd)
case 0x0111: // WM_COMMAND
case _WM_COMMAND:
switch wparam {
default:
return 1
case 1, 6: // IDOK, IDYES
case _IDOK, _IDYES:
//
case 2: // IDCANCEL
case _IDCANCEL:
dlg.err = ErrCanceled
case 7: // IDNO
case _IDNO:
dlg.err = ErrExtraButton
}
destroyWindow.Call(wnd)
case 0x02e0: // WM_DPICHANGED
case _WM_DPICHANGED:
dlg.layout(dpi(uint32(wparam) >> 16))
default:

View File

@ -204,7 +204,7 @@ func dialogHookProc(code int32, wparam uintptr, lparam *_CWPRETSTRUCT) uintptr {
hook := (*dialogHook)(loadBackRef(tid))
atomic.StoreUintptr(&hook.wnd, lparam.Wnd)
if hook.ctx != nil && hook.ctx.Err() != nil {
sendMessage.Call(lparam.Wnd, 0x0112 /* WM_SYSCOMMAND */, 0xf060 /* SC_CLOSE */, 0)
sendMessage.Call(lparam.Wnd, _WM_SYSCOMMAND, _SC_CLOSE, 0)
} else if hook.init != nil {
hook.init(lparam.Wnd)
}
@ -227,7 +227,7 @@ func (h *dialogHook) wait() {
select {
case <-h.ctx.Done():
if wnd := atomic.LoadUintptr(&h.wnd); wnd != 0 {
sendMessage.Call(wnd, 0x0112 /* WM_SYSCOMMAND */, 0xf060 /* SC_CLOSE */, 0)
sendMessage.Call(wnd, _WM_SYSCOMMAND, _SC_CLOSE, 0)
}
case <-h.done:
}
@ -507,6 +507,18 @@ type _WNDCLASSEX struct {
IconSm uintptr
}
// https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-systemtime
type _SYSTEMTIME struct {
year uint16
month uint16
dayOfWeek uint16
day uint16
hour uint16
minute uint16
second uint16
milliseconds uint16
}
// https://github.com/wine-mirror/wine/blob/master/include/unknwn.idl
type _IUnknownVtbl struct {

View File

@ -55,9 +55,7 @@ type options struct {
defaultItems []string
// Calendar options
month time.Month
day int
year *int
time *time.Time
// File selection options
directory bool