From c61ce1e2de3f0be983a1369c93a421162245f661 Mon Sep 17 00:00:00 2001 From: stffabi Date: Fri, 24 Jun 2022 22:46:23 +0200 Subject: [PATCH] [v2, windows] Make SetBackgroundColour compatible for windows/386 (#1493) * [v2, windows] Remove duplicate SetBackgroundColour * [v2, windows] Make SetBackgroundColour compatible for windows/386 --- .../frontend/desktop/windows/win32/consts.go | 1 + .../frontend/desktop/windows/win32/window.go | 18 ++++++++++++++++-- v2/internal/frontend/desktop/windows/window.go | 4 ---- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/v2/internal/frontend/desktop/windows/win32/consts.go b/v2/internal/frontend/desktop/windows/win32/consts.go index 9b29bf2c..8731664b 100644 --- a/v2/internal/frontend/desktop/windows/win32/consts.go +++ b/v2/internal/frontend/desktop/windows/win32/consts.go @@ -15,6 +15,7 @@ var ( moduser32 = syscall.NewLazyDLL("user32.dll") procSystemParametersInfo = moduser32.NewProc("SystemParametersInfoW") procGetWindowLong = moduser32.NewProc("GetWindowLongW") + procSetClassLong = moduser32.NewProc("SetClassLongW") procSetClassLongPtr = moduser32.NewProc("SetClassLongPtrW") procShowWindow = moduser32.NewProc("ShowWindow") ) diff --git a/v2/internal/frontend/desktop/windows/win32/window.go b/v2/internal/frontend/desktop/windows/win32/window.go index c5db085f..1ddcf4c9 100644 --- a/v2/internal/frontend/desktop/windows/win32/window.go +++ b/v2/internal/frontend/desktop/windows/win32/window.go @@ -4,10 +4,12 @@ package win32 import ( "fmt" - "github.com/wailsapp/wails/v2/internal/frontend/desktop/windows/winc" "log" + "strconv" "syscall" "unsafe" + + "github.com/wailsapp/wails/v2/internal/frontend/desktop/windows/winc" ) const ( @@ -119,7 +121,19 @@ func dwmExtendFrameIntoClientArea(hwnd uintptr, margins *MARGINS) error { } func setClassLongPtr(hwnd uintptr, param int32, val uintptr) bool { - ret, _, _ := procSetClassLongPtr.Call( + proc := procSetClassLongPtr + if strconv.IntSize == 32 { + /* + https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setclasslongptrw + Note: To write code that is compatible with both 32-bit and 64-bit Windows, use SetClassLongPtr. + When compiling for 32-bit Windows, SetClassLongPtr is defined as a call to the SetClassLong function + + => We have to do this dynamically when directly calling the DLL procedures + */ + proc = procSetClassLong + } + + ret, _, _ := proc.Call( hwnd, uintptr(param), val, diff --git a/v2/internal/frontend/desktop/windows/window.go b/v2/internal/frontend/desktop/windows/window.go index dce79438..5bbada15 100644 --- a/v2/internal/frontend/desktop/windows/window.go +++ b/v2/internal/frontend/desktop/windows/window.go @@ -86,10 +86,6 @@ func NewWindow(parent winc.Controller, appoptions *options.App, versionInfo *ope result.theme = winoptions.SystemDefault } - if appoptions.BackgroundColour != nil { - win32.SetBackgroundColour(result.Handle(), appoptions.BackgroundColour.R, appoptions.BackgroundColour.G, appoptions.BackgroundColour.B) - } - result.SetSize(appoptions.Width, appoptions.Height) result.SetText(appoptions.Title) result.EnableSizable(!appoptions.DisableResize)