-
Notifications
You must be signed in to change notification settings - Fork 12
/
menu.go
122 lines (102 loc) · 2.4 KB
/
menu.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//go:build windows
package winapi
import (
"errors"
"syscall"
"unsafe"
)
const (
MF_INSERT = 0x00000000
MF_CHANGE = 0x00000080
MF_APPEND = 0x00000100
MF_DELETE = 0x00000200
MF_REMOVE = 0x00001000
MF_BYCOMMAND = 0x00000000
MF_BYPOSITION = 0x00000400
MF_SEPARATOR = 0x00000800
MF_ENABLED = 0x00000000
MF_GRAYED = 0x00000001
MF_DISABLED = 0x00000002
MF_UNCHECKED = 0x00000000
MF_CHECKED = 0x00000008
MF_USECHECKBITMAPS = 0x00000200
MF_STRING = 0x00000000
MF_BITMAP = 0x00000004
MF_OWNERDRAW = 0x00000100
MF_POPUP = 0x00000010
MF_MENUBARBREAK = 0x00000020
MF_MENUBREAK = 0x00000040
MF_UNHILITE = 0x00000000
MF_HILITE = 0x00000080
MF_DEFAULT = 0x00001000
MF_SYSMENU = 0x00002000
MF_HELP = 0x00004000
MF_RIGHTJUSTIFY = 0x00004000
MF_MOUSESELECT = 0x00008000
MF_END = 0x00000080 // Obsolete -- only used by old RES files
)
func AppendMenu(hMenu HMENU, Flags uint32, IdNewItem uintptr, NewItem string) error {
var err error
var pNewItem *uint16
if NewItem != "" {
pNewItem, err = syscall.UTF16PtrFromString(NewItem)
if err != nil {
return err
}
}
return _AppendMenu(hMenu, Flags, IdNewItem, pNewItem)
}
func _AppendMenu(hMenu HMENU, Flags uint32, IdNewItem uintptr, NewItem *uint16) (err error) {
r1, _, e1 := syscall.Syscall6(procAppendMenu.Addr(), 4,
uintptr(hMenu), uintptr(Flags), IdNewItem, uintptr(unsafe.Pointer(NewItem)),
0, 0)
if r1 == 0 {
wec := WinErrorCode(e1)
if wec != 0 {
err = wec
} else {
err = errors.New("winapi: AppendMenu failed.")
}
}
return
}
func CreateMenu() (hMenu HMENU, err error) {
r1, _, e1 := syscall.Syscall(procCreateMenu.Addr(), 0, 0, 0, 0)
if r1 == 0 {
wec := WinErrorCode(e1)
if wec != 0 {
err = wec
} else {
err = errors.New("winapi: CreateMenu failed.")
}
} else {
hMenu = HMENU(r1)
}
return
}
func CreatePopupMenu() (hMenu HMENU, err error) {
r1, _, e1 := syscall.Syscall(procCreatePopupMenu.Addr(), 0, 0, 0, 0)
if r1 == 0 {
wec := WinErrorCode(e1)
if wec != 0 {
err = wec
} else {
err = errors.New("winapi: CreatePopupMenu failed.")
}
} else {
hMenu = HMENU(r1)
}
return
}
func DestroyMenu(hMenu HMENU) (err error) {
r1, _, e1 := syscall.Syscall(procDestroyMenu.Addr(), 1, uintptr(hMenu), 0, 0)
if r1 == 0 {
wec := WinErrorCode(e1)
if wec != 0 {
err = wec
} else {
err = errors.New("winapi: DestroyMenu failed.")
}
}
return
}