From ad3e3f74edf6ae545a4c67ddbfef17eeb0c4245c Mon Sep 17 00:00:00 2001 From: LowLvlGod <88935541+LowLvlGod@users.noreply.github.com> Date: Sun, 20 Jul 2025 14:37:41 +0200 Subject: [PATCH 1/2] Fix Windows 32-bit support for GetWindowLong/SetWindowLong functions --- internal/w32/w32.go | 26 ++++++++++++++++++++++++++ webview.go | 4 ++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/internal/w32/w32.go b/internal/w32/w32.go index 35aa2f3..78213f4 100644 --- a/internal/w32/w32.go +++ b/internal/w32/w32.go @@ -37,7 +37,9 @@ var ( User32SetWindowTextW = user32.NewProc("SetWindowTextW") User32PostThreadMessageW = user32.NewProc("PostThreadMessageW") User32GetWindowLongPtrW = user32.NewProc("GetWindowLongPtrW") + User32GetWindowLongW = user32.NewProc("GetWindowLongW") User32SetWindowLongPtrW = user32.NewProc("SetWindowLongPtrW") + User32SetWindowLongW = user32.NewProc("SetWindowLongW") User32AdjustWindowRect = user32.NewProc("AdjustWindowRect") User32SetWindowPos = user32.NewProc("SetWindowPos") User32IsDialogMessage = user32.NewProc("IsDialogMessage") @@ -190,3 +192,27 @@ func SHCreateMemStream(data []byte) (uintptr, error) { return ret, nil } + +func GetWindowLong(hwnd uintptr, index int) uintptr { + if unsafe.Sizeof(uintptr(0)) == 8 { + // 64-bit + ret, _, _ := User32GetWindowLongPtrW.Call(hwnd, uintptr(index)) + return ret + } else { + // 32-bit + ret, _, _ := User32GetWindowLongW.Call(hwnd, uintptr(index)) + return ret + } +} + +func SetWindowLong(hwnd uintptr, index int, newLong uintptr) uintptr { + if unsafe.Sizeof(uintptr(0)) == 8 { + // 64-bit + ret, _, _ := User32SetWindowLongPtrW.Call(hwnd, uintptr(index), newLong) + return ret + } else { + // 32-bit + ret, _, _ := User32SetWindowLongW.Call(hwnd, uintptr(index), newLong) + return ret + } +} diff --git a/webview.go b/webview.go index 263d083..8f35aec 100644 --- a/webview.go +++ b/webview.go @@ -404,13 +404,13 @@ func (w *webview) SetTitle(title string) { func (w *webview) SetSize(width int, height int, hints Hint) { index := w32.GWLStyle - style, _, _ := w32.User32GetWindowLongPtrW.Call(w.hwnd, uintptr(index)) + style := w32.GetWindowLong(w.hwnd, index) if hints == HintFixed { style &^= (w32.WSThickFrame | w32.WSMaximizeBox) } else { style |= (w32.WSThickFrame | w32.WSMaximizeBox) } - _, _, _ = w32.User32SetWindowLongPtrW.Call(w.hwnd, uintptr(index), style) + w32.SetWindowLong(w.hwnd, index, style) if hints == HintMax { w.maxsz.X = int32(width) From bd1bb53d5b5b26c36762e6f2eb38cdd1f7e93cdd Mon Sep 17 00:00:00 2001 From: LowLvlGod <88935541+LowLvlGod@users.noreply.github.com> Date: Mon, 21 Jul 2025 14:21:13 +0200 Subject: [PATCH 2/2] Use build tags --- internal/w32/w32.go | 28 ++-------------------------- internal/w32/w32_386.go | 14 ++++++++++++++ internal/w32/w32_64bit.go | 15 +++++++++++++++ 3 files changed, 31 insertions(+), 26 deletions(-) create mode 100644 internal/w32/w32_386.go create mode 100644 internal/w32/w32_64bit.go diff --git a/internal/w32/w32.go b/internal/w32/w32.go index 78213f4..e76f894 100644 --- a/internal/w32/w32.go +++ b/internal/w32/w32.go @@ -36,10 +36,10 @@ var ( User32PostMessageW = user32.NewProc("PostMessageW") User32SetWindowTextW = user32.NewProc("SetWindowTextW") User32PostThreadMessageW = user32.NewProc("PostThreadMessageW") - User32GetWindowLongPtrW = user32.NewProc("GetWindowLongPtrW") User32GetWindowLongW = user32.NewProc("GetWindowLongW") - User32SetWindowLongPtrW = user32.NewProc("SetWindowLongPtrW") + User32GetWindowLongPtrW = user32.NewProc("GetWindowLongPtrW") User32SetWindowLongW = user32.NewProc("SetWindowLongW") + User32SetWindowLongPtrW = user32.NewProc("SetWindowLongPtrW") User32AdjustWindowRect = user32.NewProc("AdjustWindowRect") User32SetWindowPos = user32.NewProc("SetWindowPos") User32IsDialogMessage = user32.NewProc("IsDialogMessage") @@ -192,27 +192,3 @@ func SHCreateMemStream(data []byte) (uintptr, error) { return ret, nil } - -func GetWindowLong(hwnd uintptr, index int) uintptr { - if unsafe.Sizeof(uintptr(0)) == 8 { - // 64-bit - ret, _, _ := User32GetWindowLongPtrW.Call(hwnd, uintptr(index)) - return ret - } else { - // 32-bit - ret, _, _ := User32GetWindowLongW.Call(hwnd, uintptr(index)) - return ret - } -} - -func SetWindowLong(hwnd uintptr, index int, newLong uintptr) uintptr { - if unsafe.Sizeof(uintptr(0)) == 8 { - // 64-bit - ret, _, _ := User32SetWindowLongPtrW.Call(hwnd, uintptr(index), newLong) - return ret - } else { - // 32-bit - ret, _, _ := User32SetWindowLongW.Call(hwnd, uintptr(index), newLong) - return ret - } -} diff --git a/internal/w32/w32_386.go b/internal/w32/w32_386.go new file mode 100644 index 0000000..728d4c7 --- /dev/null +++ b/internal/w32/w32_386.go @@ -0,0 +1,14 @@ +//go:build windows && 386 +// +build windows,386 + +package w32 + +func GetWindowLong(hwnd uintptr, index int) uintptr { + ret, _, _ := User32GetWindowLongW.Call(hwnd, uintptr(index)) + return ret +} + +func SetWindowLong(hwnd uintptr, index int, newLong uintptr) uintptr { + ret, _, _ := User32SetWindowLongW.Call(hwnd, uintptr(index), newLong) + return ret +} diff --git a/internal/w32/w32_64bit.go b/internal/w32/w32_64bit.go new file mode 100644 index 0000000..b5bf9d9 --- /dev/null +++ b/internal/w32/w32_64bit.go @@ -0,0 +1,15 @@ +//go:build windows && (amd64 || arm64) +// +build windows +// +build amd64 arm64 + +package w32 + +func GetWindowLong(hwnd uintptr, index int) uintptr { + ret, _, _ := User32GetWindowLongPtrW.Call(hwnd, uintptr(index)) + return ret +} + +func SetWindowLong(hwnd uintptr, index int, newLong uintptr) uintptr { + ret, _, _ := User32SetWindowLongPtrW.Call(hwnd, uintptr(index), newLong) + return ret +}