This commit is contained in:
Nuno Cruces 2022-03-23 13:52:52 +00:00
parent da48e44e0c
commit b73a8aaa3e
4 changed files with 47 additions and 47 deletions

View file

@ -17,29 +17,29 @@ func entry(text string, opts options) (out string, err error) {
defer setup()() defer setup()()
font := getFont() font := getFont()
defer font.Delete() defer font.delete()
defWindowProc := defWindowProc.Addr() defWindowProc := defWindowProc.Addr()
var wnd, textCtl, editCtl uintptr var wnd, textCtl, editCtl uintptr
var okBtn, cancelBtn, extraBtn uintptr var okBtn, cancelBtn, extraBtn uintptr
layout := func(dpi dpi) { layout := func(dpi dpi) {
hfont := font.ForDPI(dpi) font := font.forDPI(dpi)
sendMessage.Call(textCtl, 0x0030 /* WM_SETFONT */, hfont, 1) sendMessage.Call(textCtl, 0x0030 /* WM_SETFONT */, font, 1)
sendMessage.Call(editCtl, 0x0030 /* WM_SETFONT */, hfont, 1) sendMessage.Call(editCtl, 0x0030 /* WM_SETFONT */, font, 1)
sendMessage.Call(okBtn, 0x0030 /* WM_SETFONT */, hfont, 1) sendMessage.Call(okBtn, 0x0030 /* WM_SETFONT */, font, 1)
sendMessage.Call(cancelBtn, 0x0030 /* WM_SETFONT */, hfont, 1) sendMessage.Call(cancelBtn, 0x0030 /* WM_SETFONT */, font, 1)
sendMessage.Call(extraBtn, 0x0030 /* WM_SETFONT */, hfont, 1) sendMessage.Call(extraBtn, 0x0030 /* WM_SETFONT */, font, 1)
setWindowPos.Call(wnd, 0, 0, 0, dpi.Scale(281), dpi.Scale(141), 0x6) // SWP_NOZORDER|SWP_NOMOVE setWindowPos.Call(wnd, 0, 0, 0, dpi.scale(281), dpi.scale(141), 0x6) // SWP_NOZORDER|SWP_NOMOVE
setWindowPos.Call(textCtl, 0, dpi.Scale(12), dpi.Scale(10), dpi.Scale(241), dpi.Scale(16), 0x4) // SWP_NOZORDER setWindowPos.Call(textCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), 0x4) // SWP_NOZORDER
setWindowPos.Call(editCtl, 0, dpi.Scale(12), dpi.Scale(30), dpi.Scale(241), dpi.Scale(24), 0x4) // SWP_NOZORDER setWindowPos.Call(editCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(24), 0x4) // SWP_NOZORDER
if extraBtn == 0 { if extraBtn == 0 {
setWindowPos.Call(okBtn, 0, dpi.Scale(95), dpi.Scale(66), dpi.Scale(75), dpi.Scale(24), 0x4) // SWP_NOZORDER setWindowPos.Call(okBtn, 0, dpi.scale(95), dpi.scale(66), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(cancelBtn, 0, dpi.Scale(178), dpi.Scale(66), dpi.Scale(75), dpi.Scale(24), 0x4) // SWP_NOZORDER setWindowPos.Call(cancelBtn, 0, dpi.scale(178), dpi.scale(66), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
} else { } else {
setWindowPos.Call(okBtn, 0, dpi.Scale(12), dpi.Scale(66), dpi.Scale(75), dpi.Scale(24), 0x4) // SWP_NOZORDER setWindowPos.Call(okBtn, 0, dpi.scale(12), dpi.scale(66), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(extraBtn, 0, dpi.Scale(95), dpi.Scale(66), dpi.Scale(75), dpi.Scale(24), 0x4) // SWP_NOZORDER setWindowPos.Call(extraBtn, 0, dpi.scale(95), dpi.scale(66), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(cancelBtn, 0, dpi.Scale(178), dpi.Scale(66), dpi.Scale(75), dpi.Scale(24), 0x4) // SWP_NOZORDER setWindowPos.Call(cancelBtn, 0, dpi.scale(178), dpi.scale(66), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
} }
} }

View file

@ -30,29 +30,29 @@ func listDlg(text string, items []string, multiple bool, opts options) (out []st
defer setup()() defer setup()()
font := getFont() font := getFont()
defer font.Delete() defer font.delete()
defWindowProc := defWindowProc.Addr() defWindowProc := defWindowProc.Addr()
var wnd, textCtl, listCtl uintptr var wnd, textCtl, listCtl uintptr
var okBtn, cancelBtn, extraBtn uintptr var okBtn, cancelBtn, extraBtn uintptr
layout := func(dpi dpi) { layout := func(dpi dpi) {
hfont := font.ForDPI(dpi) hfont := font.forDPI(dpi)
sendMessage.Call(textCtl, 0x0030 /* WM_SETFONT */, hfont, 1) sendMessage.Call(textCtl, 0x0030 /* WM_SETFONT */, hfont, 1)
sendMessage.Call(listCtl, 0x0030 /* WM_SETFONT */, hfont, 1) sendMessage.Call(listCtl, 0x0030 /* WM_SETFONT */, hfont, 1)
sendMessage.Call(okBtn, 0x0030 /* WM_SETFONT */, hfont, 1) sendMessage.Call(okBtn, 0x0030 /* WM_SETFONT */, hfont, 1)
sendMessage.Call(cancelBtn, 0x0030 /* WM_SETFONT */, hfont, 1) sendMessage.Call(cancelBtn, 0x0030 /* WM_SETFONT */, hfont, 1)
sendMessage.Call(extraBtn, 0x0030 /* WM_SETFONT */, hfont, 1) sendMessage.Call(extraBtn, 0x0030 /* WM_SETFONT */, hfont, 1)
setWindowPos.Call(wnd, 0, 0, 0, dpi.Scale(281), dpi.Scale(281), 0x6) // SWP_NOZORDER|SWP_NOMOVE setWindowPos.Call(wnd, 0, 0, 0, dpi.scale(281), dpi.scale(281), 0x6) // SWP_NOZORDER|SWP_NOMOVE
setWindowPos.Call(textCtl, 0, dpi.Scale(12), dpi.Scale(10), dpi.Scale(241), dpi.Scale(16), 0x4) // SWP_NOZORDER setWindowPos.Call(textCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), 0x4) // SWP_NOZORDER
setWindowPos.Call(listCtl, 0, dpi.Scale(12), dpi.Scale(30), dpi.Scale(241), dpi.Scale(164), 0x4) // SWP_NOZORDER setWindowPos.Call(listCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(164), 0x4) // SWP_NOZORDER
if extraBtn == 0 { if extraBtn == 0 {
setWindowPos.Call(okBtn, 0, dpi.Scale(95), dpi.Scale(206), dpi.Scale(75), dpi.Scale(24), 0x4) // SWP_NOZORDER setWindowPos.Call(okBtn, 0, dpi.scale(95), dpi.scale(206), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(cancelBtn, 0, dpi.Scale(178), dpi.Scale(206), dpi.Scale(75), dpi.Scale(24), 0x4) // SWP_NOZORDER setWindowPos.Call(cancelBtn, 0, dpi.scale(178), dpi.scale(206), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
} else { } else {
setWindowPos.Call(okBtn, 0, dpi.Scale(12), dpi.Scale(206), dpi.Scale(75), dpi.Scale(24), 0x4) // SWP_NOZORDER setWindowPos.Call(okBtn, 0, dpi.scale(12), dpi.scale(206), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(extraBtn, 0, dpi.Scale(95), dpi.Scale(206), dpi.Scale(75), dpi.Scale(24), 0x4) // SWP_NOZORDER setWindowPos.Call(extraBtn, 0, dpi.scale(95), dpi.scale(206), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(cancelBtn, 0, dpi.Scale(178), dpi.Scale(206), dpi.Scale(75), dpi.Scale(24), 0x4) // SWP_NOZORDER setWindowPos.Call(cancelBtn, 0, dpi.scale(178), dpi.scale(206), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
} }
} }

View file

@ -48,33 +48,33 @@ func progressDlg(opts options, dlg *progressDialog) (err error) {
defer dlg.init.Done() defer dlg.init.Done()
defer setup()() defer setup()()
font := getFont() font := getFont()
defer font.Delete() defer font.delete()
defWindowProc := defWindowProc.Addr() defWindowProc := defWindowProc.Addr()
layout := func(dpi dpi) { layout := func(dpi dpi) {
hfont := font.ForDPI(dpi) font := font.forDPI(dpi)
sendMessage.Call(dlg.textCtl, 0x0030 /* WM_SETFONT */, hfont, 1) sendMessage.Call(dlg.textCtl, 0x0030 /* WM_SETFONT */, font, 1)
sendMessage.Call(dlg.okBtn, 0x0030 /* WM_SETFONT */, hfont, 1) sendMessage.Call(dlg.okBtn, 0x0030 /* WM_SETFONT */, font, 1)
sendMessage.Call(dlg.cancelBtn, 0x0030 /* WM_SETFONT */, hfont, 1) sendMessage.Call(dlg.cancelBtn, 0x0030 /* WM_SETFONT */, font, 1)
sendMessage.Call(dlg.extraBtn, 0x0030 /* WM_SETFONT */, hfont, 1) sendMessage.Call(dlg.extraBtn, 0x0030 /* WM_SETFONT */, font, 1)
setWindowPos.Call(dlg.wnd, 0, 0, 0, dpi.Scale(281), dpi.Scale(133), 0x6) // SWP_NOZORDER|SWP_NOMOVE setWindowPos.Call(dlg.wnd, 0, 0, 0, dpi.scale(281), dpi.scale(133), 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.textCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), 0x4) // SWP_NOZORDER
setWindowPos.Call(dlg.progCtl, 0, dpi.Scale(12), dpi.Scale(30), dpi.Scale(241), dpi.Scale(16), 0x4) // SWP_NOZORDER setWindowPos.Call(dlg.progCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(16), 0x4) // SWP_NOZORDER
if dlg.extraBtn == 0 { if dlg.extraBtn == 0 {
if dlg.cancelBtn == 0 { if dlg.cancelBtn == 0 {
setWindowPos.Call(dlg.okBtn, 0, dpi.Scale(178), dpi.Scale(58), dpi.Scale(75), dpi.Scale(24), 0x4) // SWP_NOZORDER setWindowPos.Call(dlg.okBtn, 0, dpi.scale(178), dpi.scale(58), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
} else { } else {
setWindowPos.Call(dlg.okBtn, 0, dpi.Scale(95), dpi.Scale(58), dpi.Scale(75), dpi.Scale(24), 0x4) // SWP_NOZORDER setWindowPos.Call(dlg.okBtn, 0, dpi.scale(95), dpi.scale(58), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(dlg.cancelBtn, 0, dpi.Scale(178), dpi.Scale(58), dpi.Scale(75), dpi.Scale(24), 0x4) // SWP_NOZORDER setWindowPos.Call(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(58), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
} }
} else { } else {
if dlg.cancelBtn == 0 { if dlg.cancelBtn == 0 {
setWindowPos.Call(dlg.okBtn, 0, dpi.Scale(95), dpi.Scale(58), dpi.Scale(75), dpi.Scale(24), 0x4) // SWP_NOZORDER setWindowPos.Call(dlg.okBtn, 0, dpi.scale(95), dpi.scale(58), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(dlg.extraBtn, 0, dpi.Scale(178), dpi.Scale(58), dpi.Scale(75), dpi.Scale(24), 0x4) // SWP_NOZORDER setWindowPos.Call(dlg.extraBtn, 0, dpi.scale(178), dpi.scale(58), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
} else { } else {
setWindowPos.Call(dlg.okBtn, 0, dpi.Scale(12), dpi.Scale(58), dpi.Scale(75), dpi.Scale(24), 0x4) // SWP_NOZORDER setWindowPos.Call(dlg.okBtn, 0, dpi.scale(12), dpi.scale(58), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(dlg.extraBtn, 0, dpi.Scale(95), dpi.Scale(58), dpi.Scale(75), dpi.Scale(24), 0x4) // SWP_NOZORDER setWindowPos.Call(dlg.extraBtn, 0, dpi.scale(95), dpi.scale(58), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
setWindowPos.Call(dlg.cancelBtn, 0, dpi.Scale(178), dpi.Scale(58), dpi.Scale(75), dpi.Scale(24), 0x4) // SWP_NOZORDER setWindowPos.Call(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(58), dpi.scale(75), dpi.scale(24), 0x4) // SWP_NOZORDER
} }
} }
} }

View file

@ -287,7 +287,7 @@ func getDPI(wnd uintptr) dpi {
return dpi(res) return dpi(res)
} }
func (d dpi) Scale(dim uintptr) uintptr { func (d dpi) scale(dim uintptr) uintptr {
if d == 0 { if d == 0 {
return dim return dim
} }
@ -307,16 +307,16 @@ func getFont() font {
return font{logical: metrics.MessageFont} return font{logical: metrics.MessageFont}
} }
func (f *font) ForDPI(dpi dpi) uintptr { func (f *font) forDPI(dpi dpi) uintptr {
if h := -int32(dpi.Scale(12)); f.handle == 0 || f.logical.Height != h { if h := -int32(dpi.scale(12)); f.handle == 0 || f.logical.Height != h {
f.Delete() f.delete()
f.logical.Height = h f.logical.Height = h
f.handle, _, _ = createFontIndirect.Call(uintptr(unsafe.Pointer(&f.logical))) f.handle, _, _ = createFontIndirect.Call(uintptr(unsafe.Pointer(&f.logical)))
} }
return f.handle return f.handle
} }
func (f *font) Delete() { func (f *font) delete() {
if f.handle != 0 { if f.handle != 0 {
deleteObject.Call(f.handle) deleteObject.Call(f.handle)
f.handle = 0 f.handle = 0