-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathregWin.go
61 lines (49 loc) · 1.31 KB
/
regWin.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
package gd
import (
"syscall"
"unsafe"
"github.com/fjs-icu/win"
)
// 必须先注册窗口类
var (
RegWinClass = make(map[string]bool)
DefaultWndProcPtr uintptr
Hwnd2WindowBase = make(map[win.HWND]*WindowBase)
)
func MustRegWinProcPtr(className string, wndProcPtr uintptr) {
MustRegWin(className, wndProcPtr, 0)
}
func MustRegWin(className string, wndProcPtr uintptr, style uint32) error {
if RegWinClass[className] {
return nil
}
hInst := win.GetModuleHandle(nil)
if hInst == 0 {
return NewErr("GetModuleHandle nil")
}
hIcon := win.LoadIcon(hInst, win.MAKEINTRESOURCE(7)) // rsrc uses 7 for app icon
if hIcon == 0 {
hIcon = win.LoadIcon(0, win.MAKEINTRESOURCE(win.IDI_APPLICATION))
}
if hIcon == 0 {
return NewErr("GetModuleHandle LoadIcon")
}
hCursor := win.LoadCursor(0, win.MAKEINTRESOURCE(win.IDC_ARROW))
if hCursor == 0 {
return NewErr("GetModuleHandle LoadCursor")
}
var wc win.WNDCLASSEX
wc.CbSize = uint32(unsafe.Sizeof(wc))
wc.LpfnWndProc = wndProcPtr
wc.HInstance = hInst
wc.HIcon = hIcon
wc.HCursor = hCursor
wc.HbrBackground = win.COLOR_BTNFACE + 1
wc.LpszClassName = syscall.StringToUTF16Ptr(className)
wc.Style = style
if atom := win.RegisterClassEx(&wc); atom == 0 {
return NewErr("GetModuleHandle RegisterClassEx")
}
RegWinClass[className] = true
return nil
}