-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgdi.ahk
3193 lines (2671 loc) · 120 KB
/
gdi.ahk
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
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; GDI library for AHK v1.1.
; made by Marius Șucan
; License: NONE
; Contains trace amounts from:
; GDI class by GeekDuede https://www.autohotkey.com/boards/viewtopic.php?t=5820
; It also contains GDI functions already found in GDI+ library made by Tic.
; https://github.com/marius-sucan/AHK-GDIp-Library-Compilation
; It also contains functions borrowed and modified from Font Library 3 by jBalli.
; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=4379
; Other functions added by Marius Șucan.
; Last update on: mercredi samedi 21 janvier 2023; 21/01/2023
; version: 1.31
Gdi_DrawTextHelper(hDC, hFont, Text, x, y, txtColor, bgrColor:="") {
; Transparent background, no color needed
If (bgrColor="")
Gdi_SetBgrMode(hDC, 1)
Else
Gdi_SetBgrColor(hDC, bgrColor)
Gdi_SetTextColor(hDC, txtColor)
hOriginalFont := Gdi_SelectObject(hDC, hFont)
; Gdi_DrawText(hDC, Text, 0, 0, 900, 900, "LT")
E := Gdi_TextOut(hDC, Text, x, y)
Gdi_SelectObject(hDC, hOriginalFont)
; ToolTip, % E " , " hdc " , " hFont " , " txtColor " , " bgrColor "`n" x ";" y ";" w ";" h "`n" text, , , 2
Return E
}
Gdi_TextOut(hDC, Text, x, y) {
Return DllCall("gdi32\TextOut", "UPtr", hDC, "Int", x, "Int", y, "Str", Text, "Int", StrLen(Text))
}
Gdi_DrawText(hDC, Text, x, y, w, h, flags:=0) {
; For the «flags» parameter you can use any of the following
; DT_Format flags separated by |. Please omit the DT_ prefix.
; e.g., "left|vcenter|wordbreak"
; DrawText flags
Static DT_LEFT := 0x0
;-- Aligns text to the left. Note: This format is used by
; default unless there is an overriding format (Ex: DT_RIGHT).
, DT_TOP := 0x0
;-- Justifies the text to the top of the rectangle. Note: This
; format is used by default unless there is an overriding
; format (Ex: DT_BOTTOM).
, DT_CENTER := 0x1
;-- Centers text horizontally in the rectangle.
, DT_RIGHT := 0x2
;-- Aligns text to the right.
, DT_VCENTER := 0x4
;-- Centers text vertically. This value is used only with the
; DT_SINGLELINE format.
, DT_BOTTOM := 0x8
;-- Justifies the text to the bottom of the rectangle. This
; format is used only with the DT_SINGLELINE format.
, DT_WORDBREAK := 0x10
;-- Breaks words. Lines are automatically broken between words
; if a word extends past the edge of the rectangle specified
; by the lprc parameter. A carriage return-line feed sequence
; also breaks the line.
, DT_SINGLELINE := 0x20
;-- Displays text on a single line only. Carriage returns and
; line feeds do not break the line.
, DT_EXPANDTABS := 0x40
;-- Expands tab characters. The default number of characters
; per tab is eight.
, DT_TABSTOP := 0x80
;-- Sets tab stops. The DRAWTEXTPARAMS structure pointed to by
; the lpDTParams parameter specifies the number of average
; character widths per tab stop.
, DT_NOCLIP := 0x100
;-- Draws without clipping. DrawTextEx is somewhat faster when
; DT_NOCLIP is used.
, DT_EXTERNALLEADING := 0x200
;-- Includes the font external leading in line height.
; Normally, external leading is not included in the height of
; a line of text.
, DT_CALCRECT := 0x400
;-- Determines the width and height of the rectangle. The text
; is not drawn.
, DT_NOPREFIX := 0x800
;-- Turns off processing of prefix characters. Normally,
; DrawTextEx interprets the ampersand (&) mnemonic-prefix
; character as a directive to underscore the character that
; follows, and the double-ampersand (&&) mnemonic-prefix
; characters as a directive to print a single ampersand. By
; specifying DT_NOPREFIX, this processing is turned off.
; Compare with DT_HIDEPREFIX and DT_PREFIXONLY.
, DT_INTERNAL := 0x1000
;-- Uses the system font to calculate text metrics.
, DT_EDITCONTROL := 0x2000
;-- Duplicates the text-displaying characteristics of a
; multiline edit control. Specifically, the average character
; width is calculated in the same manner as for an Edit
; control, and the function does not display a partially
; visible last line.
, DT_PATHELLIPSIS := 0x4000 ;-- Alias
, DT_PATH_ELLIPSIS := 0x4000
;-- For displayed text, replaces characters in the middle of the
; string with ellipses so that the result fits in the
; specified rectangle. If the string contains backslash (\)
; characters, DT_PATH_ELLIPSIS preserves as much as possible
; of the text after the last backslash. The string is not
; modified unless the DT_MODIFYSTRING flag is specified.
; Compare with DT_END_ELLIPSIS and DT_WORD_ELLIPSIS.
, DT_ENDELLIPSIS := 0x8000 ;-- Alias
, DT_END_ELLIPSIS := 0x8000
;-- For displayed text, replaces the end of a string with
; ellipses so that the result fits in the specified rectangle.
; Any word (not at the end of the string) that goes beyond the
; limits of the rectangle is truncated without ellipses. The
; string is not modified unless the DT_MODIFYSTRING flag is
; specified. Compare with DT_PATH_ELLIPSIS and
; DT_WORD_ELLIPSIS.
, DT_MODIFYSTRING := 0x10000
;-- Modifies the specified string to match the displayed text.
; This format has no effect unless DT_END_ELLIPSIS or
; DT_PATH_ELLIPSIS is specified.
, DT_RTLREADING := 0x20000
;-- Layout in right-to-left reading order for bidirectional text
; when the font selected into the hdc is a Hebrew or Arabic
; font. The default reading order for all text is
; left-to-right.
, DT_WORDELLIPSIS := 0x40000 ;-- Alias
, DT_WORD_ELLIPSIS := 0x40000
;-- Truncates any word that does not fit in the rectangle and
; adds ellipses. Compare with DT_END_ELLIPSIS and
; DT_PATH_ELLIPSIS.
, DT_NOFULLWIDTHCHARBREAK := 0x80000
;-- Prevents a line break at a DBCS (double-wide character
; string), so that the line-breaking rule is equivalent to
; SBCS strings. For example, this can be used in Korean
; windows, for more readability of icon labels. This format
; has no effect unless DT_WORDBREAK is specified.
, DT_HIDEPREFIX := 0x100000
;-- Ignores the ampersand (&) prefix character in the text. The
; letter that follows will not be underlined, but other
; mnemonic-prefix characters are still processed. Compare
; with DT_NOPREFIX and DT_PREFIXONLY. See the full
; documentation on this flag for examples.
, DT_PREFIXONLY := 0x200000
;-- Draws only an underline at the position of the character
; following the ampersand (&) prefix character. Does not draw
; any character in the string. Compare with DT_NOPREFIX and
; DT_HIDEPREFIX. See the full documentation on this flag for
; examples.
DT_Format := 0x0
Loop, Parse, flags, |
{
If DT_%A_LoopField% is not Space
DT_Format|=DT_%A_LoopField%
}
obju := []
VarSetCapacity(Rect, 16, 0)
NumPut(x, Rect, 0, "uint"), NumPut(y, Rect, 4, "uint")
NumPut(x + w, Rect, 8, "uint"), NumPut(y + h, Rect, 12, "uint")
E := DllCall("user32\DrawText", "UPtr", hDC, "Str", Text, "Int", -1, "UPtr", &Rect, "UInt", DT_Format)
obju.w := NumGet(Rect, 8, "Int")
obju.h := NumGet(Rect, 12, "Int")
obju.dll := E
; ToolTip, % DT_Format " === " E " == " obju.w "===" obju.h " ===`n" flags , , , 2
Return obju
}
Gdi_CreateRectRegion(x, y, x2, y2) {
Return DllCall("gdi32\CreateRectRgn", "Int", x, "Int", y, "Int", x2, "Int", y2, "Ptr")
}
Gdi_CreateRoundRectRegion(x, y, x2, y2, w, h) {
; w, h - width and height of the ellipse used to create the rounded corners in device units.
Return DllCall("gdi32\CreateRoundRectRgn", "Int", x, "Int", y, "Int", x2, "Int", y2, "Int", w, "Int", h, "Ptr")
}
Gdi_CreateEllipticRegion(x, y, x2, y2) {
Return DllCall("gdi32\CreateEllipticRgn", "Int", x, "Int", y, "Int", x2, "Int", y2, "Ptr")
}
Gdi_CombineRegion(hRgnDst, hRgn1, hRgn2, mode) {
; The CombineRgn function combines two regions and stores the result
; in a third region. The two regions are combined according to
; the specified mode.
; Mode options:
; RGN_AND = 1
; RGN_OR = 2
; RGN_XOR = 3
; RGN_DIFF = 4
; RGN_COPY = 5
Return DllCall("gdi32\CombineRgn", "Ptr", hRgnDst, "Ptr", hRgn1, "Ptr", hRgn2, "UInt", mode)
}
Gdi_EqualRegions(hRgn1, hRgn2) {
; The EqualRgn function checks the two specified regions to determine
; whether they are identical. The function considers two regions
; identical if they are equal in size and shape.
; Return value
; If the two regions are equal, the return value is nonzero.
; If the two regions are not equal, the return value is zero.
; A return value of ERROR means at least one of the region
; handles is invalid.
Return DllCall("gdi32\EqualRgn", "Ptr", hRgn1, "Ptr", hRgn2)
}
Gdi_FillRegion(hDC, hRgn, hBrush) {
; Return value
; If the function succeeds, the return value is nonzero.
; If the function fails, the return value is zero.
If (hBrush && hRgn && hDC)
Return DllCall("gdi32\FillRgn", "UPtr", hDC, "UPtr", hRgn, "UPtr", hBrush)
}
Gdi_PaintRegion(hDC, hRgn) {
; The function paints the specified region by using the brush
; currently selected into the device context.
; Return value
; If the function succeeds, the return value is nonzero.
; If the function fails, the return value is zero.
Return DllCall("gdi32\PaintRgn", "UPtr", hDC, "UPtr", hRgn)
}
Gdi_FrameRegion(hDC, hRgn, hBrush, w, h) {
; w = specifies the width, in logical units, of vertical brush strokes.
; h = specifies the height, in logical units, of horizontal brush strokes.
; Return value
; If the function succeeds, the return value is nonzero.
; If the function fails, the return value is zero.
Return DllCall("gdi32\FillRgn", "UPtr", hDC, "UPtr", hRgn, "UPtr", hBrush, "Int", w, "Int", h)
}
Gdi_GetPolyFillMode(hDC) {
; Return value
; If the function succeeds, the return value specifies the polygon fill mode,
; which can be one of the following values.
; 1 = ALTERNATE
; Selects alternate mode (fills area between odd-numbered and even
;-numbered polygon sides on each scan line).
; 2 = WINDING
; Selects winding mode (fills any region with a nonzero winding value).
; If an error occurs, the return value is zero.
Return DllCall("gdi32\GetPolyFillMode", "UPtr", hDC)
}
Gdi_SetPolyFillMode(hDC, mode) {
; Mode options:
; 1 = ALTERNATE
; Selects alternate mode (fills area between odd-numbered and even
;-numbered polygon sides on each scan line).
; 2 = WINDING
; Selects winding mode (fills any region with a nonzero winding value).
; Return value
; The return value specifies the previous filling mode. If an error
; occurs, the return value is zero.
; Remarks
; In general, the modes differ only in cases where a complex, overlapping
; polygon must be filled (for example, a five-sided polygon that forms a five-
; pointed star with a pentagon in the center). In such cases, ALTERNATE mode
; fills every other enclosed region within the polygon (that is, the points of the
; star), but WINDING mode fills all regions (that is, the points and the pentagon).
; When the fill mode is ALTERNATE, GDI fills the area between odd-numbered and
; even-numbered polygon sides on each scan line. That is, GDI fills the area
; between the first and second side, between the third and fourth side, and so on.
; When the fill mode is WINDING, GDI fills any region that has a nonzero winding
; value. This value is defined as the number of times a pen used to draw the
; polygon would go around the region. The direction of each edge of the polygon is important.
Return DllCall("gdi32\SetPolyFillMode", "UPtr", hDC, "Int", mode)
}
Gdi_GetRandomRegion(hDC, hRgn) {
; hrgn - A handle to a pre-existing region. After the function returns,
; this identifies a copy of the current system region.
; The old region identified by hrgn is overwritten.
; Return value
; If the function succeeds, the return value is 1. If the function fails,
; the return value is -1. If the region to be retrieved is NULL,
; the return value is 0. If the function fails or the region to be
; retrieved is NULL, hrgn is not initialized.
; The region returned is in screen coordinates.
; Remarks
; Note that the system clipping region might not be current because of
; window movements. Nonetheless, it is safe to retrieve and use the system
; clipping region within the BeginPaint - EndPaint block during WM_PAINT
; processing. In this case, the system region is the intersection of the
; update region and the current visible area of the window. Any window
; movement following the return of GetRandomRgn and before EndPaint will
; result in a new WM_PAINT message. Any other use of the SYSRGN flag
; may result in painting errors in your application.
Return DllCall("gdi32\GetRandomRgn", "UPtr", hDC, "UPtr", hRgn, "Int", 4)
}
Gdi_GetMetaRegion(hDC, hRgn) {
; The function retrieves the current metaregion for the specified hDC.
; hrgn - A handle to a pre-existing region. After the function returns,
; this parameter is a handle to a copy of the current metaregion.
; Return value
; If the function succeeds, the return value is nonzero.
; If the function fails, the return value is zero.
; Remarks
; If the function succeeds, hrgn is a handle to a copy of the current
; metaregion. Subsequent changes to this copy will not affect the
; current metaregion.
; The current clipping region of a device context is defined by the
; intersection of its clipping region and its metaregion.
Return DllCall("gdi32\GetMetaRgn", "UPtr", hDC, "UPtr", hRgn)
}
Gdi_SetMetaRegion(hDC) {
; The function intersects the current clipping region for the specified
; device context with the current metaregion and saves the combined
; region as the new metaregion for the specified device context.
; The clipping region is reset to a null region.
; Return value
; The return value specifies the new clipping region's complexity and can
; be one of the following values:
; 1 = NULLREGION - Region is empty.
; 2 = SIMPLEREGION - Region is a single rectangle.
; 3 = COMPLEXREGION - Region is more than one rectangle.
; 0 = An error occurred. The previous clipping region is unaffected.
; Remarks
; The function should only be called after an application's original
; device context was saved by calling the SaveDC function.
Return DllCall("gdi32\SetMetaRgn", "UPtr", hDC)
}
Gdi_GetRegionBox(hRgn) {
; The function retrieves the bounding box of the given hRgn [region handle]
; The function will return an object.
; obju.x1, obju.y1, obju.x2, obju.y2 - the coordinates of two points representing the bounding box
; x1, y1 - top, left corner
; x2, y2 - bottom, right corner
; obj.E - the value returned by the internal API. It defines the region complexity.
; 1 = NULLREGION - Region is empty.
; 2 = SIMPLEREGION - Region is a single rectangle.
; 3 = COMPLEXREGION - Region is more than one rectangle.
; 0 = An error occurred.
VarSetCapacity(Rect, 16, 0)
obju.E := DllCall("gdi32\GetRgnBox", "UPtr", hRgn, "UPtr", &Rect)
obju.x1 := NumGet(Rect, 0, "uint")
obju.y1 := NumGet(Rect, 4, "uint")
obju.x2 := NumGet(Rect, 8, "uint")
obju.y2 := NumGet(Rect, 12, "uint")
Return obju
}
Gdi_InvertColorsRegion(hDC, hRgn) {
; The function inverts the colors in the specified region.
; Return value
; If the function succeeds, the return value is nonzero.
; If the function fails, the return value is zero.
Return DllCall("gdi32\InvertRgn", "UPtr", hDC, "UPtr", hRgn)
}
Gdi_InvertColorsRect(hDC, x, y, w, h) {
; The function inverts the colors in the specified region.
; Return value
; If the function succeeds, the return value is nonzero.
; If the function fails, the return value is zero.
VarSetCapacity(Rect, 16, 0)
NumPut(x, Rect, 0, "uint"), NumPut(y, Rect, 4, "uint")
NumPut(x + w, Rect, 8, "uint"), NumPut(y + h, Rect, 12, "uint")
Return DllCall("gdi32\InvertRect", "UPtr", hDC, "UPtr", &Rect)
}
Gdi_PatBlt(hDC, x, y, w, h, mRop) {
; The function paints the specified rectangle using the brush that
; is currently selected into the specified hDC. The brush color and
; the surface color or colors are combined by using the specified
; raster operation [mRop].
; mRop options:
; PATCOPY = 0x00F00021
; PATINVERT = 0x005A0049
; DSTINVERT = 0x00550009
; BLACKNESS = 0x00000042
; WHITENESS = 0x00FF0062
; Return value
; If the function succeeds, the return value is nonzero.
; If the function fails, the return value is zero.
Return DllCall("gdi32\PatBlt", "UPtr", hDC, "Int", x, "Int", y, "Int", w, "Int", h, "uInt", mRop)
}
Gdi_OffsetRegion(hRgn, x, y) {
; Return value defines the region complexity.
; 1 = NULLREGION - Region is empty.
; 2 = SIMPLEREGION - Region is a single rectangle.
; 3 = COMPLEXREGION - Region is more than one rectangle.
; 0 = An error occurred.
Return DllCall("gdi32\OffsetRgn", "UPtr", hRgn, "Int", x, "Int", y)
}
Gdi_SetRectRegion(hRgn, x, y, w, h) {
; The function converts a region into a rectangular region with the specified coordinates.
; Return value
; If the specified point is in the region, the return value is nonzero.
; If the specified point is not in the region, the return value is zero.
Return DllCall("gdi32\SetRectRgn", "UPtr", hRgn, "Int", x, "Int", y, "Int", x + w, "Int", y + h)
}
Gdi_IsPointInRegion(hRgn, x, y) {
; The function determines whether the specified point is inside the specified region.
; Return value
; If the specified point is in the region, the return value is nonzero.
; If the specified point is not in the region, the return value is zero.
Return DllCall("gdi32\PtInRegion", "UPtr", hRgn, "Int", x, "Int", y)
}
Gdi_IsRectInRegion(hRgn, x, y, w, h) {
; The function determines whether any part of the specified rectangle
; is within the boundaries of a region.
; Return value
; If any part of the specified rectangle lies within the boundaries of the
; region, the return value is nonzero. Otherwise, the value is zero.
VarSetCapacity(Rect, 16, 0)
NumPut(x, Rect, 0, "uint"), NumPut(y, Rect, 4, "uint")
NumPut(x + w, Rect, 8, "uint"), NumPut(y + h, Rect, 12, "uint")
Return DllCall("gdi32\RectInRegion", "UPtr", hRgn, "UPtr", &Rect)
}
Gdi_DrawTextOutline(hDC, hFont, Text, x, y, BorderColor, BorderWidth) {
Pen := Gdi_CreatePen(BorderColor, BorderWidth)
hOriginalPen := Gdi_SelectObject(hDC, Pen)
hOriginalFont := Gdi_SelectObject(hDC, hFont)
Gdi_BeginPath(hDC)
Gdi_SetBgrMode(hDC, 1)
; E1 := Gdi_DrawText(hDC, Text, x, y, w, h, Alignment)
E1 := Gdi_TextOut(hDC, Text, x, y)
Gdi_EndPath(hDC)
E2 := Gdi_StrokePath(hDC)
Gdi_SelectObject(hDC, hOriginalPen)
Gdi_SelectObject(hDC, hOriginalFont)
Gdi_DeleteObject(Pen)
; Gdi_DeleteObject(hRgn)
; ToolTip, % E1 " , " E2 " , " hdc " , " hFont " , " borderColor " , " BorderWidth "`n" pen ";" y ";" w ";" h "`n" text, , , 2
Return E1
}
Gdi_GetTextExtentPoint32(hDC, string, ByRef w, ByRef h) {
VarSetCapacity(SIZE, 8, 0)
E := DllCall("gdi32\GetTextExtentPoint32"
,"UPtr", hDC ;-- hDC
,"Str", string ;-- lpString
,"Int", StrLen(string) ;-- c (string length)
,"Ptr", &SIZE) ;-- lpSize
w := NumGet(SIZE, 0, "Int")
h := NumGet(SIZE, 4, "Int")
Return E
}
Gdi_MeasureString(hFont, string, precision, ByRef w, ByRef h) {
; precision = 0 ; uses GetTextExtentExPoint()
; precision = 1 ; uses DrawText()
hDC := Gdi_GetDC()
old_hFont := Gdi_SelectObject(hDC, hFont)
If (precision=1)
obju := Gdi_DrawText(hDC, string, 0, 0, 0, 0, "CALCRECT|NOCLIP|NOPREFIX|SINGLELINE")
Else
E := Gdi_GetTextExtentPoint32(hDC, string, w, h)
If (precision=1)
{
w := obju.w
h := obju.h
E := obju.dll
}
Gdi_SelectObject(hDC, old_hFont)
Gdi_ReleaseDC(hDC, 0)
Return E
}
Gdi_SelectClipRegion(hDC, hRgn) {
; The function selects a region as the current clipping
; region for the specified device context.
; Return values:
; 1 = NULLREGION - Region is empty.
; 2 = SIMPLEREGION - Region is a single rectangle.
; 3 = COMPLEXREGION - Region is more than one rectangle.
; 0 = An error occurred. The previous clipping region is unaffected.
Return DllCall("gdi32\SelectClipRgn", "UPtr", hDC, "UPtr", hRgn)
}
Gdi_GetClipBox(hDC) {
; The function retrieves the dimensions of the tightest bounding rectangle
; that can be drawn around the current visible area on the device.
; The visible area is defined by the current clipping region or clip path,
; as well as any overlapping windows.
; GetClipBox returns logical coordinates based on the given device context.
; The function will return an object.
; obju.x1, obju.y1, obju.x2, obju.y2 - the coordinates of two points representing the bounding box
; x1, y1 - top, left corner
; x2, y2 - bottom, right corner
; obj.E - the value returned by the internal API. It defines the region complexity.
; 1 = NULLREGION - Region is empty.
; 2 = SIMPLEREGION - Region is a single rectangle.
; 3 = COMPLEXREGION - Region is more than one rectangle.
; 0 = An error occurred.
VarSetCapacity(Rect, 16, 0)
obju.E := DllCall("gdi32\GetClipBox", "UPtr", hDC, "UPtr", &Rect)
obju.x1 := NumGet(Rect, 0, "uint")
obju.y1 := NumGet(Rect, 4, "uint")
obju.x2 := NumGet(Rect, 8, "uint")
obju.y2 := NumGet(Rect, 12, "uint")
Return obju
}
Gdi_ExtSelectClipRgn(hDC, hRgn, mode) {
; Parameters:
; hrgn - A handle to the region to be selected. This handle must not be
; NULL unless the RGN_COPY mode is specified.
; Modes:
; RGN_AND = 1
; The new clipping region includes the intersection (overlapping areas) of the current clipping region and the current path.
; RGN_OR = 2
; The new clipping region includes the union (combined areas) of the current clipping region and the current path.
; RGN_XOR = 3
; The new clipping region includes the union of the current clipping region and the current path but without the overlapping areas.
; RGN_DIFF = 4
; The new clipping region includes the areas of the current clipping region with those of the current path excluded.
; RGN_COPY = 5
; The new clipping region is the current path.
; Return value
; The return value specifies the new clipping region's complexity; it can
; be one of the following values:
; 1 = NULLREGION - Region is empty.
; 2 = SIMPLEREGION - Region is a single rectangle.
; 3 = COMPLEXREGION - Region is more than one rectangle.
; 0 = An error occurred.
; Remarks
; If an error occurs when this function is called, the previous clipping
; region for the specified device context is not affected.
; This function assumes that the coordinates for the specified region
; are specified in device units.
; Only a copy of the region identified by the hRgn parameter is used.
; The region itself can be reused after this call or it can be deleted.
Return DllCall("gdi32\ExtSelectClipRgn", "UPtr", hDC, "UPtr", hRgn, "Int", mode)
}
Gdi_ClipPointVisible(hDC, x, y) {
; The function determines whether the specified point is within the
; clipping region of a device context.
; Return value
; If the specified point is within the clipping region of the hDC,
; the return value is TRUE (1).
; If the specified point is not within the clipping region of the hDC,
; the return value is FALSE (0).
; If the hDC is not valid, the return value is -1.
Return DllCall("gdi32\PtVisible", "UPtr", hDC, "Int", x, "Int", y)
}
Gdi_ClipRectVisible(hDC, x, y, w, h) {
; The function determines whether any part of the specified rectangle
; lies within the clipping region of a device context.
VarSetCapacity(Rect, 16, 0)
NumPut(x, Rect, 0, "uint"), NumPut(y, Rect, 4, "uint")
NumPut(x + w, Rect, 8, "uint"), NumPut(y + h, Rect, 12, "uint")
Return DllCall("gdi32\RectVisible", "UPtr", hDC, "UPtr", &Rect)
}
Gdi_GetClipRegion(hDC, hRgn) {
; The function retrieves a handle identifying the current application
;-defined clipping region for the specified device context.
; hrgn - A handle to an existing region before the function is called.
; After the function returns, this parameter is a handle to a copy of
; the current clipping region.
; Return value
; If the function succeeds and there is no clipping region for the given
; device context, the return value is zero. If the function succeeds and
; there is a clipping region for the given DC, the return value is 1.
; If an error occurs, the return value is -1.
; Remarks
; An application-defined clipping region is a clipping region identified
; by the SelectClipRgn function. It is not a clipping region created when
; the application calls the BeginPaint function.
; If the function succeeds, the hRgn parameter is a handle to a copy of
; the current clipping region. Subsequent changes to this copy will
; not affect the current clipping region.
Return DllCall("gdi32\GetClipRgn", "UPtr", hDC, "UPtr", hRgn)
}
Gdi_SelectClipPath(hDC, mode) {
; The SelectClipPath function selects the current path as a clipping region
; for a device context, combining the new region with any existing clipping
; region using the specified mode. The provided path must be a closed path.
; Modes:
; RGN_AND = 1
; The new clipping region includes the intersection (overlapping areas) of the current clipping region and the current path.
; RGN_OR = 2
; The new clipping region includes the union (combined areas) of the current clipping region and the current path.
; RGN_XOR = 3
; The new clipping region includes the union of the current clipping region and the current path but without the overlapping areas.
; RGN_DIFF = 4
; The new clipping region includes the areas of the current clipping region with those of the current path excluded.
; RGN_COPY = 5
; The new clipping region is the current path.
Return DllCall("gdi32\SelectClipPath", "UPtr", hDC, "int", mode)
}
Gdi_IntersectClipRect(hDC, x, y, x2, y2) {
; The SelectClipRgn function selects a region as the current clipping
; region for the specified device context.
; Return values:
; 1 = NULLREGION - Region is empty.
; 2 = SIMPLEREGION - Region is a single rectangle.
; 3 = COMPLEXREGION - Region is more than one rectangle.
; 0 = An error occurred. The previous clipping region is unaffected.
Return DllCall("gdi32\IntersectClipRect", "UPtr", hDC, "Int", x, "Int", y, "Int", x2, "Int", y2)
}
Gdi_OffsetClipRegion(hDC, x, y) {
; The OffsetClipRgn function moves the clipping region of a
; device context by the specified offsets.
; Return values:
; 1 = NULLREGION - Region is empty.
; 2 = SIMPLEREGION - Region is a single rectangle.
; 3 = COMPLEXREGION - Region is more than one rectangle.
; 0 = An error occurred.
Return DllCall("gdi32\OffsetClipRgn", "UPtr", hDC, "Int", x, "Int", y)
}
Gdi_ExcludeClipRect(hDC, x, y, x2, y2) {
; The ExcludeClipRect function creates a new clipping region that consists
; of the existing clipping region minus the specified rectangle.
; Return values:
; 1 = NULLREGION - Region is empty.
; 2 = SIMPLEREGION - Region is a single rectangle.
; 3 = COMPLEXREGION - Region is more than one rectangle.
; 0 = An error occurred. The previous clipping region is unaffected.
Return DllCall("gdi32\ExcludeClipRect", "UPtr", hDC, "Int", x, "Int", y, "Int", x2, "Int", y2)
}
Gdi_SetTextAlign(hDC, flags) {
; TA_LEFT = 0
; TA_RIGHT = 2
; TA_CENTER = 6
; TA_TOP = 0
; TA_BOTTOM = 8
; TA_BASELINE = 24
; TA_RTLREADING = 256
; Middle East language edition of Windows: The text is laid out in
; right to left reading order, as opposed to the default left to right
; order. This applies only when the font selected into the
; device context is either Hebrew or Arabic.
; TA_NOUPDATECP = 0
; The current position is not updated after each text output
; call. The reference point is passed to the text output function.
; TA_UPDATECP = 1
; The current position is updated after each text output call. The
; current position is used as the reference point.
; Vertical alignment:
; VTA_BASELINE = TA_BASELINE
; VTA_LEFT = TA_BOTTOM
; VTA_RIGHT = TA_TOP
; VTA_CENTER = TA_CENTER
; VTA_BOTTOM = TA_RIGHT
; VTA_TOP = TA_LEFT
; The SetTextAlign function sets the text-alignment flags for the
; specified device context.
; To set text alignment use the bit-wise OR operator |
; Example: 2|24
; Equivalent to: TA_RIGHT|VTA_BASELINE
; Default values for an hDC are TA_LEFT, TA_TOP, and TA_NOUPDATECP.
Return DllCall("gdi32\SetTextAlign", "UPtr", hDC, "UInt", flags)
}
Gdi_SetTextColor(hDC, color) {
Return DllCall("gdi32\SetTextColor", "UPtr", hDC, "UInt", color)
}
Gdi_SetTextJustification(hDC, extraSpace, countBreaks) {
; The SetTextJustification function specifies the amount of space the
; system should add to the break characters in a string of text.
; The space is added when an application calls the TextOut
; or ExtTextOut functions.
; extraSpace
; The total extra space, in logical units, to be added to the line of
; text. If the current mapping mode is not MM_TEXT, the value
; identified by the nBreakExtra parameter is transformed and rounded
; to the nearest pixel.
; countBreaks
; The number of break characters in the line.
; Return value
; If the function succeeds, the return value is nonzero.
; Remarks
; The break character is usually the space character (ASCII 32),
; but it may be defined by a font as some other character.
; The GetTextMetrics function can be used to retrieve a
; font's break character.
; The TextOut function distributes the specified extra space evenly
; among the break characters in the line.
; The GetTextExtentPoint32 function is always used with
; the SetTextJustification function. Sometimes the
; GetTextExtentPoint32 function takes justification
; into account when computing the width of a specified line
; before justification, and sometimes it does not.
Return DllCall("gdi32\SetTextJustification", "UPtr", hDC, "Int", extraSpace, "Int", countBreaks)
}
Gdi_BeginPath(hDC) {
; Opens a path bracket in the specified device context.
Return DllCall("gdi32\BeginPath", "UPtr", hDC)
}
Gdi_EndPath(hDC) {
; Closes a path bracket and selects the path defined by the bracket
; into the specified device context.
Return DllCall("gdi32\EndPath", "UPtr", hDC)
}
Gdi_AbortPath(hDC) {
; Closes and discards any paths in the specified device context.
Return DllCall("gdi32\AbortPath", "UPtr", hDC)
}
Gdi_FlattenPath(hDC) {
; Transforms any curves in the path that is selected into
; the current device context (DC), turning each curve into
; a sequence of lines.
Return DllCall("gdi32\FlattenPath", "UPtr", hDC)
}
Gdi_WidenPath(hDC) {
; Redefines the current path as the area that would be painted if
; the path were stroked using the pen currently selected into
; the given device context.
Return DllCall("gdi32\WidenPath", "UPtr", hDC)
}
Gdi_StrokePath(hDC) {
; Renders the specified path by using the current pen.
; If the function fails, the return value is zero.
Return DllCall("gdi32\StrokePath", "UPtr", hDC)
}
Gdi_FillPath(hDC) {
; The FillPath function closes any open figures in the
; current path and fills the path's interior by using
; the current brush and polygon-filling mode.
; If the function fails, the return value is zero.
Return DllCall("gdi32\StrokePath", "UPtr", hDC)
}
Gdi_StrokeAndFillPath(hDC) {
; The StrokeAndFillPath function closes any open figures in a path,
; strokes the outline of the path by using the current pen,
; and fills its interior by using the current brush.
; If the function fails, the return value is zero.
Return DllCall("gdi32\StrokeAndFillPath", "UPtr", hDC)
}
Gdi_PathToRegion(hDC) {
; If the function succeeds, the return value identifies a valid region.
; If the function fails, the return value is zero.
Return DllCall("gdi32\PathToRegion", "UPtr", hDC)
}
Gdi_SetMiterLimit(hDC, limit:=10) {
; The SetMiterLimit function sets the limit for the length of
; miter joins for the specified device context.
; Minimum value is 1.
Return DllCall("gdi32\SetMiterLimit", "UPtr", hDC, "uint", limit)
}
Gdi_CloseFigure(hDC) {
Return DllCall("gdi32\CloseFigure", "UPtr", hDC)
}
Gdi_SetBgrMode(hDC, mode) {
; mode = 1 ; transparent
; mode = 2 ; opaque
Return DllCall("gdi32\SetBkMode", "UPtr", hDC, "Int", mode)
}
Gdi_SetBgrColor(hDC, color) {
; The SetBkColor function sets the current background color to the specified color value, or to the nearest physical color if the device cannot represent the specified color value.
Return DllCall("gdi32\SetBkColor", "UPtr", hDC, "UInt", color)
}
Gdi_CreatePen(Color, Width:=1, Style:=0) {
; Style options:
; 0 = PS_SOLID - solid.
; 1 = PS_DASH - dashed. Valid only when the pen width is one or less in device units.
; 2 = PS_DOT - dotted. Valid only when the pen width is one or less in device units.
; 3 = PS_DASHDOT - alternating dashes and dots. Valid only when the pen width is one or less in device units.
; 4 = PS_DASHDOTDOT - alternating dashes and double dots. Valid only when the pen width is one or less in device units.
; 5 = PS_NULL - The pen is invisible.
; 6 = PS_INSIDEFRAME - The pen is solid. When this pen is used in any GDI drawing function that takes
; a bounding rectangle, the dimensions of the figure are shrunk so that it fits entirely in the
; bounding rectangle, taking into account the width of the pen. This applies only to geometric pens.
; 7 = PS_USERSTYLE
; 8 = PS_ALTERNATE
Return DllCall("gdi32\CreatePen", "Int", Style, "Int", Width, "UInt", Color, "UPtr")
}
Gdi_CreateSolidBrush(gColor) {
Return DllCall("gdi32\CreateSolidBrush", "UInt", gColor, "UPtr")
}
Gdi_CreatePatternBrush(hBitmap) {
; The CreatePatternBrush function creates a logical brush with the
; specified bitmap pattern. The bitmap can be a DIB section bitmap,
; which is created by the CreateDIBSection function, or it can
; be a device-dependent bitmap.
Return DllCall("gdi32\CreatePatternBrush", "UPtr", hBitmap)
}
Gdi_CreateHatchBrush(iHatch, color) {
; The CreateHatchBrush function creates a logical brush that has
; the specified hatch pattern and color.
; iHatch options:
; HS_HORIZONTAL = 0 ; Horizontal hatch
; HS_VERTICAL = 1 ; Vertical hatch
; HS_FDIAGONAL = 2 ; 45-degree downward left-to-right hatch
; HS_BDIAGONAL = 3 ; 45-degree upward left-to-right hatch
; HS_CROSS = 4 ; Horizontal and vertical crosshatch
; HS_DIAGCROSS = 5 ; 45-degree crosshatch
Return DllCall("gdi32\CreateHatchBrush", "Int", iHatch, "UInt", Color, "UPtr")
}
Gdi_ExtFloodFill(X, Y, Color, Type) {
; Type options:
; 0 = FLOODFILLBORDER -The fill area is bounded by the color specified by the crColor parameter. This style is identical to the filling performed by the FloodFill function.
; 1 = FLOODFILLSURFACE - The fill area is defined by the color that is specified by crColor. Filling continues outward in all directions as long as the color is encountered. This style is useful for filling areas with multicolored boundaries.
; If the function fails, the return value is zero.
Return DllCall("gdi32\ExtFloodFill", "Int", x, "Int", y, "UInt", Color, "Int", Type)
}
Gdi_SetBrushOrgEx(hDC, X, Y) {
Return DllCall("gdi32\SetBrushOrgEx", "UPtr", hDC, "Int", x, "Int", y, "UPtr", 0)
}
Gdi_SetDCBrushColor(hDC, Color) {
Return DllCall("gdi32\SetDCBrushColor", "UPtr", hDC, "UInt", Color, "UPtr")
}
Gdi_SetDCPenColor(hDC, Color) {
Return DllCall("gdi32\SetDCPenColor", "UPtr", hDC, "UInt", Color, "UPtr")
}
Gdi_GetROP2(hDC) {
; The function retrieves the foreground mix mode of the specified device
; context. The mix mode specifies how the pen or interior color and
; the color already on the screen are combined to yield a new color.
; Return value
; If the function succeeds, the return value specifies the foreground mix mode.
; otherwise, the return value is zero.
Return DllCall("gdi32\GetROP2", "UPtr", hDC)
}
Gdi_SetROP2(hDC, rop2) {
; The function sets the current foreground mix mode. GDI uses the foreground
; mix mode to combine pens and interiors of filled objects with the
; colors already on the screen. The foreground mix mode defines how colors
; from the brush or pen and the colors in the existing image are to be combined.
; The mix modes define how GDI combines source and destination colors when
; drawing with the current pen. The mix modes are binary raster operation
; codes, representing all possible Boolean functions of two variables, using
; the binary operations AND, OR, and XOR (exclusive OR), and the unary operation
; NOT. The mix mode is for raster devices only; it is not available
; for vector devices.
; Parameters
; hdc - A handle to the device context.
; rop2 - The mix mode.
; Return value
; If the function succeeds, the return value specifies the previous mix mode.
; otherwise, the return value is zero.
Return DllCall("gdi32\SetROP2", "UPtr", hDC, "Int", rop2)
}