-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhdc.go
767 lines (685 loc) Β· 23.5 KB
/
hdc.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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
package wingo
import (
"fmt"
proc2 "github.com/rogeecn/wingo/proc"
"github.com/rogeecn/wingo/util"
"runtime"
"syscall"
"unsafe"
"github.com/rogeecn/wingo/co"
"github.com/rogeecn/wingo/errco"
)
// A handle to a device context (DC).
//
// π https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types#hdc
type HDC HANDLE
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-abortpath
func (hdc HDC) AbortPath() {
ret, _, err := syscall.Syscall(proc2.AbortPath.Addr(), 1,
uintptr(hdc), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-anglearc
func (hdc HDC) AngleArc(center POINT, r uint32, startAngle, sweepAngle float32) {
ret, _, err := syscall.Syscall6(proc2.AngleArc.Addr(), 6,
uintptr(hdc), uintptr(center.X), uintptr(center.Y), uintptr(r),
uintptr(startAngle), uintptr(sweepAngle))
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-arc
func (hdc HDC) Arc(bound RECT, radialStart, radialEnd POINT) {
ret, _, err := syscall.Syscall9(proc2.Arc.Addr(), 9,
uintptr(hdc), uintptr(bound.Left), uintptr(bound.Top),
uintptr(bound.Right), uintptr(bound.Bottom),
uintptr(radialStart.X), uintptr(radialStart.Y),
uintptr(radialEnd.X), uintptr(radialEnd.Y))
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-arcto
func (hdc HDC) ArcTo(bound RECT, radialStart, radialEnd POINT) {
ret, _, err := syscall.Syscall9(proc2.ArcTo.Addr(), 9,
uintptr(hdc), uintptr(bound.Left), uintptr(bound.Top),
uintptr(bound.Right), uintptr(bound.Bottom),
uintptr(radialStart.X), uintptr(radialStart.Y),
uintptr(radialEnd.X), uintptr(radialEnd.Y))
if ret == 0 {
panic(errco.ERROR(err))
}
}
// β οΈ You must defer HDC.EndPath().
//
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-beginpath
func (hdc HDC) BeginPath() {
ret, _, err := syscall.Syscall(proc2.BeginPath.Addr(), 1,
uintptr(hdc), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// This method is called from the destination HDC.
//
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-bitblt
func (hdc HDC) BitBlt(
destTopLeft POINT, sz SIZE, hdcSrc HDC, srcTopLeft POINT, rop co.ROP) {
ret, _, err := syscall.Syscall9(proc2.BitBlt.Addr(), 9,
uintptr(hdc), uintptr(destTopLeft.X), uintptr(destTopLeft.Y),
uintptr(sz.Cx), uintptr(sz.Cy),
uintptr(hdcSrc), uintptr(srcTopLeft.X), uintptr(srcTopLeft.Y),
uintptr(rop))
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-canceldc
func (hdc HDC) CancelDC() {
ret, _, err := syscall.Syscall(proc2.CancelDC.Addr(), 1,
uintptr(hdc), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-chord
func (hdc HDC) Chord(bound RECT, radialStart, radialEnd POINT) {
ret, _, err := syscall.Syscall9(proc2.Chord.Addr(), 9,
uintptr(hdc), uintptr(bound.Left), uintptr(bound.Top),
uintptr(bound.Right), uintptr(bound.Bottom),
uintptr(radialStart.X), uintptr(radialStart.Y),
uintptr(radialEnd.X), uintptr(radialEnd.Y))
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-closefigure
func (hdc HDC) CloseFigure() {
ret, _, err := syscall.Syscall(proc2.CloseFigure.Addr(), 1,
uintptr(hdc), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// β οΈ You must defer HBITMAP.DeleteObject().
//
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createcompatiblebitmap
func (hdc HDC) CreateCompatibleBitmap(cx, cy int32) HBITMAP {
ret, _, err := syscall.Syscall(proc2.CreateCompatibleBitmap.Addr(), 3,
uintptr(hdc), uintptr(cx), uintptr(cy))
if ret == 0 {
panic(errco.ERROR(err))
}
return HBITMAP(ret)
}
// β οΈ You must defer HDC.DeleteDC().
//
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createcompatibledc
func (hdc HDC) CreateCompatibleDC() HDC {
ret, _, err := syscall.Syscall(proc2.CreateCompatibleDC.Addr(), 1,
uintptr(hdc), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return HDC(ret)
}
// β οΈ You must defer HBITMAP.DeleteObject().
//
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-createdibsection
func (hdc HDC) CreateDIBSection(
bmi *BITMAPINFO, usage co.DIB,
hSection HFILEMAP, offset uint32) (HBITMAP, *byte) {
var ppvBits *byte
ret, _, err := syscall.Syscall6(proc2.CreateDIBSection.Addr(), 6,
uintptr(hdc), uintptr(unsafe.Pointer(bmi)), uintptr(usage),
uintptr(unsafe.Pointer(&ppvBits)), uintptr(hSection), uintptr(offset))
if ret == 0 {
panic(errco.ERROR(err))
}
return HBITMAP(ret), ppvBits
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-deletedc
func (hdc HDC) DeleteDC() {
ret, _, err := syscall.Syscall(proc2.DeleteDC.Addr(), 1,
uintptr(hdc), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-drawicon
func (hdc HDC) DrawIcon(x, y int32, hIcon HICON) {
ret, _, err := syscall.Syscall6(proc2.DrawIcon.Addr(), 4,
uintptr(hdc), uintptr(x), uintptr(y), uintptr(hIcon), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-ellipse
func (hdc HDC) Ellipse(bound RECT) {
ret, _, err := syscall.Syscall6(proc2.Ellipse.Addr(), 5,
uintptr(hdc), uintptr(bound.Left), uintptr(bound.Top),
uintptr(bound.Right), uintptr(bound.Bottom), 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-endpath
func (hdc HDC) EndPath() {
ret, _, err := syscall.Syscall(proc2.EndPath.Addr(), 1,
uintptr(hdc), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-enumdisplaymonitors
func (hdc HDC) EnumDisplayMonitors(
rcClip *RECT,
enumFunc func(hMon HMONITOR, hdcMon HDC, rcMon *RECT) bool) {
pPack := &_EnumMonitorPack{f: enumFunc}
if _globalEnumMonitorFuncs == nil {
_globalEnumMonitorFuncs = make(map[*_EnumMonitorPack]struct{}, 2)
}
_globalEnumMonitorFuncs[pPack] = struct{}{} // store pointer in the set
ret, _, err := syscall.Syscall6(proc2.EnumDisplayMonitors.Addr(), 4,
uintptr(hdc), uintptr(unsafe.Pointer(rcClip)),
_globalEnumMonitorCallback, uintptr(unsafe.Pointer(pPack)), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
type _EnumMonitorPack struct {
f func(hMon HMONITOR, hdcMon HDC, rcMon *RECT) bool
}
var (
_globalEnumMonitorCallback uintptr = syscall.NewCallback(_EnumMonitorProc)
_globalEnumMonitorFuncs map[*_EnumMonitorPack]struct{}
)
func _EnumMonitorProc(hMon HMONITOR, hdcMon HDC, rcMon *RECT, lParam LPARAM) uintptr {
pPack := (*_EnumMonitorPack)(unsafe.Pointer(lParam))
retVal := uintptr(0)
if _, isStored := _globalEnumMonitorFuncs[pPack]; isStored {
retVal = util.BoolToUintptr(pPack.f(hMon, hdcMon, rcMon))
if retVal == 0 {
delete(_globalEnumMonitorFuncs, pPack) // remove from set
}
}
return retVal
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-fillpath
func (hdc HDC) FillPath() {
ret, _, err := syscall.Syscall(proc2.FillPath.Addr(), 1,
uintptr(hdc), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-fillrect
func (hdc HDC) FillRect(rc *RECT, hBrush HBRUSH) {
ret, _, err := syscall.Syscall(proc2.FillRect.Addr(), 3,
uintptr(hdc), uintptr(unsafe.Pointer(rc)), uintptr(hBrush))
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-fillrgn
func (hdc HDC) FillRgn(hRgn HRGN, hBrush HBRUSH) {
ret, _, err := syscall.Syscall(proc2.FillRgn.Addr(), 3,
uintptr(hdc), uintptr(hRgn), uintptr(hBrush))
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-flattenpath
func (hdc HDC) FlattenPath() {
ret, _, err := syscall.Syscall(proc2.FlattenPath.Addr(), 1,
uintptr(hdc), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-framerect
func (hdc HDC) FrameRect(rc *RECT, hBrush HBRUSH) {
ret, _, err := syscall.Syscall(proc2.FrameRect.Addr(), 3,
uintptr(hdc), uintptr(unsafe.Pointer(rc)), uintptr(hBrush))
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-framergn
func (hdc HDC) FrameRgn(hRgn HRGN, hBrush HBRUSH, w, h int32) {
ret, _, err := syscall.Syscall6(proc2.FrameRgn.Addr(), 5,
uintptr(hdc), uintptr(hRgn), uintptr(hBrush), uintptr(w), uintptr(h),
0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getcurrentpositionex
func (hdc HDC) GetCurrentPositionEx() POINT {
var pt POINT
ret, _, err := syscall.Syscall(proc2.GetCurrentPositionEx.Addr(), 2,
uintptr(hdc), uintptr(unsafe.Pointer(&pt)), 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return pt
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getdcbrushcolor
func (hdc HDC) GetDCBrushColor() COLORREF {
ret, _, err := syscall.Syscall(proc2.GetDCBrushColor.Addr(), 1,
uintptr(hdc), 0, 0)
if ret == _CLR_INVALID {
panic(errco.ERROR(err))
}
return COLORREF(ret)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getdcpencolor
func (hdc HDC) GetDCPenColor() COLORREF {
ret, _, err := syscall.Syscall(proc2.GetDCPenColor.Addr(), 1,
uintptr(hdc), 0, 0)
if ret == _CLR_INVALID {
panic(errco.ERROR(err))
}
return COLORREF(ret)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getdevicecaps
func (hdc HDC) GetDeviceCaps(index co.GDC) int32 {
ret, _, _ := syscall.Syscall(proc2.GetDeviceCaps.Addr(), 2,
uintptr(hdc), uintptr(index), 0)
return int32(ret)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-getpolyfillmode
func (hdc HDC) GetPolyFillMode() co.POLYF {
ret, _, err := syscall.Syscall(proc2.GetPolyFillMode.Addr(), 1,
uintptr(hdc), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return co.POLYF(ret)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-gettextextentpoint32w
func (hdc HDC) GetTextExtentPoint32(text string) SIZE {
var sz SIZE
lpString16 := Str.ToNativeSlice(text)
ret, _, err := syscall.Syscall6(proc2.GetTextExtentPoint32.Addr(), 4,
uintptr(hdc), uintptr(unsafe.Pointer(&lpString16[0])),
uintptr(len(lpString16)-1), uintptr(unsafe.Pointer(&sz)), 0, 0)
runtime.KeepAlive(lpString16)
if ret == 0 {
panic(errco.ERROR(err))
}
return sz
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-gettextfacew
func (hdc HDC) GetTextFace() string {
var buf [_LF_FACESIZE]uint16
ret, _, err := syscall.Syscall(proc2.GetTextFace.Addr(), 3,
uintptr(hdc), uintptr(len(buf)), uintptr(unsafe.Pointer(&buf[0])))
if ret == 0 {
panic(errco.ERROR(err))
}
return Str.FromNativeSlice(buf[:])
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-gettextmetricsw
func (hdc HDC) GetTextMetrics(tm *TEXTMETRIC) {
ret, _, err := syscall.Syscall(proc2.GetTextMetrics.Addr(), 2,
uintptr(hdc), uintptr(unsafe.Pointer(tm)), 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-invertrect
func (hdc HDC) InvertRect(rc *RECT) {
ret, _, err := syscall.Syscall(proc2.InvertRect.Addr(), 2,
uintptr(hdc), uintptr(unsafe.Pointer(rc)), 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-invertrgn
func (hdc HDC) InvertRgn(hRgn HRGN) {
ret, _, err := syscall.Syscall(proc2.InvertRgn.Addr(), 2,
uintptr(hdc), uintptr(hRgn), 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-lineto
func (hdc HDC) LineTo(x, y int32) {
ret, _, err := syscall.Syscall(proc2.LineTo.Addr(), 3,
uintptr(hdc), uintptr(x), uintptr(y))
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-lptodp
func (hdc HDC) LPtoDP(pts []POINT) {
ret, _, err := syscall.Syscall(proc2.LPtoDP.Addr(), 3,
uintptr(hdc), uintptr(unsafe.Pointer(&pts[0])), uintptr(len(pts)))
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-movetoex
func (hdc HDC) MoveToEx(x, y int32, pt *POINT) {
ret, _, err := syscall.Syscall6(proc2.MoveToEx.Addr(), 4,
uintptr(hdc), uintptr(x), uintptr(y), uintptr(unsafe.Pointer(pt)),
0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-paintrgn
func (hdc HDC) PaintRgn(hRgn HRGN) {
ret, _, err := syscall.Syscall(proc2.PaintRgn.Addr(), 2,
uintptr(hdc), uintptr(hRgn), 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// β οΈ You must defer HRGN.DeleteObject().
//
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-pathtoregion
func (hdc HDC) PathToRegion() HRGN {
ret, _, err := syscall.Syscall(proc2.PathToRegion.Addr(), 1,
uintptr(hdc), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return HRGN(ret)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-pie
func (hdc HDC) Pie(bound RECT, endPointRadial1, endPointRadial2 POINT) {
ret, _, err := syscall.Syscall9(proc2.Pie.Addr(), 9,
uintptr(hdc), uintptr(bound.Left), uintptr(bound.Top),
uintptr(bound.Right), uintptr(bound.Bottom),
uintptr(endPointRadial1.X), uintptr(endPointRadial1.Y),
uintptr(endPointRadial2.X), uintptr(endPointRadial2.Y))
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-polydraw
func (hdc HDC) PolyDraw(pts []POINT, usage []co.PT) {
if len(pts) != len(usage) {
panic(fmt.Sprintf("PolyDraw different slice sizes: %d, %d.",
len(pts), len(usage)))
}
ret, _, err := syscall.Syscall6(proc2.PolyDraw.Addr(), 4,
uintptr(hdc), uintptr(unsafe.Pointer(&pts[0])),
uintptr(unsafe.Pointer(&usage[0])), uintptr(len(pts)),
0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-polygon
func (hdc HDC) Polygon(pts []POINT) {
ret, _, err := syscall.Syscall(proc2.Polygon.Addr(), 3,
uintptr(hdc), uintptr(unsafe.Pointer(&pts[0])), uintptr(len(pts)))
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-polyline
func (hdc HDC) Polyline(pts []POINT) {
ret, _, err := syscall.Syscall(proc2.Polyline.Addr(), 3,
uintptr(hdc), uintptr(unsafe.Pointer(&pts[0])), uintptr(len(pts)))
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-polylineto
func (hdc HDC) PolylineTo(pts []POINT) {
ret, _, err := syscall.Syscall(proc2.PolylineTo.Addr(), 3,
uintptr(hdc), uintptr(unsafe.Pointer(&pts[0])), uintptr(len(pts)))
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-polypolygon
func (hdc HDC) PolyPolygon(pts [][]POINT) {
totalPoints := 0
for _, block := range pts {
totalPoints += len(block)
}
flat := make([]POINT, 0, totalPoints) // flat slice of all points
blockCount := make([]int32, 0, len(pts)) // lengths of each block of points
for _, block := range pts {
flat = append(flat, block...)
blockCount = append(blockCount, int32(len(block)))
}
ret, _, err := syscall.Syscall6(proc2.PolyPolygon.Addr(), 4,
uintptr(hdc), uintptr(unsafe.Pointer(&flat[0])),
uintptr(unsafe.Pointer(&blockCount[0])), uintptr(len(blockCount)),
0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-polypolyline
func (hdc HDC) PolyPolyline(pts [][]POINT) {
totalPoints := 0
for _, block := range pts {
totalPoints += len(block)
}
flat := make([]POINT, 0, totalPoints) // flat slice of all points
blockCount := make([]uint32, 0, len(pts)) // lengths of each block of points
for _, block := range pts {
flat = append(flat, block...)
blockCount = append(blockCount, uint32(len(block)))
}
ret, _, err := syscall.Syscall6(proc2.PolyPolyline.Addr(), 4,
uintptr(hdc), uintptr(unsafe.Pointer(&flat[0])),
uintptr(unsafe.Pointer(&blockCount[0])), uintptr(len(blockCount)),
0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-ptvisible
func (hdc HDC) PtVisible(x, y int32) bool {
ret, _, err := syscall.Syscall(proc2.PtVisible.Addr(), 3,
uintptr(hdc), uintptr(x), uintptr(y))
if int(ret) == -1 {
panic(errco.ERROR(err))
}
return ret != 0
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-rectangle
func (hdc HDC) Rectangle(bound RECT) {
ret, _, err := syscall.Syscall6(proc2.Rectangle.Addr(), 5,
uintptr(hdc), uintptr(bound.Left), uintptr(bound.Top),
uintptr(bound.Right), uintptr(bound.Bottom), 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-restoredc
func (hdc HDC) RestoreDC(savedDC int32) {
ret, _, err := syscall.Syscall(proc2.RestoreDC.Addr(), 2,
uintptr(hdc), uintptr(savedDC), 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-roundrect
func (hdc HDC) RoundRect(bound RECT, sz SIZE) {
ret, _, err := syscall.Syscall9(proc2.RoundRect.Addr(), 7,
uintptr(hdc), uintptr(bound.Left), uintptr(bound.Top),
uintptr(bound.Right), uintptr(bound.Bottom),
uintptr(sz.Cx), uintptr(sz.Cy), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-savedc
func (hdc HDC) SaveDC() int32 {
ret, _, err := syscall.Syscall(proc2.SaveDC.Addr(), 1,
uintptr(hdc), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return int32(ret)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-selectobject
func (hdc HDC) SelectObjectBitmap(hBmp HBITMAP) HBITMAP {
ret, _, err := syscall.Syscall(proc2.SelectObject.Addr(), 2,
uintptr(hdc), uintptr(hBmp), 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return HBITMAP(ret)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-selectobject
func (hdc HDC) SelectObjectBrush(hBrush HBRUSH) HBRUSH {
ret, _, err := syscall.Syscall(proc2.SelectObject.Addr(), 2,
uintptr(hdc), uintptr(hBrush), 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return HBRUSH(ret)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-selectobject
func (hdc HDC) SelectObjectFont(hFont HFONT) HFONT {
ret, _, err := syscall.Syscall(proc2.SelectObject.Addr(), 2,
uintptr(hdc), uintptr(hFont), 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return HFONT(ret)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-selectobject
func (hdc HDC) SelectObjectPen(hPen HPEN) HPEN {
ret, _, err := syscall.Syscall(proc2.SelectObject.Addr(), 2,
uintptr(hdc), uintptr(hPen), 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return HPEN(ret)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-selectobject
func (hdc HDC) SelectObjectRgn(hRgn HRGN) co.REGION {
ret, _, err := syscall.Syscall(proc2.SelectObject.Addr(), 2,
uintptr(hdc), uintptr(hRgn), 0)
if ret == _HGDI_ERROR {
panic(errco.ERROR(err))
}
return co.REGION(ret)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setbkcolor
func (hdc HDC) SetBkColor(color COLORREF) COLORREF {
ret, _, err := syscall.Syscall(proc2.SetBkColor.Addr(), 2,
uintptr(hdc), uintptr(color), 0)
if ret == _CLR_INVALID {
panic(errco.ERROR(err))
}
return COLORREF(ret)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setbkmode
func (hdc HDC) SetBkMode(mode co.BKMODE) co.BKMODE {
ret, _, err := syscall.Syscall(proc2.SetBkMode.Addr(), 2,
uintptr(hdc), uintptr(mode), 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return co.BKMODE(ret)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setpolyfillmode
func (hdc HDC) SetPolyFillMode(mode co.POLYF) co.POLYF {
ret, _, err := syscall.Syscall(proc2.SetPolyFillMode.Addr(), 2,
uintptr(hdc), uintptr(mode), 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return co.POLYF(ret)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-setstretchbltmode
func (hdc HDC) SetStretchBltMode(mode co.STRETCH) co.STRETCH {
ret, _, err := syscall.Syscall(proc2.SetStretchBltMode.Addr(), 2,
uintptr(hdc), uintptr(mode), 0)
if ret == 0 {
panic(errco.ERROR(err))
}
return co.STRETCH(ret)
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-settextalign
func (hdc HDC) SetTextAlign(align co.TA) {
ret, _, err := syscall.Syscall(proc2.SetTextAlign.Addr(), 2,
uintptr(hdc), uintptr(align), 0)
if ret == _GDI_ERR {
panic(errco.ERROR(err))
}
}
// This method is called from the destination HDC.
//
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-stretchblt
func (hdc HDC) StretchBlt(
destTopLeft POINT, destSz SIZE,
hdcSrc HDC, srcTopLeft POINT, srcSz SIZE, rop co.ROP) {
ret, _, err := syscall.Syscall12(proc2.StretchBlt.Addr(), 11,
uintptr(hdc), uintptr(destTopLeft.X), uintptr(destTopLeft.Y),
uintptr(destSz.Cx), uintptr(destSz.Cy),
uintptr(hdcSrc), uintptr(srcTopLeft.X), uintptr(srcTopLeft.Y),
uintptr(srcSz.Cx), uintptr(srcSz.Cy), uintptr(rop), 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-strokeandfillpath
func (hdc HDC) StrokeAndFillPath() {
ret, _, err := syscall.Syscall(proc2.StrokeAndFillPath.Addr(), 1,
uintptr(hdc), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-strokepath
func (hdc HDC) StrokePath() {
ret, _, err := syscall.Syscall(proc2.StrokePath.Addr(), 1,
uintptr(hdc), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-textoutw
func (hdc HDC) TextOut(x, y int32, text string) {
lpString16 := Str.ToNativeSlice(text)
ret, _, err := syscall.Syscall6(proc2.TextOut.Addr(), 5,
uintptr(hdc), uintptr(x), uintptr(y),
uintptr(unsafe.Pointer(&lpString16[0])),
uintptr(len(lpString16)-1), 0)
runtime.KeepAlive(lpString16)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// This method is called from the destination HDC.
//
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-transparentblt
func (hdc HDC) TransparentBlt(
destTopLeft POINT, destSz SIZE,
hdcSrc HDC, srcTopLeft POINT, srcSz SIZE,
colorTransparent COLORREF) {
ret, _, err := syscall.Syscall12(proc2.TransparentBlt.Addr(), 11,
uintptr(hdc),
uintptr(destTopLeft.X), uintptr(destTopLeft.Y),
uintptr(destSz.Cx), uintptr(destSz.Cy),
uintptr(hdcSrc),
uintptr(srcTopLeft.X), uintptr(srcTopLeft.Y),
uintptr(srcSz.Cx), uintptr(srcSz.Cy),
uintptr(colorTransparent), 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}
// π https://docs.microsoft.com/en-us/windows/win32/api/wingdi/nf-wingdi-widenpath
func (hdc HDC) WidenPath() {
ret, _, err := syscall.Syscall(proc2.WidenPath.Addr(), 1,
uintptr(hdc), 0, 0)
if ret == 0 {
panic(errco.ERROR(err))
}
}