mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-11 22:49:29 +08:00
44 lines
883 B
Go
44 lines
883 B
Go
//go:build windows
|
|
|
|
package w32
|
|
|
|
import (
|
|
"unsafe"
|
|
)
|
|
|
|
func CreateIconFromResourceEx(presbits uintptr, dwResSize uint32, isIcon bool, version uint32, cxDesired int, cyDesired int, flags uint) (uintptr, error) {
|
|
icon := 0
|
|
if isIcon {
|
|
icon = 1
|
|
}
|
|
r, _, err := procCreateIconFromResourceEx.Call(
|
|
presbits,
|
|
uintptr(dwResSize),
|
|
uintptr(icon),
|
|
uintptr(version),
|
|
uintptr(cxDesired),
|
|
uintptr(cyDesired),
|
|
uintptr(flags),
|
|
)
|
|
|
|
if r == 0 {
|
|
return 0, err
|
|
}
|
|
return r, nil
|
|
}
|
|
|
|
// CreateHIconFromPNG creates a HICON from a PNG file
|
|
func CreateHIconFromPNG(pngData []byte) (HICON, error) {
|
|
iconWidth := GetSystemMetrics(SM_CXSMICON)
|
|
iconHeight := GetSystemMetrics(SM_CYSMICON)
|
|
icon, err := CreateIconFromResourceEx(
|
|
uintptr(unsafe.Pointer(&pngData[0])),
|
|
uint32(len(pngData)),
|
|
true,
|
|
0x00030000,
|
|
iconWidth,
|
|
iconHeight,
|
|
LR_DEFAULTSIZE)
|
|
return HICON(icon), err
|
|
}
|