Ejemplo n.º 1
0
func (p *_Systray) SetIcon(file string) error {
	p.currentIcon = file
	if p.isCreated {
		cFile := C.CString(file)
		defer C.free(unsafe.Pointer(cFile))
		C.setIcon(cFile)
	}
	return nil
}
Ejemplo n.º 2
0
func SetIcon(iconBytes []byte) {
	f, err := ioutil.TempFile("", "systray_temp_icon")
	if err != nil {
		log.Printf("Unable to create temp icon: %v", err)
		return
	}
	defer f.Close()
	_, err = f.Write(iconBytes)
	if err != nil {
		log.Printf("Unable to write icon to temp file %v: %v", f.Name(), f)
		return
	}
	// Need to close file before we load it to make sure contents is flushed.
	f.Close()
	name, err := syscall.UTF16PtrFromString(f.Name())
	if err != nil {
		log.Printf("Unable to convert name to string pointer: %v", err)
		return
	}

	C.setIcon((*C.wchar_t)(unsafe.Pointer(name)), 0)
}
Ejemplo n.º 3
0
// SetIcon sets the systray icon.
// iconBytes should be the content of .ico for windows and .ico/.jpg/.png
// for other platforms.
func SetIcon(iconBytes []byte) {
	cstr := (*C.char)(unsafe.Pointer(&iconBytes[0]))
	C.setIcon(cstr, (C.int)(len(iconBytes)))
}