Repository navigation
Expand file tree
/
Copy pathui.go
More file actions
698 lines (597 loc) · 19.2 KB
/
Copy pathui.go
File metadata and controls
698 lines (597 loc) · 19.2 KB
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
package main
import (
"bytes"
"fmt"
"image/png"
"sync"
"syscall"
"unsafe"
"golang.org/x/sys/windows"
)
// ────────────────────────────────────────────────────────────
// UI globals — per-window data tracked via GWLP_USERDATA
// ────────────────────────────────────────────────────────────
const GWLP_USERDATA = -21
// uiData keeps Go references to per-window data structs alive, preventing
// GC from collecting them while they are referenced only by uintptr in GWLP_USERDATA.
var (
uiDataMu sync.Mutex
uiData = map[HANDLE]interface{}{}
)
type qrPopupData struct {
pngBytes []byte
charCount int
truncated bool
hBitmap HBITMAP
imgWidth int
imgHeight int
origWidth int
origHeight int
}
type scanResultData struct {
resultText string
}
// ────────────────────────────────────────────────────────────
// Window procedures
// ────────────────────────────────────────────────────────────
var (
qrProcVar uintptr
scanProcVar uintptr
resultProcVar uintptr
)
func init() {
qrProcVar = syscall.NewCallback(qrPopupWndProc)
scanProcVar = syscall.NewCallback(scanPreviewWndProc)
resultProcVar = syscall.NewCallback(resultPopupWndProc)
}
// ────────────────────────────────────────────────────────────
// QR Popup Window
// ────────────────────────────────────────────────────────────
func showQRPopup(pngBytes []byte, charCount int, wasTruncated bool) {
// Register class (once)
registerWindowClass(qrPopupClass, qrProcVar)
title := fmt.Sprintf("共 %d 字符", charCount)
if wasTruncated {
title = fmt.Sprintf("已截断,共 %d 字符", charCount)
}
// Decode PNG to get dimensions
img, err := png.Decode(bytes.NewReader(pngBytes))
if err != nil {
showError("二维码错误", "无法解码二维码图像")
return
}
bounds := img.Bounds()
imgW := bounds.Dx()
imgH := bounds.Dy()
// Create window at 300x300 with resizable border
hwnd, err := createWindow(
qrPopupClass, title,
0x00CF0000|0x00040000|0x00080000, // WS_OVERLAPPEDWINDOW style
100, 100, 300, 300, // initial position and size
0,
)
if err != nil {
showError("窗口错误", fmt.Sprintf("无法创建窗口: %v", err))
return
}
// Store per-window data
data := &qrPopupData{
pngBytes: pngBytes,
charCount: charCount,
truncated: wasTruncated,
origWidth: imgW,
origHeight: imgH,
}
// Allocate memory for the pointer and set it as GWLP_USERDATA
setWindowLongPtr(hwnd, GWLP_USERDATA, uintptr(unsafe.Pointer(data)))
showWindow(hwnd, 1) // SW_SHOWNORMAL
updateWindow(hwnd)
}
func qrPopupWndProc(hwnd HANDLE, msg UINT, wParam WPARAM, lParam LPARAM) LRESULT {
dataPtr := getWindowLongPtr(hwnd, GWLP_USERDATA)
data := (*qrPopupData)(unsafe.Pointer(dataPtr))
switch msg {
case WM_PAINT:
if data != nil {
paintQRPopup(hwnd, data)
}
return 0
case WM_SIZE:
// Force repaint on resize
invalidateRect(hwnd, nil, true)
return 0
case WM_GETMINMAXINFO:
// Set minimum size 150x150
if lParam != 0 {
mmi := (*MINMAXINFO)(unsafe.Pointer(lParam))
mmi.PtMinTrackSize = struct{ X, Y int32 }{150, 150}
}
return 0
case WM_ERASEBKGND:
// Prevent flicker — we paint everything in WM_PAINT
return 1
case WM_RBUTTONUP:
if data != nil {
copyQRToClipboard(data.pngBytes)
}
return 0
case WM_CLOSE:
// Free bitmap and data
if data != nil && data.hBitmap != 0 {
deleteBitmap(data.hBitmap)
}
destroyWindow(hwnd)
return 0
case WM_DESTROY:
// Clean up allocated data (allocated with new in showQRPopup)
uiDataMu.Lock()
delete(uiData, hwnd)
uiDataMu.Unlock()
return 0
}
user32 := windows.NewLazySystemDLL("user32.dll")
defProc := user32.NewProc("DefWindowProcW")
ret, _, _ := defProc.Call(uintptr(hwnd), uintptr(msg), wParam, lParam)
return LRESULT(ret)
}
func paintQRPopup(hwnd HANDLE, data *qrPopupData) {
gdi32 := windows.NewLazySystemDLL("gdi32.dll")
user32 := windows.NewLazySystemDLL("user32.dll")
// Get client area size
var rect RECT
user32.NewProc("GetClientRect").Call(uintptr(hwnd), uintptr(unsafe.Pointer(&rect)))
cw := int(rect.Right - rect.Left)
ch := int(rect.Bottom - rect.Top)
// Decode PNG
img, err := png.Decode(bytes.NewReader(data.pngBytes))
if err != nil {
return
}
// Calculate square area that fits in the window
side := cw
if ch < side {
side = ch
}
if side < 50 {
side = 50
}
offsetX := (cw - side) / 2
offsetY := (ch - side) / 2
// Get DC
beginPaint := user32.NewProc("BeginPaint")
var ps PAINTSTRUCT
hdc, _, _ := beginPaint.Call(uintptr(hwnd), uintptr(unsafe.Pointer(&ps)))
if hdc == 0 {
return
}
defer user32.NewProc("EndPaint").Call(uintptr(hwnd), uintptr(unsafe.Pointer(&ps)))
// Fill background white
fillRect := user32.NewProc("FillRect")
whiteBrush, _, _ := gdi32.NewProc("GetStockObject").Call(0) // WHITE_BRUSH = 0
fillRect.Call(hdc, uintptr(unsafe.Pointer(&rect)), whiteBrush)
// Create compatible DC and bitmap for the image
createCompatibleDC := gdi32.NewProc("CreateCompatibleDC")
memDC, _, _ := createCompatibleDC.Call(hdc)
if memDC == 0 {
return
}
defer gdi32.NewProc("DeleteDC").Call(memDC)
// Convert image to raw BGRA bytes for CreateDIBitmap
bounds := img.Bounds()
imgW := bounds.Dx()
imgH := bounds.Dy()
bgra := make([]byte, imgW*imgH*4)
for y := 0; y < imgH; y++ {
for x := 0; x < imgW; x++ {
r, g, b, a := img.At(x, y).RGBA()
offset := (y*imgW + x) * 4
bgra[offset] = byte(b >> 8) // B
bgra[offset+1] = byte(g >> 8) // G
bgra[offset+2] = byte(r >> 8) // R
bgra[offset+3] = byte(a >> 8) // A
}
}
// Create BITMAPINFO header
biSize := uint32(unsafe.Sizeof(BITMAPINFOHEADER{}))
bi := BITMAPINFO{
Header: BITMAPINFOHEADER{
Size: biSize,
Width: int32(imgW),
Height: -int32(imgH), // negative = top-down
Planes: 1,
BitCount: 32,
Compression: 0, // BI_RGB
SizeImage: 0,
XPelsPerMeter: 0,
YPelsPerMeter: 0,
ClrUsed: 0,
ClrImportant: 0,
},
}
createDIBitmap := gdi32.NewProc("CreateDIBitmap")
hBmp, _, _ := createDIBitmap.Call(
hdc,
uintptr(unsafe.Pointer(&bi.Header)),
4, // CBM_INIT
uintptr(unsafe.Pointer(&bgra[0])),
uintptr(unsafe.Pointer(&bi)),
0, // DIB_RGB_COLORS
)
if hBmp == 0 {
return
}
defer gdi32.NewProc("DeleteObject").Call(hBmp)
// Select bitmap into mem DC
selectObject := gdi32.NewProc("SelectObject")
oldBmp, _, _ := selectObject.Call(memDC, hBmp)
defer selectObject.Call(memDC, oldBmp)
// StretchBlt from mem DC to window DC, keeping square proportions
stretchBlt := gdi32.NewProc("StretchBlt")
stretchBlt.Call(
hdc,
uintptr(offsetX), uintptr(offsetY), uintptr(side), uintptr(side), // dest
memDC,
0, 0, uintptr(imgW), uintptr(imgH), // source
0x00CC0020, // SRCCOPY
)
}
func copyQRToClipboard(pngBytes []byte) {
// Decode PNG to get a HBITMAP
img, err := png.Decode(bytes.NewReader(pngBytes))
if err != nil {
return
}
bounds := img.Bounds()
imgW := bounds.Dx()
imgH := bounds.Dy()
bgra := make([]byte, imgW*imgH*4)
for y := 0; y < imgH; y++ {
for x := 0; x < imgW; x++ {
r, g, b, _ := img.At(x, y).RGBA()
offset := (y*imgW + x) * 4
bgra[offset] = byte(b >> 8)
bgra[offset+1] = byte(g >> 8)
bgra[offset+2] = byte(r >> 8)
bgra[offset+3] = 255
}
}
user32 := windows.NewLazySystemDLL("user32.dll")
gdi32 := windows.NewLazySystemDLL("gdi32.dll")
// Get screen DC
screenDC, _, _ := user32.NewProc("GetDC").Call(0)
if screenDC == 0 {
return
}
defer user32.NewProc("ReleaseDC").Call(0, screenDC)
bi := BITMAPINFO{
Header: BITMAPINFOHEADER{
Size: uint32(unsafe.Sizeof(BITMAPINFOHEADER{})),
Width: int32(imgW),
Height: -int32(imgH),
Planes: 1,
BitCount: 32,
Compression: 0,
},
}
hBmp, _, _ := gdi32.NewProc("CreateDIBitmap").Call(
screenDC,
uintptr(unsafe.Pointer(&bi.Header)),
4,
uintptr(unsafe.Pointer(&bgra[0])),
uintptr(unsafe.Pointer(&bi)),
0,
)
if hBmp == 0 {
return
}
defer gdi32.NewProc("DeleteObject").Call(hBmp)
user32.NewProc("OpenClipboard").Call(uintptr(mainHWND))
user32.NewProc("EmptyClipboard").Call()
user32.NewProc("SetClipboardData").Call(2, hBmp) // CF_BITMAP = 2
user32.NewProc("CloseClipboard").Call()
}
// ────────────────────────────────────────────────────────────
// Scan Preview Window
// ────────────────────────────────────────────────────────────
type scanPreviewData struct {
detected chan string // sent when QR is found
done chan struct{}
}
func showScanPreview(outHwnd *HANDLE) {
registerWindowClass(scanPreviewClass, scanProcVar)
hwnd, err := createWindow(
scanPreviewClass, "扫描二维码",
0x00CF0000|0x00040000|0x00080000,
200, 200, 480, 400,
0,
)
if err != nil {
showError("窗口错误", fmt.Sprintf("无法创建扫描窗口: %v", err))
return
}
data := &scanPreviewData{
detected: make(chan string, 1),
done: make(chan struct{}),
}
setWindowLongPtr(hwnd, GWLP_USERDATA, uintptr(unsafe.Pointer(data)))
uiDataMu.Lock()
uiData[hwnd] = data
uiDataMu.Unlock()
*outHwnd = hwnd
showWindow(hwnd, 1)
updateWindow(hwnd)
// When the user closes the window, signal camera to stop
// (the done channel is closed in scanPreviewWndProc WM_CLOSE)
}
func scanPreviewWndProc(hwnd HANDLE, msg UINT, wParam WPARAM, lParam LPARAM) LRESULT {
switch msg {
case WM_PAINT:
paintScanPreview(hwnd)
return 0
case WM_CLOSE:
// Signal camera to stop
dataPtr := getWindowLongPtr(hwnd, GWLP_USERDATA)
if dataPtr != 0 {
data := (*scanPreviewData)(unsafe.Pointer(dataPtr))
select {
case <-data.done:
// Already closed
default:
close(data.done)
}
}
// Post to main window to clean up
user32 := windows.NewLazySystemDLL("user32.dll")
postMsg := user32.NewProc("PostMessageW")
postMsg.Call(uintptr(mainHWND), WM_CLOSE_PREVIEW, 0, 0)
return 0
case WM_ERASEBKGND:
return 1
case WM_DESTROY:
// Handled — do NOT call DefWindowProcW to avoid PostQuitMessage
uiDataMu.Lock()
delete(uiData, hwnd)
uiDataMu.Unlock()
return 0
}
user32 := windows.NewLazySystemDLL("user32.dll")
defProc := user32.NewProc("DefWindowProcW")
ret, _, _ := defProc.Call(uintptr(hwnd), uintptr(msg), wParam, lParam)
return LRESULT(ret)
}
func paintScanPreview(hwnd HANDLE) {
user32 := windows.NewLazySystemDLL("user32.dll")
gdi32 := windows.NewLazySystemDLL("gdi32.dll")
var rect RECT
user32.NewProc("GetClientRect").Call(uintptr(hwnd), uintptr(unsafe.Pointer(&rect)))
cw := int(rect.Right - rect.Left)
ch := int(rect.Bottom - rect.Top)
var ps PAINTSTRUCT
hdc, _, _ := user32.NewProc("BeginPaint").Call(uintptr(hwnd), uintptr(unsafe.Pointer(&ps)))
if hdc == 0 {
return
}
defer user32.NewProc("EndPaint").Call(uintptr(hwnd), uintptr(unsafe.Pointer(&ps)))
// Fill black background
blackBrush, _, _ := gdi32.NewProc("GetStockObject").Call(4) // BLACK_BRUSH = 4
user32.NewProc("FillRect").Call(hdc, uintptr(unsafe.Pointer(&rect)), blackBrush)
// Draw green guide frame (centered, 60% of window)
frameW := int32(float64(cw) * 0.6)
frameH := int32(float64(ch) * 0.6)
frameX := (int32(cw) - frameW) / 2
frameY := (int32(ch) - frameH) / 2
// Create green pen
createPen := gdi32.NewProc("CreatePen")
greenPen, _, _ := createPen.Call(0, 3, 0x0000FF00) // PS_SOLID, width 3, BGR green
if greenPen != 0 {
oldPen, _, _ := gdi32.NewProc("SelectObject").Call(hdc, greenPen)
defer gdi32.NewProc("SelectObject").Call(hdc, oldPen)
defer gdi32.NewProc("DeleteObject").Call(greenPen)
}
// Draw hollow rectangle using brush
nullBrush, _, _ := gdi32.NewProc("GetStockObject").Call(5) // NULL_BRUSH
oldBrush, _, _ := gdi32.NewProc("SelectObject").Call(hdc, nullBrush)
defer gdi32.NewProc("SelectObject").Call(hdc, oldBrush)
selectObject := gdi32.NewProc("SelectObject")
selectObject.Call(hdc, greenPen)
selectObject.Call(hdc, nullBrush)
gdi32.NewProc("Rectangle").Call(
hdc,
uintptr(frameX), uintptr(frameY),
uintptr(frameX+frameW), uintptr(frameY+frameH),
)
// Draw hint text below frame
setBkMode := gdi32.NewProc("SetBkMode")
setBkMode.Call(hdc, 1) // TRANSPARENT
setTextColor := gdi32.NewProc("SetTextColor")
setTextColor.Call(hdc, 0x0000FF00) // Green text
hintText, _ := syscall.UTF16PtrFromString("请将二维码对准框内")
textRect := RECT{
Left: 0,
Top: frameY + frameH + 20,
Right: int32(cw),
Bottom: int32(ch),
}
user32.NewProc("DrawTextW").Call(
hdc,
uintptr(unsafe.Pointer(hintText)),
^uintptr(0), // -1 means auto-calculate text length
uintptr(unsafe.Pointer(&textRect)),
0x00000001|0x00000020, // DT_CENTER | DT_SINGLELINE
)
}
// ────────────────────────────────────────────────────────────
// Result Popup Window
// ────────────────────────────────────────────────────────────
type resultPopupData struct {
resultText string
}
func showScanResult(text string) {
registerWindowClass(resultPopupClass, resultProcVar)
title := "扫描结果"
hwnd, err := createWindow(
resultPopupClass, title,
0x00CF0000|0x00040000|0x00080000,
200, 200, 400, 250,
0,
)
if err != nil {
showError("窗口错误", fmt.Sprintf("无法创建结果窗口: %v", err))
return
}
data := &resultPopupData{resultText: text}
setWindowLongPtr(hwnd, GWLP_USERDATA, uintptr(unsafe.Pointer(data)))
uiDataMu.Lock()
uiData[hwnd] = data
uiDataMu.Unlock()
showWindow(hwnd, 1)
updateWindow(hwnd)
}
func resultPopupWndProc(hwnd HANDLE, msg UINT, wParam WPARAM, lParam LPARAM) LRESULT {
dataPtr := getWindowLongPtr(hwnd, GWLP_USERDATA)
data := (*resultPopupData)(unsafe.Pointer(dataPtr))
switch msg {
case WM_PAINT:
if data != nil {
paintResultPopup(hwnd, data)
}
return 0
case WM_ERASEBKGND:
return 1
case WM_CLOSE:
destroyWindow(hwnd)
return 0
case WM_DESTROY:
// Handled — do NOT call DefWindowProcW to avoid PostQuitMessage
uiDataMu.Lock()
delete(uiData, hwnd)
uiDataMu.Unlock()
return 0
}
user32 := windows.NewLazySystemDLL("user32.dll")
defProc := user32.NewProc("DefWindowProcW")
ret, _, _ := defProc.Call(uintptr(hwnd), uintptr(msg), wParam, lParam)
return LRESULT(ret)
}
func paintResultPopup(hwnd HANDLE, data *resultPopupData) {
user32 := windows.NewLazySystemDLL("user32.dll")
gdi32 := windows.NewLazySystemDLL("gdi32.dll")
var rect RECT
user32.NewProc("GetClientRect").Call(uintptr(hwnd), uintptr(unsafe.Pointer(&rect)))
var ps PAINTSTRUCT
hdc, _, _ := user32.NewProc("BeginPaint").Call(uintptr(hwnd), uintptr(unsafe.Pointer(&ps)))
if hdc == 0 {
return
}
defer user32.NewProc("EndPaint").Call(uintptr(hwnd), uintptr(unsafe.Pointer(&ps)))
// White background
whiteBrush, _, _ := gdi32.NewProc("GetStockObject").Call(0) // WHITE_BRUSH
user32.NewProc("FillRect").Call(hdc, uintptr(unsafe.Pointer(&rect)), whiteBrush)
// Draw text
setBkMode := gdi32.NewProc("SetBkMode")
setBkMode.Call(hdc, 1) // TRANSPARENT
// Padding
textRect := RECT{
Left: 10,
Top: 10,
Right: rect.Right - 10,
Bottom: rect.Bottom - 10,
}
text, _ := syscall.UTF16PtrFromString(data.resultText)
// DT_WORDBREAK = 0x10, DT_LEFT = 0x00
user32.NewProc("DrawTextW").Call(
hdc,
uintptr(unsafe.Pointer(text)),
^uintptr(0), // -1 means auto-calculate text length
uintptr(unsafe.Pointer(&textRect)),
0x00000000|0x00000010, // DT_LEFT | DT_WORDBREAK
)
}
// ────────────────────────────────────────────────────────────
// Win32 helper structs and functions
// ────────────────────────────────────────────────────────────
type RECT struct {
Left, Top, Right, Bottom int32
}
type PAINTSTRUCT struct {
HDC HDC
FErase BOOL
RcPaint RECT
FRestore BOOL
FIncUpdate BOOL
RgbReserved [32]byte
}
type BITMAPINFOHEADER struct {
Size uint32
Width int32
Height int32
Planes uint16
BitCount uint16
Compression uint32
SizeImage uint32
XPelsPerMeter int32
YPelsPerMeter int32
ClrUsed uint32
ClrImportant uint32
}
type BITMAPINFO struct {
Header BITMAPINFOHEADER
Colors [1]uint32 // placeholder
}
type MINMAXINFO struct {
PtReserved struct{ X, Y int32 }
PtMaxSize struct{ X, Y int32 }
PtMaxPosition struct{ X, Y int32 }
PtMinTrackSize struct{ X, Y int32 }
PtMaxTrackSize struct{ X, Y int32 }
}
func setWindowLongPtr(hwnd HANDLE, index int32, value uintptr) {
user32 := windows.NewLazySystemDLL("user32.dll")
setWindowLong := user32.NewProc("SetWindowLongPtrW")
setWindowLong.Call(uintptr(hwnd), uintptr(index), value)
}
func getWindowLongPtr(hwnd HANDLE, index int32) uintptr {
user32 := windows.NewLazySystemDLL("user32.dll")
getWindowLong := user32.NewProc("GetWindowLongPtrW")
val, _, _ := getWindowLong.Call(uintptr(hwnd), uintptr(index))
return val
}
func showWindow(hwnd HANDLE, cmdShow int32) {
user32 := windows.NewLazySystemDLL("user32.dll")
show := user32.NewProc("ShowWindow")
show.Call(uintptr(hwnd), uintptr(cmdShow))
}
func updateWindow(hwnd HANDLE) {
user32 := windows.NewLazySystemDLL("user32.dll")
update := user32.NewProc("UpdateWindow")
update.Call(uintptr(hwnd))
}
func destroyWindow(hwnd HANDLE) {
user32 := windows.NewLazySystemDLL("user32.dll")
destroy := user32.NewProc("DestroyWindow")
destroy.Call(uintptr(hwnd))
}
func closeWindow(hwnd HANDLE) {
user32 := windows.NewLazySystemDLL("user32.dll")
closeWin := user32.NewProc("CloseWindow")
closeWin.Call(uintptr(hwnd))
}
func invalidateRect(hwnd HANDLE, rect *RECT, erase bool) {
user32 := windows.NewLazySystemDLL("user32.dll")
inv := user32.NewProc("InvalidateRect")
var b uintptr
if erase {
b = 1
}
inv.Call(uintptr(hwnd), uintptr(unsafe.Pointer(rect)), b)
}
func deleteBitmap(hBmp HBITMAP) {
gdi32 := windows.NewLazySystemDLL("gdi32.dll")
gdi32.NewProc("DeleteObject").Call(uintptr(hBmp))
}
// ────────────────────────────────────────────────────────────
// Message box convenience
// ────────────────────────────────────────────────────────────
const WM_NULL = 0x0000
// Stub — full definition in main.go
// showError and showAboutDialog are defined in main.go