Refactor, docs.
This commit is contained in:
parent
408d1642d3
commit
14ebdecd22
2 changed files with 45 additions and 45 deletions
|
@ -25,7 +25,7 @@ func selectColor(opts options) (color.Color, error) {
|
||||||
customColors := savedColors
|
customColors := savedColors
|
||||||
colorsMutex.Unlock()
|
colorsMutex.Unlock()
|
||||||
|
|
||||||
var args _CHOOSECOLORW
|
var args _CHOOSECOLOR
|
||||||
args.StructSize = uint32(unsafe.Sizeof(args))
|
args.StructSize = uint32(unsafe.Sizeof(args))
|
||||||
args.CustColors = &customColors
|
args.CustColors = &customColors
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ func selectColor(opts options) (color.Color, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://docs.microsoft.com/en-us/windows/win32/api/commdlg/ns-commdlg-choosecolorw-r1
|
// https://docs.microsoft.com/en-us/windows/win32/api/commdlg/ns-commdlg-choosecolorw-r1
|
||||||
type _CHOOSECOLORW struct {
|
type _CHOOSECOLOR struct {
|
||||||
StructSize uint32
|
StructSize uint32
|
||||||
Owner uintptr
|
Owner uintptr
|
||||||
Instance uintptr
|
Instance uintptr
|
||||||
|
|
|
@ -29,7 +29,7 @@ func password(opts options) (string, string, bool, error) {
|
||||||
var (
|
var (
|
||||||
gdi32 = syscall.NewLazyDLL("gdi32.dll")
|
gdi32 = syscall.NewLazyDLL("gdi32.dll")
|
||||||
|
|
||||||
createWindowExW = user32.NewProc("CreateWindowExW")
|
createWindowEx = user32.NewProc("CreateWindowExW")
|
||||||
defWindowProcW = user32.NewProc("DefWindowProcW")
|
defWindowProcW = user32.NewProc("DefWindowProcW")
|
||||||
destroyWindowW = user32.NewProc("DestroyWindow")
|
destroyWindowW = user32.NewProc("DestroyWindow")
|
||||||
dispatchMessage = user32.NewProc("DispatchMessageW")
|
dispatchMessage = user32.NewProc("DispatchMessageW")
|
||||||
|
@ -104,7 +104,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-wndclassexw
|
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-wndclassexw
|
||||||
type _WNDCLASSEXW struct {
|
type _WNDCLASSEX struct {
|
||||||
Size uint32
|
Size uint32
|
||||||
Style uint32
|
Style uint32
|
||||||
WndProc uintptr
|
WndProc uintptr
|
||||||
|
@ -119,7 +119,7 @@ type _WNDCLASSEXW struct {
|
||||||
IconSm uintptr
|
IconSm uintptr
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://docs.microsoft.com/en-ie/windows/win32/api/winuser/ns-winuser-msg
|
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-msg
|
||||||
type _MSG struct {
|
type _MSG struct {
|
||||||
Owner syscall.Handle
|
Owner syscall.Handle
|
||||||
Message uint32
|
Message uint32
|
||||||
|
@ -129,41 +129,41 @@ type _MSG struct {
|
||||||
Pt _POINT
|
Pt _POINT
|
||||||
}
|
}
|
||||||
|
|
||||||
// nonClientMetricsW https://msdn.microsoft.com/en-us/library/windows/desktop/ff729175.aspx
|
// https://docs.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-nonclientmetricsw
|
||||||
type nonClientMetricsW struct {
|
type _NONCLIENTMETRICS struct {
|
||||||
cbSize uint32
|
Size uint32
|
||||||
iBorderWidth int32
|
BorderWidth int32
|
||||||
iScrollWidth int32
|
ScrollWidth int32
|
||||||
iScrollHeight int32
|
ScrollHeight int32
|
||||||
iCaptionWidth int32
|
CaptionWidth int32
|
||||||
iCaptionHeight int32
|
CaptionHeight int32
|
||||||
lfCaptionFont logfontW
|
CaptionFont _LOGFONT
|
||||||
iSmCaptionWidth int32
|
SmCaptionWidth int32
|
||||||
iSmCaptionHeight int32
|
SmCaptionHeight int32
|
||||||
lfSmCaptionFont logfontW
|
SmCaptionFont _LOGFONT
|
||||||
iMenuWidth int32
|
MenuWidth int32
|
||||||
iMenuHeight int32
|
MenuHeight int32
|
||||||
lfMenuFont logfontW
|
MenuFont _LOGFONT
|
||||||
lfStatusFont logfontW
|
StatusFont _LOGFONT
|
||||||
lfMessageFont logfontW
|
MessageFont _LOGFONT
|
||||||
}
|
}
|
||||||
|
|
||||||
// logfontW https://msdn.microsoft.com/en-us/library/windows/desktop/dd145037.aspx
|
// https://docs.microsoft.com/en-us/windows/win32/api/wingdi/ns-wingdi-logfontw
|
||||||
type logfontW struct {
|
type _LOGFONT struct {
|
||||||
lfHeight int32
|
Height int32
|
||||||
lfWidth int32
|
Width int32
|
||||||
lfEscapement int32
|
Escapement int32
|
||||||
lfOrientation int32
|
Orientation int32
|
||||||
lfWeight int32
|
Weight int32
|
||||||
lfItalic byte
|
Italic byte
|
||||||
lfUnderline byte
|
Underline byte
|
||||||
lfStrikeOut byte
|
StrikeOut byte
|
||||||
lfCharSet byte
|
CharSet byte
|
||||||
lfOutPrecision byte
|
OutPrecision byte
|
||||||
lfClipPrecision byte
|
ClipPrecision byte
|
||||||
lfQuality byte
|
Quality byte
|
||||||
lfPitchAndFamily byte
|
PitchAndFamily byte
|
||||||
lfFaceName [32]uint16
|
FaceName [32]uint16
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://docs.microsoft.com/en-us/windows/win32/api/windef/ns-windef-point
|
// https://docs.microsoft.com/en-us/windows/win32/api/windef/ns-windef-point
|
||||||
|
@ -190,7 +190,7 @@ func getModuleHandle() (syscall.Handle, error) {
|
||||||
|
|
||||||
func createWindow(exStyle uint64, className, windowName string, style uint64, x, y, width, height int64,
|
func createWindow(exStyle uint64, className, windowName string, style uint64, x, y, width, height int64,
|
||||||
parent, menu, instance syscall.Handle) (syscall.Handle, error) {
|
parent, menu, instance syscall.Handle) (syscall.Handle, error) {
|
||||||
ret, _, err := createWindowExW.Call(uintptr(exStyle), uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(className))),
|
ret, _, err := createWindowEx.Call(uintptr(exStyle), uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(className))),
|
||||||
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(windowName))), uintptr(style), uintptr(x), uintptr(y),
|
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(windowName))), uintptr(style), uintptr(x), uintptr(y),
|
||||||
uintptr(width), uintptr(height), uintptr(parent), uintptr(menu), uintptr(instance), uintptr(0))
|
uintptr(width), uintptr(height), uintptr(parent), uintptr(menu), uintptr(instance), uintptr(0))
|
||||||
|
|
||||||
|
@ -215,7 +215,7 @@ func defWindowProc(hwnd syscall.Handle, msg uint32, wparam, lparam uintptr) uint
|
||||||
return uintptr(ret)
|
return uintptr(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
func registerClassEx(wcx *_WNDCLASSEXW) (uint16, error) {
|
func registerClassEx(wcx *_WNDCLASSEX) (uint16, error) {
|
||||||
ret, _, err := registerClassExW.Call(uintptr(unsafe.Pointer(wcx)))
|
ret, _, err := registerClassExW.Call(uintptr(unsafe.Pointer(wcx)))
|
||||||
|
|
||||||
if ret == 0 {
|
if ret == 0 {
|
||||||
|
@ -254,7 +254,7 @@ func systemParametersInfo(uiAction, uiParam uint32, pvParam unsafe.Pointer, fWin
|
||||||
return int32(ret) != 0
|
return int32(ret) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func createFontIndirect(lplf *logfontW) uintptr {
|
func createFontIndirect(lplf *_LOGFONT) uintptr {
|
||||||
ret, _, _ := createFontIndirectW.Call(uintptr(unsafe.Pointer(lplf)), 0, 0)
|
ret, _, _ := createFontIndirectW.Call(uintptr(unsafe.Pointer(lplf)), 0, 0)
|
||||||
return uintptr(ret)
|
return uintptr(ret)
|
||||||
}
|
}
|
||||||
|
@ -304,14 +304,14 @@ func centerWindow(hwnd syscall.Handle) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMessageFont() uintptr {
|
func getMessageFont() uintptr {
|
||||||
var metrics nonClientMetricsW
|
var metrics _NONCLIENTMETRICS
|
||||||
metrics.cbSize = uint32(unsafe.Sizeof(metrics))
|
metrics.Size = uint32(unsafe.Sizeof(metrics))
|
||||||
systemParametersInfo(spiGetNonClientMetrics, uint32(unsafe.Sizeof(metrics)), unsafe.Pointer(&metrics), 0)
|
systemParametersInfo(spiGetNonClientMetrics, uint32(unsafe.Sizeof(metrics)), unsafe.Pointer(&metrics), 0)
|
||||||
return createFontIndirect(&metrics.lfMessageFont)
|
return createFontIndirect(&metrics.MessageFont)
|
||||||
}
|
}
|
||||||
|
|
||||||
func registerClass(className string, instance syscall.Handle, fn interface{}) error {
|
func registerClass(className string, instance syscall.Handle, fn interface{}) error {
|
||||||
var wcx _WNDCLASSEXW
|
var wcx _WNDCLASSEX
|
||||||
wcx.Size = uint32(unsafe.Sizeof(wcx))
|
wcx.Size = uint32(unsafe.Sizeof(wcx))
|
||||||
wcx.WndProc = syscall.NewCallback(fn)
|
wcx.WndProc = syscall.NewCallback(fn)
|
||||||
wcx.Instance = uintptr(instance)
|
wcx.Instance = uintptr(instance)
|
||||||
|
|
Loading…
Reference in a new issue