-
Notifications
You must be signed in to change notification settings - Fork 45
/
icon.go
51 lines (40 loc) · 1.1 KB
/
icon.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package gform
import (
"errors"
"fmt"
"github.com/AllenDang/w32"
"syscall"
)
type Icon struct {
handle w32.HICON
}
func NewIconFromFile(path string) (*Icon, error) {
ico := new(Icon)
var err error
if ico.handle = w32.LoadIcon(0, syscall.StringToUTF16Ptr(path)); ico.handle == 0 {
err = errors.New(fmt.Sprintf("Cannot load icon from %s", path))
}
return ico, err
}
func NewIconFromResource(instance w32.HINSTANCE, resId uint16) (*Icon, error) {
ico := new(Icon)
var err error
if ico.handle = w32.LoadIcon(instance, w32.MakeIntResource(resId)); ico.handle == 0 {
err = errors.New(fmt.Sprintf("Cannot load icon from resource with id %v", resId))
}
return ico, err
}
func ExtractIcon(fileName string, index int) (*Icon, error) {
ico := new(Icon)
var err error
if ico.handle = w32.ExtractIcon(fileName, index); ico.handle == 0 || ico.handle == 1 {
err = errors.New(fmt.Sprintf("Cannot extract icon from %s at index %v", fileName, index))
}
return ico, err
}
func (this *Icon) Destroy() bool {
return w32.DestroyIcon(this.handle)
}
func (this *Icon) Handle() w32.HICON {
return this.handle
}