diff --git a/app/internal/window/os_windows.go b/app/internal/window/os_windows.go index 938fa7b8..e6168c8f 100644 --- a/app/internal/window/os_windows.go +++ b/app/internal/window/os_windows.go @@ -70,6 +70,9 @@ var backends []gpuAPI // winMap maps win32 HWNDs to *windows. var winMap sync.Map +// iconID is the ID of the icon in the resource file. +const iconID = 1 + var resources struct { once sync.Once // handle is the module handle from GetModuleHandle. @@ -130,11 +133,13 @@ func initResources() error { return err } resources.cursor = c + icon, _ := windows.LoadImage(hInst, iconID, windows.IMAGE_ICON, 0, 0, windows.LR_DEFAULTSIZE|windows.LR_SHARED) wcls := windows.WndClassEx{ CbSize: uint32(unsafe.Sizeof(windows.WndClassEx{})), Style: windows.CS_HREDRAW | windows.CS_VREDRAW | windows.CS_OWNDC, LpfnWndProc: syscall.NewCallback(windowProc), HInstance: hInst, + HIcon: icon, LpszClassName: syscall.StringToUTF16Ptr("GioWindow"), } cls, err := windows.RegisterClassEx(&wcls) diff --git a/app/internal/windows/windows.go b/app/internal/windows/windows.go index 22435b49..d35f05a9 100644 --- a/app/internal/windows/windows.go +++ b/app/internal/windows/windows.go @@ -193,6 +193,19 @@ const ( GHND = 0x0042 CF_UNICODETEXT = 13 + IMAGE_BITMAP = 0 + IMAGE_ICON = 1 + IMAGE_CURSOR = 2 + + LR_CREATEDIBSECTION = 0x00002000 + LR_DEFAULTCOLOR = 0x00000000 + LR_DEFAULTSIZE = 0x00000040 + LR_LOADFROMFILE = 0x00000010 + LR_LOADMAP3DCOLORS = 0x00001000 + LR_LOADTRANSPARENT = 0x00000020 + LR_MONOCHROME = 0x00000001 + LR_SHARED = 0x00008000 + LR_VGACOLOR = 0x00000080 ) var ( @@ -221,6 +234,7 @@ var ( _GetMessageTime = user32.NewProc("GetMessageTime") _KillTimer = user32.NewProc("KillTimer") _LoadCursor = user32.NewProc("LoadCursorW") + _LoadImage = user32.NewProc("LoadImageW") _MonitorFromPoint = user32.NewProc("MonitorFromPoint") _MsgWaitForMultipleObjectsEx = user32.NewProc("MsgWaitForMultipleObjectsEx") _OpenClipboard = user32.NewProc("OpenClipboard") @@ -438,6 +452,14 @@ func LoadCursor(curID uint16) (syscall.Handle, error) { return syscall.Handle(h), nil } +func LoadImage(hInst syscall.Handle, res uint32, typ uint32, cx, cy int, fuload uint32) (syscall.Handle, error) { + h, _, err := _LoadImage.Call(uintptr(hInst), uintptr(res), uintptr(typ), uintptr(cx), uintptr(cy), uintptr(fuload)) + if h == 0 { + return 0, fmt.Errorf("LoadImageW failed: %v", err) + } + return syscall.Handle(h), nil +} + func monitorFromPoint(pt Point, flags uint32) syscall.Handle { r, _, _ := _MonitorFromPoint.Call(uintptr(pt.X), uintptr(pt.Y), uintptr(flags)) return syscall.Handle(r)