Color dialog title (windows).

This commit is contained in:
Nuno Cruces 2020-01-24 13:59:03 +00:00
parent 5633d0d7e6
commit d95237cefb
2 changed files with 26 additions and 0 deletions

View file

@ -46,6 +46,14 @@ func selectColor(options ...Option) (color.Color, error) {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
if opts.title != "" {
hook, err := hookDialogTitle(opts.title)
if hook == 0 {
return nil, err
}
defer unhookWindowsHookEx.Call(hook)
}
n, _, _ := chooseColor.Call(uintptr(unsafe.Pointer(&args)))
// save custom colors back

View file

@ -49,6 +49,24 @@ type _CWPRETSTRUCT struct {
Wnd uintptr
}
func hookDialogTitle(title string) (hook uintptr, err error) {
tid, _, _ := getCurrentThreadId.Call()
hook, _, err = setWindowsHookEx.Call(12, // WH_CALLWNDPROCRET
syscall.NewCallback(func(code int, wparam uintptr, lparam *_CWPRETSTRUCT) uintptr {
if lparam.Message == 0x0110 { // WM_INITDIALOG
name := [7]uint16{}
getClassName.Call(lparam.Wnd, uintptr(unsafe.Pointer(&name)), uintptr(len(name)))
if syscall.UTF16ToString(name[:]) == "#32770" { // The class for a dialog box
ptr := syscall.StringToUTF16Ptr(title)
setWindowText.Call(lparam.Wnd, uintptr(unsafe.Pointer(ptr)))
}
}
next, _, _ := callNextHookEx.Call(hook, uintptr(code), wparam, uintptr(unsafe.Pointer(lparam)))
return next
}), 0, tid)
return
}
type _COMObject struct{}
func (o *_COMObject) Call(trap uintptr, a ...uintptr) (r1, r2 uintptr, lastErr error) {