Refactor (windows).

This commit is contained in:
Nuno Cruces 2022-06-21 12:28:21 +01:00
parent 2428e68504
commit 113333268d
9 changed files with 323 additions and 205 deletions

View File

@ -1,46 +0,0 @@
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
_SC_CLOSE = 0xf060
_GWL_STYLE = -16
_PROGRESS_CLASS = "msctls_progress32"
_MONTHCAL_CLASS = "SysMonthCal32"
)

View File

@ -59,35 +59,32 @@ func (dlg *calendarDialog) setup(text string, opts options) (time.Time, error) {
defer win.UnregisterClass(cls, instance)
owner, _ := opts.attach.(win.HWND)
dlg.wnd, _ = win.CreateWindowEx(_WS_EX_CONTROLPARENT|_WS_EX_WINDOWEDGE|_WS_EX_DLGMODALFRAME,
cls, strptr(*opts.title),
_WS_POPUPWINDOW|_WS_CLIPSIBLINGS|_WS_DLGFRAME,
_CW_USEDEFAULT, _CW_USEDEFAULT,
dlg.wnd, _ = win.CreateWindowEx(_WS_EX_ZEN_DIALOG,
cls, strptr(*opts.title), _WS_ZEN_DIALOG,
win.CW_USEDEFAULT, win.CW_USEDEFAULT,
281, 281, owner, 0, instance, unsafe.Pointer(dlg))
dlg.textCtl, _ = win.CreateWindowEx(0,
strptr("STATIC"), strptr(text),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_SS_WORDELLIPSIS|_SS_EDITCONTROL|_SS_NOPREFIX,
strptr("STATIC"), strptr(text), _WS_ZEN_LABEL,
12, 10, 241, 16, dlg.wnd, 0, instance, nil)
var flags uint32 = _WS_CHILD | _WS_VISIBLE | _WS_GROUP | _WS_TABSTOP | _MCS_NOTODAY
dlg.dateCtl, _ = win.CreateWindowEx(0,
strptr(_MONTHCAL_CLASS),
nil, flags,
strptr(win.MONTHCAL_CLASS),
nil, _WS_ZEN_CONTROL|win.MCS_NOTODAY,
12, 30, 241, 164, dlg.wnd, 0, instance, nil)
dlg.okBtn, _ = win.CreateWindowEx(0,
strptr("BUTTON"), strptr(*opts.okLabel),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP|_BS_DEFPUSHBUTTON,
_WS_ZEN_BUTTON|win.BS_DEFPUSHBUTTON,
12, 206, 75, 24, dlg.wnd, win.IDOK, instance, nil)
dlg.cancelBtn, _ = win.CreateWindowEx(0,
strptr("BUTTON"), strptr(*opts.cancelLabel),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP,
_WS_ZEN_BUTTON,
12, 206, 75, 24, dlg.wnd, win.IDCANCEL, instance, nil)
if opts.extraButton != nil {
dlg.extraBtn, _ = win.CreateWindowEx(0,
strptr("BUTTON"), strptr(*opts.extraButton),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP,
_WS_ZEN_BUTTON,
12, 206, 75, 24, dlg.wnd, win.IDNO, instance, nil)
}
@ -103,7 +100,7 @@ func (dlg *calendarDialog) setup(text string, opts options) (time.Time, error) {
dlg.layout(getDPI(dlg.wnd))
centerWindow(dlg.wnd)
win.SetFocus(dlg.dateCtl)
win.ShowWindow(dlg.wnd, _SW_NORMAL)
win.ShowWindow(dlg.wnd, win.SW_NORMAL)
if opts.ctx != nil {
wait := make(chan struct{})
@ -111,7 +108,7 @@ func (dlg *calendarDialog) setup(text string, opts options) (time.Time, error) {
go func() {
select {
case <-opts.ctx.Done():
win.SendMessage(dlg.wnd, win.WM_SYSCOMMAND, _SC_CLOSE, 0)
win.SendMessage(dlg.wnd, win.WM_SYSCOMMAND, win.SC_CLOSE, 0)
case <-wait:
}
}()
@ -133,16 +130,16 @@ func (dlg *calendarDialog) layout(dpi dpi) {
win.SendMessage(dlg.okBtn, win.WM_SETFONT, font, 1)
win.SendMessage(dlg.cancelBtn, win.WM_SETFONT, font, 1)
win.SendMessage(dlg.extraBtn, win.WM_SETFONT, font, 1)
win.SetWindowPos(dlg.wnd, 0, 0, 0, dpi.scale(281), dpi.scale(281), _SWP_NOZORDER|_SWP_NOMOVE)
win.SetWindowPos(dlg.textCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), _SWP_NOZORDER)
win.SetWindowPos(dlg.dateCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(164), _SWP_NOZORDER)
win.SetWindowPos(dlg.wnd, 0, 0, 0, dpi.scale(281), dpi.scale(281), win.SWP_NOMOVE|win.SWP_NOZORDER)
win.SetWindowPos(dlg.textCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), win.SWP_NOZORDER)
win.SetWindowPos(dlg.dateCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(164), win.SWP_NOZORDER)
if dlg.extraBtn == 0 {
win.SetWindowPos(dlg.okBtn, 0, dpi.scale(95), dpi.scale(206), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(206), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.okBtn, 0, dpi.scale(95), dpi.scale(206), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
win.SetWindowPos(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(206), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
} else {
win.SetWindowPos(dlg.okBtn, 0, dpi.scale(12), dpi.scale(206), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.extraBtn, 0, dpi.scale(95), dpi.scale(206), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(206), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.okBtn, 0, dpi.scale(12), dpi.scale(206), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
win.SetWindowPos(dlg.extraBtn, 0, dpi.scale(95), dpi.scale(206), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
win.SetWindowPos(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(206), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
}
}

View File

@ -58,45 +58,43 @@ func (dlg *entryDialog) setup(text string, opts options) (string, error) {
defer win.UnregisterClass(cls, instance)
owner, _ := opts.attach.(win.HWND)
dlg.wnd, _ = win.CreateWindowEx(_WS_EX_CONTROLPARENT|_WS_EX_WINDOWEDGE|_WS_EX_DLGMODALFRAME,
cls, strptr(*opts.title),
_WS_POPUPWINDOW|_WS_CLIPSIBLINGS|_WS_DLGFRAME,
_CW_USEDEFAULT, _CW_USEDEFAULT,
dlg.wnd, _ = win.CreateWindowEx(_WS_EX_ZEN_DIALOG,
cls, strptr(*opts.title), _WS_ZEN_DIALOG,
win.CW_USEDEFAULT, win.CW_USEDEFAULT,
281, 141, owner, 0, instance, unsafe.Pointer(dlg))
dlg.textCtl, _ = win.CreateWindowEx(0,
strptr("STATIC"), strptr(text),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_SS_WORDELLIPSIS|_SS_EDITCONTROL|_SS_NOPREFIX,
strptr("STATIC"), strptr(text), _WS_ZEN_LABEL,
12, 10, 241, 16, dlg.wnd, 0, instance, nil)
var flags uint32 = _WS_CHILD | _WS_VISIBLE | _WS_GROUP | _WS_TABSTOP | _ES_AUTOHSCROLL
var flags uint32 = _WS_ZEN_CONTROL | win.ES_AUTOHSCROLL
if opts.hideText {
flags |= _ES_PASSWORD
flags |= win.ES_PASSWORD
}
dlg.editCtl, _ = win.CreateWindowEx(_WS_EX_CLIENTEDGE,
dlg.editCtl, _ = win.CreateWindowEx(win.WS_EX_CLIENTEDGE,
strptr("EDIT"), strptr(opts.entryText),
flags,
12, 30, 241, 24, dlg.wnd, 0, instance, nil)
dlg.okBtn, _ = win.CreateWindowEx(0,
strptr("BUTTON"), strptr(*opts.okLabel),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP|_BS_DEFPUSHBUTTON,
_WS_ZEN_BUTTON|win.BS_DEFPUSHBUTTON,
12, 66, 75, 24, dlg.wnd, win.IDOK, instance, nil)
dlg.cancelBtn, _ = win.CreateWindowEx(0,
strptr("BUTTON"), strptr(*opts.cancelLabel),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP,
_WS_ZEN_BUTTON,
12, 66, 75, 24, dlg.wnd, win.IDCANCEL, instance, nil)
if opts.extraButton != nil {
dlg.extraBtn, _ = win.CreateWindowEx(0,
strptr("BUTTON"), strptr(*opts.extraButton),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP,
_WS_ZEN_BUTTON,
12, 66, 75, 24, dlg.wnd, win.IDNO, instance, nil)
}
dlg.layout(getDPI(dlg.wnd))
centerWindow(dlg.wnd)
win.SetFocus(dlg.editCtl)
win.ShowWindow(dlg.wnd, _SW_NORMAL)
win.ShowWindow(dlg.wnd, win.SW_NORMAL)
win.SendMessage(dlg.editCtl, win.EM_SETSEL, 0, intptr(-1))
if opts.ctx != nil {
@ -105,7 +103,7 @@ func (dlg *entryDialog) setup(text string, opts options) (string, error) {
go func() {
select {
case <-opts.ctx.Done():
win.SendMessage(dlg.wnd, win.WM_SYSCOMMAND, _SC_CLOSE, 0)
win.SendMessage(dlg.wnd, win.WM_SYSCOMMAND, win.SC_CLOSE, 0)
case <-wait:
}
}()
@ -127,16 +125,16 @@ func (dlg *entryDialog) layout(dpi dpi) {
win.SendMessage(dlg.okBtn, win.WM_SETFONT, font, 1)
win.SendMessage(dlg.cancelBtn, win.WM_SETFONT, font, 1)
win.SendMessage(dlg.extraBtn, win.WM_SETFONT, font, 1)
win.SetWindowPos(dlg.wnd, 0, 0, 0, dpi.scale(281), dpi.scale(141), _SWP_NOZORDER|_SWP_NOMOVE)
win.SetWindowPos(dlg.textCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), _SWP_NOZORDER)
win.SetWindowPos(dlg.editCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.wnd, 0, 0, 0, dpi.scale(281), dpi.scale(141), win.SWP_NOMOVE|win.SWP_NOZORDER)
win.SetWindowPos(dlg.textCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), win.SWP_NOZORDER)
win.SetWindowPos(dlg.editCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(24), win.SWP_NOZORDER)
if dlg.extraBtn == 0 {
win.SetWindowPos(dlg.okBtn, 0, dpi.scale(95), dpi.scale(66), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(66), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.okBtn, 0, dpi.scale(95), dpi.scale(66), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
win.SetWindowPos(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(66), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
} else {
win.SetWindowPos(dlg.okBtn, 0, dpi.scale(12), dpi.scale(66), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.extraBtn, 0, dpi.scale(95), dpi.scale(66), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(66), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.okBtn, 0, dpi.scale(12), dpi.scale(66), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
win.SetWindowPos(dlg.extraBtn, 0, dpi.scale(95), dpi.scale(66), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
win.SetWindowPos(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(66), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
}
}

View File

@ -10,6 +10,7 @@ import (
)
const (
// Button IDs
IDOK = 1
IDCANCEL = 2
IDABORT = 3
@ -18,6 +19,7 @@ const (
IDYES = 6
IDNO = 7
// MessageBox types
MB_OK = windows.MB_OK
MB_OKCANCEL = windows.MB_OKCANCEL
MB_ABORTRETRYIGNORE = windows.MB_ABORTRETRYIGNORE
@ -33,12 +35,14 @@ const (
MB_DEFBUTTON2 = windows.MB_DEFBUTTON2
MB_DEFBUTTON3 = windows.MB_DEFBUTTON3
// Window messages
WM_DESTROY = 0x0002
WM_CLOSE = 0x0010
WM_SETFONT = 0x0030
WM_SETICON = 0x0080
WM_NCCREATE = 0x0081
WM_NCDESTROY = 0x0082
WM_INITDIALOG = 0x0110
WM_COMMAND = 0x0111
WM_SYSCOMMAND = 0x0112
WM_DPICHANGED = 0x02e0
@ -55,6 +59,161 @@ const (
PBM_SETMARQUEE = WM_USER + 10
STM_SETICON = 0x0170
// CreateWindow
CW_USEDEFAULT = 0x80000000
// Window classes
PROGRESS_CLASS = "msctls_progress32"
MONTHCAL_CLASS = "SysMonthCal32"
// Window styles
WS_OVERLAPPED = 0x00000000
WS_TILED = 0x00000000
WS_MAXIMIZEBOX = 0x00010000
WS_TABSTOP = 0x00010000
WS_GROUP = 0x00020000
WS_MINIMIZEBOX = 0x00020000
WS_SIZEBOX = 0x00040000
WS_THICKFRAME = 0x00040000
WS_SYSMENU = 0x00080000
WS_HSCROLL = 0x00100000
WS_VSCROLL = 0x00200000
WS_DLGFRAME = 0x00400000
WS_BORDER = 0x00800000
WS_CAPTION = 0x00c00000
WS_MAXIMIZE = 0x01000000
WS_CLIPCHILDREN = 0x02000000
WS_CLIPSIBLINGS = 0x04000000
WS_DISABLED = 0x08000000
WS_VISIBLE = 0x10000000
WS_ICONIC = 0x20000000
WS_MINIMIZE = 0x20000000
WS_CHILD = 0x40000000
WS_CHILDWINDOW = 0x40000000
WS_POPUP = 0x80000000
WS_POPUPWINDOW = WS_POPUP | WS_BORDER | WS_SYSMENU
WS_OVERLAPPEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX
WS_TILEDWINDOW = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX
// Extended window styles
WS_EX_LEFT = 0x00000000
WS_EX_LTRREADING = 0x00000000
WS_EX_RIGHTSCROLLBAR = 0x00000000
WS_EX_DLGMODALFRAME = 0x00000001
WS_EX_NOPARENTNOTIFY = 0x00000004
WS_EX_TOPMOST = 0x00000008
WS_EX_ACCEPTFILES = 0x00000010
WS_EX_TRANSPARENT = 0x00000020
WS_EX_MDICHILD = 0x00000040
WS_EX_TOOLWINDOW = 0x00000080
WS_EX_WINDOWEDGE = 0x00000100
WS_EX_CLIENTEDGE = 0x00000200
WS_EX_CONTEXTHELP = 0x00000400
WS_EX_RIGHT = 0x00001000
WS_EX_RTLREADING = 0x00002000
WS_EX_LEFTSCROLLBAR = 0x00004000
WS_EX_CONTROLPARENT = 0x00010000
WS_EX_STATICEDGE = 0x00020000
WS_EX_APPWINDOW = 0x00040000
WS_EX_LAYERED = 0x00080000
WS_EX_NOINHERITLAYOUT = 0x00100000
WS_EX_NOREDIRECTIONBITMAP = 0x00200000
WS_EX_LAYOUTRTL = 0x00400000
WS_EX_COMPOSITED = 0x02000000
WS_EX_NOACTIVATE = 0x08000000
WS_EX_OVERLAPPEDWINDOW = WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE
WS_EX_PALETTEWINDOW = WS_EX_WINDOWEDGE | WS_EX_TOOLWINDOW | WS_EX_TOPMOST
// Button styles
BS_DEFPUSHBUTTON = 0x0001
// Static control styles
SS_NOPREFIX = 0x0080
SS_EDITCONTROL = 0x2000
SS_WORDELLIPSIS = 0xc000
// Edic control styles
ES_PASSWORD = 0x0020
ES_AUTOHSCROLL = 0x0080
// List box control styles
LBS_EXTENDEDSEL = 0x0800
// Month calendar control styles
MCS_NOTODAY = 0x0010
// Progress bar control styles
PBS_SMOOTH = 0x0001
PBS_MARQUEE = 0x0008
// ShowWindow command
SW_HIDE = 0
SW_NORMAL = 1
SW_SHOWNORMAL = 1
SW_SHOWMINIMIZED = 2
SW_SHOWMAXIMIZED = 3
SW_MAXIMIZE = 3
SW_SHOWNOACTIVATE = 4
SW_SHOW = 5
SW_MINIMIZE = 6
SW_SHOWMINNOACTIVE = 7
SW_SHOWNA = 8
SW_RESTORE = 9
SW_SHOWDEFAULT = 10
SW_FORCEMINIMIZE = 11
// SetWindowPos flags
SWP_NOSIZE = 0x0001
SWP_NOMOVE = 0x0002
SWP_NOZORDER = 0x0004
SWP_NOREDRAW = 0x0008
SWP_NOACTIVATE = 0x0010
SWP_DRAWFRAME = 0x0020
SWP_FRAMECHANGED = 0x0020
SWP_SHOWWINDOW = 0x0040
SWP_HIDEWINDOW = 0x0080
SWP_NOCOPYBITS = 0x0100
SWP_NOREPOSITION = 0x0200
SWP_NOOWNERZORDER = 0x0200
SWP_NOSENDCHANGING = 0x0400
SWP_DEFERERASE = 0x2000
SWP_ASYNCWINDOWPOS = 0x4000
// Get/SetWindowLong ids
GWL_WNDPROC = -4
GWL_HINSTANCE = -6
GWL_ID = -12
GWL_STYLE = -16
GWL_EXSTYLE = -20
GWL_USERDATA = -21
// Get/SetSystemMetrics ids
SM_CXSCREEN = 0
SM_CYSCREEN = 1
// SystemParametersInfo ids
SPI_GETNONCLIENTMETRICS = 0x29
// WM_SYSCOMMAND wParam
SC_SIZE = 0xf000
SC_MOVE = 0xf010
SC_MINIMIZE = 0xf020
SC_MAXIMIZE = 0xf030
SC_NEXTWINDOW = 0xf040
SC_PREVWINDOW = 0xf050
SC_CLOSE = 0xf060
SC_VSCROLL = 0xf070
SC_HSCROLL = 0xf080
SC_MOUSEMENU = 0xf090
SC_KEYMENU = 0xf100
SC_RESTORE = 0xf120
SC_TASKLIST = 0xf130
SC_SCREENSAVE = 0xf140
SC_HOTKEY = 0xf150
SC_DEFAULT = 0xf160
SC_MONITORPOWER = 0xf170
SC_CONTEXTHELP = 0xf180
USER_DEFAULT_SCREEN_DPI = 96
DPI_AWARENESS_CONTEXT_UNAWARE = ^uintptr(1) + 1
@ -67,6 +226,7 @@ const (
IMAGE_ICON = 1
IMAGE_CURSOR = 2
// LoadResource (image/icon) flags
LR_DEFAULTCOLOR = 0x00000000
LR_MONOCHROME = 0x00000001
LR_LOADFROMFILE = 0x00000010
@ -171,6 +331,25 @@ type WNDCLASSEX struct {
IconSm Handle
}
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-nonclientmetricsw
type NONCLIENTMETRICS struct {
Size uint32
BorderWidth int32
ScrollWidth int32
ScrollHeight int32
CaptionWidth int32
CaptionHeight int32
CaptionFont LOGFONT
SmCaptionWidth int32
SmCaptionHeight int32
SmCaptionFont LOGFONT
MenuWidth int32
MenuHeight int32
MenuFont LOGFONT
StatusFont LOGFONT
MessageFont LOGFONT
}
//sys CreateIconFromResource(resBits []byte, icon bool, ver uint32) (ret Handle, err error) = user32.CreateIconFromResource
//sys CreateWindowEx(exStyle uint32, className *uint16, windowName *uint16, style uint32, x int, y int, width int, height int, parent HWND, menu Handle, instance Handle, param unsafe.Pointer) (ret HWND, err error) = user32.CreateWindowExW
//sys DestroyIcon(icon Handle) (err error) = user32.DestroyIcon
@ -202,5 +381,6 @@ type WNDCLASSEX struct {
//sys SetWindowPos(wnd HWND, wndInsertAfter HWND, x int, y int, cx int, cy int, flags int) (err error) = user32.SetWindowPos
//sys SetWindowText(wnd HWND, text *uint16) (err error) = user32.SetWindowTextW
//sys ShowWindow(wnd HWND, cmdShow int) (ok bool) = user32.ShowWindow
//sys SystemParametersInfo(action int, uiParam uintptr, pvParam unsafe.Pointer, winIni int) (err error) = user32.SystemParametersInfoW
//sys TranslateMessage(msg *MSG) (ok bool) = user32.TranslateMessage
//sys UnregisterClass(className *uint16, instance Handle) (err error) = user32.UnregisterClassW

View File

@ -96,6 +96,7 @@ var (
procSetWindowPos = moduser32.NewProc("SetWindowPos")
procSetWindowTextW = moduser32.NewProc("SetWindowTextW")
procShowWindow = moduser32.NewProc("ShowWindow")
procSystemParametersInfoW = moduser32.NewProc("SystemParametersInfoW")
procTranslateMessage = moduser32.NewProc("TranslateMessage")
procUnregisterClassW = moduser32.NewProc("UnregisterClassW")
procWTSSendMessageW = modwtsapi32.NewProc("WTSSendMessageW")
@ -295,6 +296,11 @@ func EnableWindow(wnd HWND, enable bool) (ok bool) {
return
}
func EnumChildWindows(parent HWND, enumFunc uintptr, lparam unsafe.Pointer) {
syscall.Syscall(procEnumChildWindows.Addr(), 3, uintptr(parent), uintptr(enumFunc), uintptr(lparam))
return
}
func EnumWindows(enumFunc uintptr, lparam unsafe.Pointer) (err error) {
r1, _, e1 := syscall.Syscall(procEnumChildWindows.Addr(), 2, uintptr(enumFunc), uintptr(lparam), 0)
if r1 == 0 {
@ -303,11 +309,6 @@ func EnumWindows(enumFunc uintptr, lparam unsafe.Pointer) (err error) {
return
}
func EnumChildWindows(parent HWND, enumFunc uintptr, lparam unsafe.Pointer) {
syscall.Syscall(procEnumChildWindows.Addr(), 3, uintptr(parent), uintptr(enumFunc), uintptr(lparam))
return
}
func GetDlgCtrlID(wnd HWND) (ret int) {
r0, _, _ := syscall.Syscall(procGetDlgCtrlID.Addr(), 1, uintptr(wnd), 0, 0)
ret = int(r0)
@ -465,6 +466,14 @@ func ShowWindow(wnd HWND, cmdShow int) (ok bool) {
return
}
func SystemParametersInfo(action int, uiParam uintptr, pvParam unsafe.Pointer, winIni int) (err error) {
r1, _, e1 := syscall.Syscall6(procSystemParametersInfoW.Addr(), 4, uintptr(action), uintptr(uiParam), uintptr(pvParam), uintptr(winIni), 0, 0)
if r1 == 0 {
err = errnoErr(e1)
}
return
}
func TranslateMessage(msg *MSG) (ok bool) {
r0, _, _ := syscall.Syscall(procTranslateMessage.Addr(), 1, uintptr(unsafe.Pointer(msg)), 0, 0)
ok = r0 != 0

View File

@ -75,38 +75,35 @@ func (dlg *listDialog) setup(text string, opts options) ([]string, error) {
defer win.UnregisterClass(cls, instance)
owner, _ := opts.attach.(win.HWND)
dlg.wnd, _ = win.CreateWindowEx(_WS_EX_CONTROLPARENT|_WS_EX_WINDOWEDGE|_WS_EX_DLGMODALFRAME,
cls, strptr(*opts.title),
_WS_POPUPWINDOW|_WS_CLIPSIBLINGS|_WS_DLGFRAME,
_CW_USEDEFAULT, _CW_USEDEFAULT,
dlg.wnd, _ = win.CreateWindowEx(_WS_EX_ZEN_DIALOG,
cls, strptr(*opts.title), _WS_ZEN_DIALOG,
win.CW_USEDEFAULT, win.CW_USEDEFAULT,
281, 281, owner, 0, instance, unsafe.Pointer(dlg))
dlg.textCtl, _ = win.CreateWindowEx(0,
strptr("STATIC"), strptr(text),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_SS_WORDELLIPSIS|_SS_EDITCONTROL|_SS_NOPREFIX,
strptr("STATIC"), strptr(text), _WS_ZEN_LABEL,
12, 10, 241, 16, dlg.wnd, 0, instance, nil)
var flags uint32 = _WS_CHILD | _WS_VISIBLE | _WS_GROUP | _WS_TABSTOP | _WS_VSCROLL
var flags uint32 = _WS_ZEN_CONTROL | win.WS_VSCROLL
if dlg.multiple {
flags |= _LBS_EXTENDEDSEL
flags |= win.LBS_EXTENDEDSEL
}
dlg.listCtl, _ = win.CreateWindowEx(_WS_EX_CLIENTEDGE,
strptr("LISTBOX"), strptr(opts.entryText),
flags,
dlg.listCtl, _ = win.CreateWindowEx(win.WS_EX_CLIENTEDGE,
strptr("LISTBOX"), strptr(opts.entryText), flags,
12, 30, 241, 164, dlg.wnd, 0, instance, nil)
dlg.okBtn, _ = win.CreateWindowEx(0,
strptr("BUTTON"), strptr(*opts.okLabel),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP|_BS_DEFPUSHBUTTON,
_WS_ZEN_BUTTON|win.BS_DEFPUSHBUTTON,
12, 206, 75, 24, dlg.wnd, win.IDOK, instance, nil)
dlg.cancelBtn, _ = win.CreateWindowEx(0,
strptr("BUTTON"), strptr(*opts.cancelLabel),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP,
_WS_ZEN_BUTTON,
12, 206, 75, 24, dlg.wnd, win.IDCANCEL, instance, nil)
if opts.extraButton != nil {
dlg.extraBtn, _ = win.CreateWindowEx(0,
strptr("BUTTON"), strptr(*opts.extraButton),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP,
_WS_ZEN_BUTTON,
12, 206, 75, 24, dlg.wnd, win.IDNO, instance, nil)
}
@ -117,7 +114,7 @@ func (dlg *listDialog) setup(text string, opts options) ([]string, error) {
dlg.layout(getDPI(dlg.wnd))
centerWindow(dlg.wnd)
win.SetFocus(dlg.listCtl)
win.ShowWindow(dlg.wnd, _SW_NORMAL)
win.ShowWindow(dlg.wnd, win.SW_NORMAL)
if opts.ctx != nil {
wait := make(chan struct{})
@ -125,7 +122,7 @@ func (dlg *listDialog) setup(text string, opts options) ([]string, error) {
go func() {
select {
case <-opts.ctx.Done():
win.SendMessage(dlg.wnd, win.WM_SYSCOMMAND, _SC_CLOSE, 0)
win.SendMessage(dlg.wnd, win.WM_SYSCOMMAND, win.SC_CLOSE, 0)
case <-wait:
}
}()
@ -147,16 +144,16 @@ func (dlg *listDialog) layout(dpi dpi) {
win.SendMessage(dlg.okBtn, win.WM_SETFONT, font, 1)
win.SendMessage(dlg.cancelBtn, win.WM_SETFONT, font, 1)
win.SendMessage(dlg.extraBtn, win.WM_SETFONT, font, 1)
win.SetWindowPos(dlg.wnd, 0, 0, 0, dpi.scale(281), dpi.scale(281), _SWP_NOZORDER|_SWP_NOMOVE)
win.SetWindowPos(dlg.textCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), _SWP_NOZORDER)
win.SetWindowPos(dlg.listCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(164), _SWP_NOZORDER)
win.SetWindowPos(dlg.wnd, 0, 0, 0, dpi.scale(281), dpi.scale(281), win.SWP_NOMOVE|win.SWP_NOZORDER)
win.SetWindowPos(dlg.textCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), win.SWP_NOZORDER)
win.SetWindowPos(dlg.listCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(164), win.SWP_NOZORDER)
if dlg.extraBtn == 0 {
win.SetWindowPos(dlg.okBtn, 0, dpi.scale(95), dpi.scale(206), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(206), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.okBtn, 0, dpi.scale(95), dpi.scale(206), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
win.SetWindowPos(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(206), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
} else {
win.SetWindowPos(dlg.okBtn, 0, dpi.scale(12), dpi.scale(206), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.extraBtn, 0, dpi.scale(95), dpi.scale(206), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(206), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.okBtn, 0, dpi.scale(12), dpi.scale(206), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
win.SetWindowPos(dlg.extraBtn, 0, dpi.scale(95), dpi.scale(206), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
win.SetWindowPos(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(206), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
}
}

View File

@ -92,7 +92,7 @@ func (d *progressDialog) Done() <-chan struct{} {
func (d *progressDialog) Complete() error {
select {
default:
win.SetWindowLong(d.progCtl, _GWL_STYLE, _WS_CHILD|_WS_VISIBLE|_PBS_SMOOTH)
win.SetWindowLong(d.progCtl, win.GWL_STYLE, win.WS_CHILD|win.WS_VISIBLE|win.PBS_SMOOTH)
win.SendMessage(d.progCtl, win.PBM_SETRANGE32, 0, 1)
win.SendMessage(d.progCtl, win.PBM_SETPOS, 1, 0)
win.EnableWindow(d.okBtn, true)
@ -104,7 +104,7 @@ func (d *progressDialog) Complete() error {
}
func (d *progressDialog) Close() error {
win.SendMessage(d.wnd, win.WM_SYSCOMMAND, _SC_CLOSE, 0)
win.SendMessage(d.wnd, win.WM_SYSCOMMAND, win.SC_CLOSE, 0)
<-d.done
if d.err == ErrCanceled {
return nil
@ -138,46 +138,44 @@ func (dlg *progressDialog) setup(opts options) error {
defer win.UnregisterClass(cls, instance)
owner, _ := opts.attach.(win.HWND)
dlg.wnd, _ = win.CreateWindowEx(_WS_EX_CONTROLPARENT|_WS_EX_WINDOWEDGE|_WS_EX_DLGMODALFRAME,
cls, strptr(*opts.title),
_WS_POPUPWINDOW|_WS_CLIPSIBLINGS|_WS_DLGFRAME,
_CW_USEDEFAULT, _CW_USEDEFAULT,
dlg.wnd, _ = win.CreateWindowEx(_WS_EX_ZEN_DIALOG,
cls, strptr(*opts.title), _WS_ZEN_DIALOG,
win.CW_USEDEFAULT, win.CW_USEDEFAULT,
281, 133, owner, 0, instance, unsafe.Pointer(dlg))
dlg.textCtl, _ = win.CreateWindowEx(0,
strptr("STATIC"), nil,
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_SS_WORDELLIPSIS|_SS_EDITCONTROL|_SS_NOPREFIX,
strptr("STATIC"), nil, _WS_ZEN_LABEL,
12, 10, 241, 16, dlg.wnd, 0, instance, nil)
var flags uint32 = _WS_CHILD | _WS_VISIBLE | _PBS_SMOOTH
var flags uint32 = win.WS_CHILD | win.WS_VISIBLE | win.PBS_SMOOTH
if opts.maxValue < 0 {
flags |= _PBS_MARQUEE
flags |= win.PBS_MARQUEE
}
dlg.progCtl, _ = win.CreateWindowEx(0,
strptr(_PROGRESS_CLASS),
strptr(win.PROGRESS_CLASS),
nil, flags,
12, 30, 241, 16, dlg.wnd, 0, instance, nil)
dlg.okBtn, _ = win.CreateWindowEx(0,
strptr("BUTTON"), strptr(*opts.okLabel),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP|_BS_DEFPUSHBUTTON|_WS_DISABLED,
_WS_ZEN_BUTTON|win.BS_DEFPUSHBUTTON|win.WS_DISABLED,
12, 58, 75, 24, dlg.wnd, win.IDOK, instance, nil)
if !opts.noCancel {
dlg.cancelBtn, _ = win.CreateWindowEx(0,
strptr("BUTTON"), strptr(*opts.cancelLabel),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP,
_WS_ZEN_BUTTON,
12, 58, 75, 24, dlg.wnd, win.IDCANCEL, instance, nil)
}
if opts.extraButton != nil {
dlg.extraBtn, _ = win.CreateWindowEx(0,
strptr("BUTTON"), strptr(*opts.extraButton),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP,
_WS_ZEN_BUTTON,
12, 58, 75, 24, dlg.wnd, win.IDNO, instance, nil)
}
dlg.layout(getDPI(dlg.wnd))
centerWindow(dlg.wnd)
win.ShowWindow(dlg.wnd, _SW_NORMAL)
win.ShowWindow(dlg.wnd, win.SW_NORMAL)
if opts.maxValue < 0 {
win.SendMessage(dlg.progCtl, win.PBM_SETMARQUEE, 1, 0)
} else {
@ -191,7 +189,7 @@ func (dlg *progressDialog) setup(opts options) error {
go func() {
select {
case <-opts.ctx.Done():
win.SendMessage(dlg.wnd, win.WM_SYSCOMMAND, _SC_CLOSE, 0)
win.SendMessage(dlg.wnd, win.WM_SYSCOMMAND, win.SC_CLOSE, 0)
case <-wait:
}
}()
@ -212,24 +210,24 @@ func (d *progressDialog) layout(dpi dpi) {
win.SendMessage(d.okBtn, win.WM_SETFONT, font, 1)
win.SendMessage(d.cancelBtn, win.WM_SETFONT, font, 1)
win.SendMessage(d.extraBtn, win.WM_SETFONT, font, 1)
win.SetWindowPos(d.wnd, 0, 0, 0, dpi.scale(281), dpi.scale(133), _SWP_NOZORDER|_SWP_NOMOVE)
win.SetWindowPos(d.textCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), _SWP_NOZORDER)
win.SetWindowPos(d.progCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(16), _SWP_NOZORDER)
win.SetWindowPos(d.wnd, 0, 0, 0, dpi.scale(281), dpi.scale(133), win.SWP_NOMOVE|win.SWP_NOZORDER)
win.SetWindowPos(d.textCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), win.SWP_NOZORDER)
win.SetWindowPos(d.progCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(16), win.SWP_NOZORDER)
if d.extraBtn == 0 {
if d.cancelBtn == 0 {
win.SetWindowPos(d.okBtn, 0, dpi.scale(178), dpi.scale(58), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(d.okBtn, 0, dpi.scale(178), dpi.scale(58), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
} else {
win.SetWindowPos(d.okBtn, 0, dpi.scale(95), dpi.scale(58), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(d.cancelBtn, 0, dpi.scale(178), dpi.scale(58), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(d.okBtn, 0, dpi.scale(95), dpi.scale(58), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
win.SetWindowPos(d.cancelBtn, 0, dpi.scale(178), dpi.scale(58), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
}
} else {
if d.cancelBtn == 0 {
win.SetWindowPos(d.okBtn, 0, dpi.scale(95), dpi.scale(58), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(d.extraBtn, 0, dpi.scale(178), dpi.scale(58), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(d.okBtn, 0, dpi.scale(95), dpi.scale(58), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
win.SetWindowPos(d.extraBtn, 0, dpi.scale(178), dpi.scale(58), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
} else {
win.SetWindowPos(d.okBtn, 0, dpi.scale(12), dpi.scale(58), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(d.extraBtn, 0, dpi.scale(95), dpi.scale(58), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(d.cancelBtn, 0, dpi.scale(178), dpi.scale(58), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(d.okBtn, 0, dpi.scale(12), dpi.scale(58), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
win.SetWindowPos(d.extraBtn, 0, dpi.scale(95), dpi.scale(58), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
win.SetWindowPos(d.cancelBtn, 0, dpi.scale(178), dpi.scale(58), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
}
}
}

View File

@ -68,52 +68,49 @@ func (dlg *passwordDialog) setup(opts options) (string, string, error) {
defer win.UnregisterClass(cls, instance)
owner, _ := opts.attach.(win.HWND)
dlg.wnd, _ = win.CreateWindowEx(_WS_EX_CONTROLPARENT|_WS_EX_WINDOWEDGE|_WS_EX_DLGMODALFRAME,
cls, strptr(*opts.title),
_WS_POPUPWINDOW|_WS_CLIPSIBLINGS|_WS_DLGFRAME,
_CW_USEDEFAULT, _CW_USEDEFAULT,
dlg.wnd, _ = win.CreateWindowEx(_WS_EX_ZEN_DIALOG,
cls, strptr(*opts.title), _WS_ZEN_DIALOG,
win.CW_USEDEFAULT, win.CW_USEDEFAULT,
281, 191, owner, 0, instance, unsafe.Pointer(dlg))
dlg.uTextCtl, _ = win.CreateWindowEx(0,
strptr("STATIC"), strptr("Username:"),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_SS_WORDELLIPSIS|_SS_EDITCONTROL|_SS_NOPREFIX,
_WS_ZEN_LABEL,
12, 10, 241, 16, dlg.wnd, 0, instance, nil)
var flags uint32 = _WS_CHILD | _WS_VISIBLE | _WS_GROUP | _WS_TABSTOP | _ES_AUTOHSCROLL
dlg.uEditCtl, _ = win.CreateWindowEx(_WS_EX_CLIENTEDGE,
dlg.uEditCtl, _ = win.CreateWindowEx(win.WS_EX_CLIENTEDGE,
strptr("EDIT"), nil,
flags,
_WS_ZEN_CONTROL|win.ES_AUTOHSCROLL,
12, 30, 241, 24, dlg.wnd, 0, instance, nil)
dlg.pTextCtl, _ = win.CreateWindowEx(0,
strptr("STATIC"), strptr("Password:"),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_SS_WORDELLIPSIS|_SS_EDITCONTROL|_SS_NOPREFIX,
strptr("STATIC"), strptr("Password:"), _WS_ZEN_LABEL,
12, 60, 241, 16, dlg.wnd, 0, instance, nil)
dlg.pEditCtl, _ = win.CreateWindowEx(_WS_EX_CLIENTEDGE,
dlg.pEditCtl, _ = win.CreateWindowEx(win.WS_EX_CLIENTEDGE,
strptr("EDIT"), nil,
flags|_ES_PASSWORD,
_WS_ZEN_CONTROL|win.ES_AUTOHSCROLL|win.ES_PASSWORD,
12, 80, 241, 24, dlg.wnd, 0, instance, nil)
dlg.okBtn, _ = win.CreateWindowEx(0,
strptr("BUTTON"), strptr(*opts.okLabel),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP|_BS_DEFPUSHBUTTON,
_WS_ZEN_BUTTON|win.BS_DEFPUSHBUTTON,
12, 116, 75, 24, dlg.wnd, win.IDOK, instance, nil)
dlg.cancelBtn, _ = win.CreateWindowEx(0,
strptr("BUTTON"), strptr(*opts.cancelLabel),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP,
_WS_ZEN_BUTTON,
12, 116, 75, 24, dlg.wnd, win.IDCANCEL, instance, nil)
if opts.extraButton != nil {
dlg.extraBtn, _ = win.CreateWindowEx(0,
strptr("BUTTON"), strptr(*opts.extraButton),
_WS_CHILD|_WS_VISIBLE|_WS_GROUP|_WS_TABSTOP,
_WS_ZEN_BUTTON,
12, 116, 75, 24, dlg.wnd, win.IDNO, instance, nil)
}
dlg.layout(getDPI(dlg.wnd))
centerWindow(dlg.wnd)
win.SetFocus(dlg.uEditCtl)
win.ShowWindow(dlg.wnd, _SW_NORMAL)
win.ShowWindow(dlg.wnd, win.SW_NORMAL)
win.SendMessage(dlg.uEditCtl, win.EM_SETSEL, 0, intptr(-1))
if opts.ctx != nil {
@ -122,7 +119,7 @@ func (dlg *passwordDialog) setup(opts options) (string, string, error) {
go func() {
select {
case <-opts.ctx.Done():
win.SendMessage(dlg.wnd, win.WM_SYSCOMMAND, _SC_CLOSE, 0)
win.SendMessage(dlg.wnd, win.WM_SYSCOMMAND, win.SC_CLOSE, 0)
case <-wait:
}
}()
@ -146,18 +143,18 @@ func (dlg *passwordDialog) layout(dpi dpi) {
win.SendMessage(dlg.okBtn, win.WM_SETFONT, font, 1)
win.SendMessage(dlg.cancelBtn, win.WM_SETFONT, font, 1)
win.SendMessage(dlg.extraBtn, win.WM_SETFONT, font, 1)
win.SetWindowPos(dlg.wnd, 0, 0, 0, dpi.scale(281), dpi.scale(191), _SWP_NOZORDER|_SWP_NOMOVE)
win.SetWindowPos(dlg.uTextCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), _SWP_NOZORDER)
win.SetWindowPos(dlg.uEditCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.pTextCtl, 0, dpi.scale(12), dpi.scale(60), dpi.scale(241), dpi.scale(16), _SWP_NOZORDER)
win.SetWindowPos(dlg.pEditCtl, 0, dpi.scale(12), dpi.scale(80), dpi.scale(241), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.wnd, 0, 0, 0, dpi.scale(281), dpi.scale(191), win.SWP_NOMOVE|win.SWP_NOZORDER)
win.SetWindowPos(dlg.uTextCtl, 0, dpi.scale(12), dpi.scale(10), dpi.scale(241), dpi.scale(16), win.SWP_NOZORDER)
win.SetWindowPos(dlg.uEditCtl, 0, dpi.scale(12), dpi.scale(30), dpi.scale(241), dpi.scale(24), win.SWP_NOZORDER)
win.SetWindowPos(dlg.pTextCtl, 0, dpi.scale(12), dpi.scale(60), dpi.scale(241), dpi.scale(16), win.SWP_NOZORDER)
win.SetWindowPos(dlg.pEditCtl, 0, dpi.scale(12), dpi.scale(80), dpi.scale(241), dpi.scale(24), win.SWP_NOZORDER)
if dlg.extraBtn == 0 {
win.SetWindowPos(dlg.okBtn, 0, dpi.scale(95), dpi.scale(116), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(116), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.okBtn, 0, dpi.scale(95), dpi.scale(116), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
win.SetWindowPos(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(116), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
} else {
win.SetWindowPos(dlg.okBtn, 0, dpi.scale(12), dpi.scale(116), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.extraBtn, 0, dpi.scale(95), dpi.scale(116), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(116), dpi.scale(75), dpi.scale(24), _SWP_NOZORDER)
win.SetWindowPos(dlg.okBtn, 0, dpi.scale(12), dpi.scale(116), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
win.SetWindowPos(dlg.extraBtn, 0, dpi.scale(95), dpi.scale(116), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
win.SetWindowPos(dlg.cancelBtn, 0, dpi.scale(178), dpi.scale(116), dpi.scale(75), dpi.scale(24), win.SWP_NOZORDER)
}
}

View File

@ -19,10 +19,17 @@ import (
var (
user32 = windows.NewLazySystemDLL("user32.dll")
callNextHookEx = user32.NewProc("CallNextHookEx")
setWindowsHookEx = user32.NewProc("SetWindowsHookExW")
systemParametersInfo = user32.NewProc("SystemParametersInfoW")
unhookWindowsHookEx = user32.NewProc("UnhookWindowsHookEx")
callNextHookEx = user32.NewProc("CallNextHookEx")
setWindowsHookEx = user32.NewProc("SetWindowsHookExW")
unhookWindowsHookEx = user32.NewProc("UnhookWindowsHookEx")
)
const (
_WS_ZEN_DIALOG = win.WS_POPUPWINDOW | win.WS_CLIPSIBLINGS | win.WS_DLGFRAME
_WS_EX_ZEN_DIALOG = win.WS_EX_CONTROLPARENT | win.WS_EX_WINDOWEDGE | win.WS_EX_DLGMODALFRAME
_WS_ZEN_LABEL = win.WS_CHILD | win.WS_VISIBLE | win.WS_GROUP | win.SS_WORDELLIPSIS | win.SS_EDITCONTROL | win.SS_NOPREFIX
_WS_ZEN_CONTROL = win.WS_CHILD | win.WS_VISIBLE | win.WS_GROUP | win.WS_TABSTOP
_WS_ZEN_BUTTON = _WS_ZEN_CONTROL
)
func intptr(i int64) uintptr { return uintptr(i) }
@ -125,12 +132,12 @@ func newDialogHook(ctx context.Context, icon any, title *string, init func(wnd w
}
func dialogHookProc(code int32, wparam uintptr, lparam *_CWPRETSTRUCT) uintptr {
if lparam.Message == 0x0110 { // WM_INITDIALOG
if lparam.Message == win.WM_INITDIALOG {
tid := win.GetCurrentThreadId()
hook := (*dialogHook)(loadBackRef(uintptr(tid)))
atomic.StoreUintptr(&hook.wnd, uintptr(lparam.Wnd))
if hook.ctx != nil && hook.ctx.Err() != nil {
win.SendMessage(lparam.Wnd, win.WM_SYSCOMMAND, _SC_CLOSE, 0)
win.SendMessage(lparam.Wnd, win.WM_SYSCOMMAND, win.SC_CLOSE, 0)
} else {
if hook.icon != nil {
icon := getIcon(hook.icon)
@ -164,7 +171,7 @@ func (h *dialogHook) wait() {
select {
case <-h.ctx.Done():
if wnd := atomic.LoadUintptr(&h.wnd); wnd != 0 {
win.SendMessage(win.HWND(wnd), win.WM_SYSCOMMAND, _SC_CLOSE, 0)
win.SendMessage(win.HWND(wnd), win.WM_SYSCOMMAND, win.SC_CLOSE, 0)
}
case <-h.done:
}
@ -230,10 +237,10 @@ type font struct {
}
func getFont() font {
var metrics _NONCLIENTMETRICS
var metrics win.NONCLIENTMETRICS
metrics.Size = uint32(unsafe.Sizeof(metrics))
systemParametersInfo.Call(0x29, // SPI_GETNONCLIENTMETRICS
unsafe.Sizeof(metrics), uintptr(unsafe.Pointer(&metrics)), 0)
win.SystemParametersInfo(win.SPI_GETNONCLIENTMETRICS,
unsafe.Sizeof(metrics), unsafe.Pointer(&metrics), 0)
return font{logical: metrics.MessageFont}
}
@ -310,9 +317,9 @@ func (i *icon) delete() {
func centerWindow(wnd win.HWND) {
var rect win.RECT
win.GetWindowRect(wnd, &rect)
x := (win.GetSystemMetrics(0 /* SM_CXSCREEN */) - int(rect.Right-rect.Left)) / 2
y := (win.GetSystemMetrics(1 /* SM_CYSCREEN */) - int(rect.Bottom-rect.Top)) / 2
win.SetWindowPos(wnd, 0, x, y, 0, 0, 0x5) // SWP_NOZORDER|SWP_NOSIZE
x := win.GetSystemMetrics(win.SM_CXSCREEN) - int(rect.Right-rect.Left)
y := win.GetSystemMetrics(win.SM_CYSCREEN) - int(rect.Bottom-rect.Top)
win.SetWindowPos(wnd, 0, x/2, y/2, 0, 0, win.SWP_NOZORDER|win.SWP_NOSIZE)
}
func getWindowString(wnd win.HWND) string {
@ -369,25 +376,6 @@ type _CWPRETSTRUCT struct {
Wnd win.HWND
}
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-nonclientmetricsw
type _NONCLIENTMETRICS struct {
Size uint32
BorderWidth int32
ScrollWidth int32
ScrollHeight int32
CaptionWidth int32
CaptionHeight int32
CaptionFont win.LOGFONT
SmCaptionWidth int32
SmCaptionHeight int32
SmCaptionFont win.LOGFONT
MenuWidth int32
MenuHeight int32
MenuFont win.LOGFONT
StatusFont win.LOGFONT
MessageFont win.LOGFONT
}
// https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-systemtime
type _SYSTEMTIME struct {
year uint16