-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhgdiobj.go
290 lines (251 loc) Β· 8.79 KB
/
hgdiobj.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
package wingo
import (
proc2 "github.com/rogeecn/wingo/proc"
"syscall"
"unsafe"
"github.com/rogeecn/wingo/co"
"github.com/rogeecn/wingo/errco"
)
// A handle to a GDI object.
//
// π https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types#hgdiobj
type HGDIOBJ HANDLE
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-deleteobject
func (hGdiObj HGDIOBJ) DeleteObject() {
ret, _, err := syscall.Syscall(proc2.DeleteObject.Addr(), 1,
uintptr(hGdiObj), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
//------------------------------------------------------------------------------
// A handle to a bitmap.
//
// π https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types#hbitmap
type HBITMAP HGDIOBJ
// β οΈ You must defer HBITMAP.DeleteObject().
//
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createbitmap
func CreateBitmap(width, height int32,
numPlanes, bitCount uint32, bits *byte) HBITMAP {
ret, _, err := syscall.Syscall6(proc2.CreateBitmap.Addr(), 5,
uintptr(width), uintptr(height), uintptr(numPlanes), uintptr(bitCount),
uintptr(unsafe.Pointer(bits)), 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return HBITMAP(ret)
}
// β οΈ You must defer HBITMAP.DeleteObject().
//
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createbitmapindirect
func CreateBitmapIndirect(bmp *BITMAP) HBITMAP {
ret, _, err := syscall.Syscall(proc2.CreateBitmapIndirect.Addr(), 1,
uintptr(unsafe.Pointer(bmp)), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return HBITMAP(ret)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-deleteobject
func (hBmp HBITMAP) DeleteObject() {
HGDIOBJ(hBmp).DeleteObject()
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getobject
func (hBmp HBITMAP) GetObject(bmp *BITMAP) {
ret, _, err := syscall.Syscall(proc2.GetObject.Addr(), 3,
uintptr(hBmp), unsafe.Sizeof(*bmp), uintptr(unsafe.Pointer(bmp)))
if ret == 0 {
panic(errco.ERROR(err))
}
}
//------------------------------------------------------------------------------
// A handle to a brush.
//
// π https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types#hbrush
type HBRUSH HGDIOBJ
// β οΈ You must defer HBRUSH.DeleteObject().
//
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createbrushindirect
func CreateBrushIndirect(lb *LOGBRUSH) HBRUSH {
ret, _, err := syscall.Syscall(proc2.CreateBrushIndirect.Addr(), 1,
uintptr(unsafe.Pointer(lb)), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return HBRUSH(ret)
}
// β οΈ You must defer HBRUSH.DeleteObject().
//
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createhatchbrush
func CreateHatchBrush(hatch co.HS, color COLORREF) HBRUSH {
ret, _, err := syscall.Syscall(proc2.CreateHatchBrush.Addr(), 2,
uintptr(hatch), uintptr(color), 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return HBRUSH(ret)
}
// β οΈ You must defer HBRUSH.DeleteObject().
//
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createpatternbrush
func CreatePatternBrush(hBmp HBITMAP) HBRUSH {
ret, _, err := syscall.Syscall(proc2.CreatePatternBrush.Addr(), 1,
uintptr(hBmp), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return HBRUSH(ret)
}
// β οΈ You must defer HBRUSH.DeleteObject().
//
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createsolidbrush
func CreateSolidBrush(color COLORREF) HBRUSH {
ret, _, err := syscall.Syscall(proc2.CreateSolidBrush.Addr(), 1,
uintptr(color), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return HBRUSH(ret)
}
// Not an actual Win32 function, just a tricky conversion to create a brush from
// a system color, particularly used when registering a window class.
func CreateSysColorBrush(sysColor co.COLOR) HBRUSH {
return HBRUSH(sysColor + 1)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsyscolorbrush
func GetSysColorBrush(index co.COLOR) HBRUSH {
ret, _, err := syscall.Syscall(proc2.GetSysColorBrush.Addr(), 1,
uintptr(index), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return HBRUSH(ret)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-deleteobject
func (hBrush HBRUSH) DeleteObject() {
HGDIOBJ(hBrush).DeleteObject()
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getobject
func (hBrush HBRUSH) GetObject(lb *LOGBRUSH) {
ret, _, err := syscall.Syscall(proc2.GetObject.Addr(), 3,
uintptr(hBrush), unsafe.Sizeof(*lb), uintptr(unsafe.Pointer(lb)))
if ret == 0 {
panic(errco.ERROR(err))
}
}
//------------------------------------------------------------------------------
// A handle to a font.
//
// π https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types#hfont
type HFONT HGDIOBJ
// β οΈ You must defer HFONT.DeleteObject().
//
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createfontindirectw
func CreateFontIndirect(lf *LOGFONT) HFONT {
ret, _, err := syscall.Syscall(proc2.CreateFontIndirect.Addr(), 1,
uintptr(unsafe.Pointer(lf)), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return HFONT(ret)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-deleteobject
func (hFont HFONT) DeleteObject() {
HGDIOBJ(hFont).DeleteObject()
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getobject
func (hFont HFONT) GetObject(lf *LOGFONT) {
ret, _, err := syscall.Syscall(proc2.GetObject.Addr(), 3,
uintptr(hFont), unsafe.Sizeof(*lf), uintptr(unsafe.Pointer(lf)))
if ret == 0 {
panic(errco.ERROR(err))
}
}
//------------------------------------------------------------------------------
// A handle to a pen.
//
// π https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types#hpen
type HPEN HGDIOBJ
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createpen
func CreatePen(style co.PS, width int32, color COLORREF) HPEN {
ret, _, err := syscall.Syscall(proc2.CreatePen.Addr(), 3,
uintptr(style), uintptr(width), uintptr(color))
if ret == 0 {
panic(errco.ERROR(err))
}
return HPEN(ret)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createpenindirect
func CreatePenIndirect(lp *LOGPEN) HPEN {
ret, _, err := syscall.Syscall(proc2.CreatePenIndirect.Addr(), 1,
uintptr(unsafe.Pointer(lp)), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return HPEN(ret)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-deleteobject
func (hPen HPEN) DeleteObject() {
HGDIOBJ(hPen).DeleteObject()
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getobject
func (hPen HPEN) GetObject(lp *LOGPEN) {
ret, _, err := syscall.Syscall(proc2.GetObject.Addr(), 3,
uintptr(hPen), unsafe.Sizeof(*lp), uintptr(unsafe.Pointer(lp)))
if ret == 0 {
panic(errco.ERROR(err))
}
}
//------------------------------------------------------------------------------
// A handle to a region.
//
// π https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types#hrgn
type HRGN HGDIOBJ
// β οΈ You must defer HRGN.DeleteObject().
//
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createrectrgnindirect
func CreateRectRgnIndirect(rc *RECT) HRGN {
ret, _, err := syscall.Syscall(proc2.CreateRectRgnIndirect.Addr(), 1,
uintptr(unsafe.Pointer(rc)), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return HRGN(ret)
}
// β οΈ You must defer HRGN.DeleteObject().
//
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createroundrectrgn
func CreateRoundRectRgn(x1, y1, x2, y2, w, h int32) HRGN {
ret, _, err := syscall.Syscall6(proc2.CreateRoundRectRgn.Addr(), 6,
uintptr(x1), uintptr(y1), uintptr(x2), uintptr(y2),
uintptr(w), uintptr(h))
if ret == 0 {
panic(errco.ERROR(err))
}
return HRGN(ret)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-deleteobject
func (hRgn HRGN) DeleteObject() {
HGDIOBJ(hRgn).DeleteObject()
}
// Combines the two regions and stores the result in current region.
//
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-combinergn
func (hRgn HRGN) CombineRgn(hrgnSrc1, hrgnSrc2 HRGN, mode co.RGN) co.REGION {
ret, _, err := syscall.Syscall6(proc2.CombineRgn.Addr(), 4,
uintptr(hRgn), uintptr(hrgnSrc1), uintptr(hrgnSrc2), uintptr(mode), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return co.REGION(ret)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-offsetrgn
func (hRgn HRGN) OffsetRgn(x, y int32) co.REGION {
ret, _, err := syscall.Syscall(proc2.OffsetRgn.Addr(), 3,
uintptr(hRgn), uintptr(x), uintptr(y))
if ret == 0 {
panic(errco.ERROR(err))
}
return co.REGION(ret)
}