-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathw32.go
170 lines (148 loc) · 4 KB
/
w32.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package w32
import (
"syscall"
"unicode/utf16"
"unsafe"
"golang.org/x/sys/windows"
)
var (
ole32 = windows.NewLazySystemDLL("ole32")
Ole32CoInitializeEx = ole32.NewProc("CoInitializeEx")
kernel32 = windows.NewLazySystemDLL("kernel32")
Kernel32GetCurrentThreadID = kernel32.NewProc("GetCurrentThreadId")
shlwapi = windows.NewLazySystemDLL("shlwapi")
shlwapiSHCreateMemStream = shlwapi.NewProc("SHCreateMemStream")
user32 = windows.NewLazySystemDLL("user32")
User32LoadImageW = user32.NewProc("LoadImageW")
User32GetSystemMetrics = user32.NewProc("GetSystemMetrics")
User32RegisterClassExW = user32.NewProc("RegisterClassExW")
User32CreateWindowExW = user32.NewProc("CreateWindowExW")
User32DestroyWindow = user32.NewProc("DestroyWindow")
User32ShowWindow = user32.NewProc("ShowWindow")
User32UpdateWindow = user32.NewProc("UpdateWindow")
User32SetFocus = user32.NewProc("SetFocus")
User32GetMessageW = user32.NewProc("GetMessageW")
User32TranslateMessage = user32.NewProc("TranslateMessage")
User32DispatchMessageW = user32.NewProc("DispatchMessageW")
User32DefWindowProcW = user32.NewProc("DefWindowProcW")
User32GetClientRect = user32.NewProc("GetClientRect")
User32PostQuitMessage = user32.NewProc("PostQuitMessage")
User32SetWindowTextW = user32.NewProc("SetWindowTextW")
User32PostThreadMessageW = user32.NewProc("PostThreadMessageW")
User32GetWindowLongPtrW = user32.NewProc("GetWindowLongPtrW")
User32SetWindowLongPtrW = user32.NewProc("SetWindowLongPtrW")
User32AdjustWindowRect = user32.NewProc("AdjustWindowRect")
User32SetWindowPos = user32.NewProc("SetWindowPos")
User32IsDialogMessage = user32.NewProc("IsDialogMessage")
User32GetAncestor = user32.NewProc("GetAncestor")
)
const (
SystemMetricsCxIcon = 11
SystemMetricsCyIcon = 12
)
const (
SWShow = 5
)
const (
SWPNoZOrder = 0x0004
SWPNoActivate = 0x0010
SWPNoMove = 0x0002
SWPFrameChanged = 0x0020
)
const (
WMDestroy = 0x0002
WMMove = 0x0003
WMSize = 0x0005
WMActivate = 0x0006
WMClose = 0x0010
WMQuit = 0x0012
WMGetMinMaxInfo = 0x0024
WMNCLButtonDown = 0x00A1
WMMoving = 0x0216
WMApp = 0x8000
)
const (
GAParent = 1
GARoot = 2
GARootOwner = 3
)
const (
GWLStyle = -16
)
const (
WSOverlapped = 0x00000000
WSMaximizeBox = 0x00020000
WSThickFrame = 0x00040000
WSCaption = 0x00C00000
WSSysMenu = 0x00080000
WSMinimizeBox = 0x00020000
WSOverlappedWindow = (WSOverlapped | WSCaption | WSSysMenu | WSThickFrame | WSMinimizeBox | WSMaximizeBox)
)
const (
WAInactive = 0
WAActive = 1
WAActiveClick = 2
)
type WndClassExW struct {
CbSize uint32
Style uint32
LpfnWndProc uintptr
CnClsExtra int32
CbWndExtra int32
HInstance windows.Handle
HIcon windows.Handle
HCursor windows.Handle
HbrBackground windows.Handle
LpszMenuName *uint16
LpszClassName *uint16
HIconSm windows.Handle
}
type Rect struct {
Left int32
Top int32
Right int32
Bottom int32
}
type MinMaxInfo struct {
PtReserved Point
PtMaxSize Point
PtMaxPosition Point
PtMinTrackSize Point
PtMaxTrackSize Point
}
type Point struct {
X, Y int32
}
type Msg struct {
Hwnd syscall.Handle
Message uint32
WParam uintptr
LParam uintptr
Time uint32
Pt Point
LPrivate uint32
}
func Utf16PtrToString(p *uint16) string {
if p == nil {
return ""
}
// Find NUL terminator.
end := unsafe.Pointer(p)
n := 0
for *(*uint16)(end) != 0 {
end = unsafe.Pointer(uintptr(end) + unsafe.Sizeof(*p))
n++
}
s := (*[(1 << 30) - 1]uint16)(unsafe.Pointer(p))[:n:n]
return string(utf16.Decode(s))
}
func SHCreateMemStream(data []byte) (uintptr, error) {
ret, _, err := shlwapiSHCreateMemStream.Call(
uintptr(unsafe.Pointer(&data[0])),
uintptr(len(data)),
)
if ret == 0 {
return 0, err
}
return ret, nil
}