From d95237cefbbdbe3aa0b7ce315f5998b7181dcbe0 Mon Sep 17 00:00:00 2001 From: Nuno Cruces Date: Fri, 24 Jan 2020 13:59:03 +0000 Subject: [PATCH] Color dialog title (windows). --- color_windows.go | 8 ++++++++ util_windows.go | 18 ++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/color_windows.go b/color_windows.go index dd26d78..e24336a 100644 --- a/color_windows.go +++ b/color_windows.go @@ -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 diff --git a/util_windows.go b/util_windows.go index d24d292..0a211b8 100644 --- a/util_windows.go +++ b/util_windows.go @@ -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) {