Skip to content

Commit

Permalink
[v2, windows] Make SetBackgroundColour compatible for windows/386 (#1493
Browse files Browse the repository at this point in the history
)

* [v2, windows] Remove duplicate SetBackgroundColour

* [v2, windows] Make SetBackgroundColour compatible for windows/386
  • Loading branch information
stffabi committed Jun 24, 2022
1 parent 16581ce commit c61ce1e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
1 change: 1 addition & 0 deletions v2/internal/frontend/desktop/windows/win32/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
Expand Down
18 changes: 16 additions & 2 deletions v2/internal/frontend/desktop/windows/win32/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions v2/internal/frontend/desktop/windows/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c61ce1e

Please sign in to comment.