-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhaccel.go
48 lines (42 loc) · 1.42 KB
/
haccel.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
package wingo
import (
"github.com/rogeecn/wingo/proc"
"syscall"
"unsafe"
"github.com/rogeecn/wingo/errco"
)
// A handle to an accelerator table.
//
// 📑 https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types#haccel
type HACCEL HANDLE
// ⚠️ You must defer HACCEL.DestroyAcceleratorTable().
//
// 📑 https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createacceleratortablew
func CreateAcceleratorTable(accelList []ACCEL) HACCEL {
ret, _, err := syscall.Syscall(proc.CreateAcceleratorTable.Addr(), 2,
uintptr(unsafe.Pointer(&accelList[0])), uintptr(len(accelList)), 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return HACCEL(ret)
}
// 📑 https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-copyacceleratortablew
func (hAccel HACCEL) CopyAcceleratorTable() []ACCEL {
szRet, _, _ := syscall.Syscall(proc.CopyAcceleratorTable.Addr(), 3,
uintptr(hAccel), 0, 0)
if szRet == 0 {
return []ACCEL{}
}
accelList := make([]ACCEL, szRet)
syscall.Syscall(proc.CopyAcceleratorTable.Addr(), 3,
uintptr(hAccel), uintptr(unsafe.Pointer(&accelList[0])), szRet)
return accelList
}
// 📑 https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-destroyacceleratortable
func (hAccel HACCEL) DestroyAcceleratorTable() {
ret, _, err := syscall.Syscall(proc.DestroyAcceleratorTable.Addr(), 1,
uintptr(hAccel), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}