github.com/AlpineAIO/wails/v2@v2.0.0-beta.32.0.20240505041856-1047a8fa5fef/internal/platform/win32/icon.go (about) 1 //go:build windows 2 3 package win32 4 5 import ( 6 "unsafe" 7 ) 8 9 func CreateIconFromResourceEx(presbits uintptr, dwResSize uint32, isIcon bool, version uint32, cxDesired int, cyDesired int, flags uint) (uintptr, error) { 10 icon := 0 11 if isIcon { 12 icon = 1 13 } 14 r, _, err := procCreateIconFromResourceEx.Call( 15 presbits, 16 uintptr(dwResSize), 17 uintptr(icon), 18 uintptr(version), 19 uintptr(cxDesired), 20 uintptr(cyDesired), 21 uintptr(flags), 22 ) 23 24 if r == 0 { 25 return 0, err 26 } 27 return r, nil 28 } 29 30 // CreateHIconFromPNG creates a HICON from a PNG file 31 func CreateHIconFromPNG(pngData []byte) (HICON, error) { 32 icon, err := CreateIconFromResourceEx( 33 uintptr(unsafe.Pointer(&pngData[0])), 34 uint32(len(pngData)), 35 true, 36 0x00030000, 37 0, 38 0, 39 LR_DEFAULTSIZE) 40 return HICON(icon), err 41 }