forked from Eruyome/PoE-Leveling-Overlay
-
Notifications
You must be signed in to change notification settings - Fork 6
/
LevelingOverlay.ahk
744 lines (619 loc) · 21.2 KB
/
LevelingOverlay.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
#SingleInstance, force
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#Include, %A_ScriptDir%\lib\JSON.ahk
;#Include, %A_ScriptDir%\lib\Gdip2.ahk
Menu, Tray, Icon, %A_ScriptDir%\poe.ico
Menu, Tray, Tip, Path of Exile - Leveling Overlays
GroupAdd, PoEWindowGrp, Path of Exile ahk_class POEWindowClass ahk_exe PathOfExile.exe
GroupAdd, PoEWindowGrp, Path of Exile ahk_class POEWindowClass ahk_exe PathOfExileSteam.exe
GroupAdd, PoEWindowGrp, Path of Exile ahk_class POEWindowClass ahk_exe PathOfExile_x64.exe
GroupAdd, PoEWindowGrp, Path of Exile ahk_class POEWindowClass ahk_exe PathOfExile_x64Steam.exe
;
; ========= Settings =========
;
global data := {}
Try {
FileRead, JSONFile, %A_ScriptDir%\data.json
data := JSON.Load(JSONFile)
If (not data.acts.Length()) {
MsgBox, 16, , Error reading zone data! `n`nExiting script.
ExitApp
}
} Catch e {
MsgBox, 16, , % e "`n`nExiting script."
ExitApp
}
opacity := 140
gui_1_toggle := 0
gui_2_toggle := 0
linenumber := 1
global maxImages := 5
global windowTrans := 180
global xPosLayoutParent := Round(A_ScreenWidth / 2) - Round(((maxImages * 110) + (maxImages * A_Index)) / 2)
global xPosSkills := xPosLayoutParent + ((maxImages * 110) + (maxImages * A_Index))
global skillsWidth := 330 ; max width
global xPosXPRange := xPosSkills + skillsWidth + 2
global PoEWindowHwnd := ""
WinGet, PoEWindowHwnd, ID, ahk_group PoEWindowGrp
global xp_active := false
global skills_active := false
global layout_active := false
global image_active := false
global LastCounter := 0
global Counter := 0
Gosub, DrawGUI1
Gosub, DrawGUI2_1
Gosub, DrawGUI3_1
SetTimer, ShowGuiTimer, 250
Return
;
; ========= MAIN / GUI =========
;
;
; ========= HOTKEY =========
;
;========== Quest Rewards =======
#IfWinActive, ahk_group PoEWindowGrp
+F3:: ; Display/Hide gem leveler window hotkey
if (gui_2_toggle = 0)
{
Gosub, DrawGUI2_1
}
else
{
Gui, 2:Destroy
gui_2_toggle := 0
}
Gosub, ActivatePOE
return
!F3::
Gui, 2:Destroy
Gosub, DrawGUI2_1
return
Gosub, ActivatePOE
return
;========== XP Range =======
#IfWinActive, ahk_group PoEWindowGrp
+F4:: ; Display/Hide xp range window hotkey
if (gui_1_toggle = 0)
{
Gosub, DrawGUI1
}
else
{
Gui, 1:Destroy
gui_1_toggle := 0
}
Gosub, ActivatePOE
return
;========== Zone Layouts =======
#IfWinActive, ahk_group PoEWindowGrp
+F1:: ; Display/Hide zone layout window hotkey
if (gui_3_toggle = 0)
{
Gosub, DrawGUI3_1
}
else
{
Gui, 3:Destroy
Gui, Controls:Destroy
Loop, % maxImages {
Gui, Image%A_Index%:Destroy
}
gui_3_toggle := 0
}
Gosub, ActivatePOE
return
; Dropdown tab switching hotkeys listed below
#IfWinActive, ahk_group PoEWindowGrp
^F1::
GoSub, cycleActDown
return
#IfWinActive, ahk_group PoEWindowGrp
^F2::
GoSub, cycleActUp
return
#IfWinActive, ahk_group PoEWindowGrp
!F1::
GoSub, cycleZoneDown
return
#IfWinActive, ahk_group PoEWindowGrp
!F2::
GoSub, cycleZoneUp
return
#IfWinActive, ahk_group PoEWindowGrp
$WheelUp::
; $ prevents triggering this when using Send {WheelUp}
MouseGetPos, mouseX, mouseY
mouseOverControlOrImage := CheckIfMouseInRegion("up")
If (mouseOverControlOrImage) {
; trigger zone/act changes
}
Else {
Send {WheelUp}
}
return
#IfWinActive, ahk_group PoEWindowGrp
$WheelDown::
; $ prevents triggering this when using Send {WheelDown}
mouseOverControlOrImage := CheckIfMouseInRegion("down")
If (mouseOverControlOrImage) {
; trigger zone/act changes
}
Else {
Send {WheelDown}
}
return
;========== Subs and Functions =======
CheckIfMouseInRegion(direction) {
MouseGetPos, mouseX, mouseY, window, winControl
overImage := false
Loop, % maxImages {
id := Image%A_Index%Window
If (id == window) {
overImage := true
}
}
overDropdownAct := false
overDropdownZone := false
If (window == ControlsWindow) {
If (winControl = "ComboBox1") {
overDropdownAct := true
}
Else If (winControl = "ComboBox2") {
overDropdownZone := true
}
}
If (overDropdownZone or overImage) {
; change zones
If (direction = "up") {
GoSub, cycleZoneUp
} Else If (direction = "down") {
GoSub, cycleZoneDown
}
Return true
} Else If (overDropDownAct) {
; change act
If (direction = "up") {
GoSub, cycleActUp
} Else If (direction = "down") {
GoSub, cycleActDown
}
Return true
}
Return false
}
ActivatePOE:
WinActivate, ahk_id %PoEWindowHwnd%
return
DrawGUI1:
Gui, 1:+E0x20 -Caption +LastFound +ToolWindow +AlwaysOnTop +hwndXpWindow
Gui, 1:Font, s9, Consolas
WinSet, Transparent, %opacity%
xp_ranges =
(LTrim
XP Range
1-15 | 3
16-31 | 4
32-47 | 5
48-63 | 6
64-79 | 7
80+ | 8
)
Gui, 1:Add, Text, x5 y+5, % xp_ranges
CalculateCellTextDimensions(xp_ranges, 9, "Consolas", xp_height, xp_width)
_width := xp_width
_height:= xp_height + 10
Gui, 1:Show, x%xPosXPRange% y5 w%_width% h%_height%
gui_1_toggle := 1
return
DrawGUI2_1:
Gui, 2:+E0x20 -Caption +LastFound +ToolWindow +AlwaysOnTop +hwndSkillGemsWindow
Gui, 2:font, s9, Arial
WinSet, Transparent, %opacity%
skillText := ""
Loop
{
FileReadLine, ReadLine, gemlist.txt, %linenumber%
{
if ErrorLevel = 0
{
linenumber += 1
} else
{
linenumber = 1
break
}
if ReadLine =
{
break
}
skillText .= ReadLine "`n"
}
if ReadLine =
{
break
}
}
Gui, 2:Add, Text, x5 y+5, % skillText
CalculateCellTextDimensions(skillText, 9, "Arial", skill_height, skill_width)
skill_width := (skill_width > skillsWidth) ? skillsWidth : skill_width
_height:= skill_height + 10
Gui, 2:Show, x%xPosSkills% y5 w%skill_width% h%_height%, Gui 2
gui_2_toggle := 1
return
DrawGUI3_1:
Gui, Parent:New, +AlwaysOnTop +ToolWindow +hwndParentWindow
Gui, Parent:Color, brown
Gui, Parent:Show, w100 h80 x%xPosLayoutParent% y5
WinSet, TransColor, brown, A
; make tooltip clickthrough and remove borders
; doesn't work
WinSet, ExStyle, +0x20, ahk_id %ParentWindow% ; 0x20 = WS_EX_CLICKTHROUGH
WinSet, Style, -0xC00000, ahk_id %ParentWindow%
Loop, % maxImages {
filepath := "" A_ScriptDir "\Overlays\" data.DdlA "\" data.DdlZ "_Seed_" A_Index ".jpg" ""
xPos := xPosLayoutParent + maxImages * 110 - (A_Index) * 110 - (5 * A_Index)
Gui, Image%A_Index%:New, -resize -SysMenu -Caption +AlwaysOnTop +hwndImage%A_Index%Window
id := Image%A_Index%Window
Gui, Image%A_Index%:Add, Picture, VPic%A_Index% x0 y0 w110 h60, %filepath%
Gui, Image%A_Index%:Show, w110 h60 x%xPos% y5, Image%A_Index%
Gui, Image%A_Index%:+OwnerParent
If (not FileExist(filepath)) {
WinSet, Transparent, 0, ahk_id %id%
} Else {
WinSet, Transparent, %windowTrans%, ahk_id %id%
}
}
Gui, Controls:+E0x20 -Caption +LastFound +ToolWindow +AlwaysOnTop +hwndControls
Gui, Controls:Color, gray
Gui, Controls:Font, s9, Arial
Gui, Controls:Add, DropDownList, VDdlA GchangeAct x0 y0 w90 h200 , % GetDelimitedActListString(data.zones, "Act I")
Gui, Controls:Add, DropDownList, VDdlZ GchangeZone x+5 y0 w120 h250 , % GetDelimitedZoneListString(data.zones, "Act I")
Gui, Controls:+OwnerParent
xPos := xPosLayoutParent + 330
Gui, Controls:Show, h21 w215 x%xPos% y68, Controls
gui_3_toggle := 1
return
GetDelimitedActListString(data, act) {
dList := ""
For key, zone in data {
dList .= "|" . zone.act
If (zone.act = act) {
dList .= "|"
}
}
Return RegExReplace(dList, "^\|")
}
GetDelimitedZoneListString(data, act) {
dList := ""
For key, zone in data {
If (zone.act = act) {
For k, val in zone.list {
dList .= "|" . val
If (val = zone.default) {
dList .= "|"
}
}
}
}
dList := RegExReplace(dList, "^\|")
_temp := RegExReplace(dList, "\|", "", count)
dList := count = 1 ? dList . "|" : dList
Return dList
}
GetDefaultZone(zones, act) {
For key, zone in zones {
If (zone.act = act) {
Return zone.default
}
}
}
GetDifferentZone(direction, zones, act, current) {
newZone := ""
indexShift := direction = "next" ? 1 : -1
first := ""
last := ""
For key, zone in zones {
If (zone.act = act) {
Loop, % zone["list"].Length()
{
If (A_Index = 1) {
first := zone.list[A_Index]
}
If (A_Index = zone.list.MaxIndex()) {
last := zone.list[A_Index]
}
If (zone.list[A_Index] = current) {
newZone := zone.list[A_Index + indexShift]
}
}
break
}
}
If (not StrLen(newZone)) {
newZone := direction = "next" ? first : last
}
Return newZone
}
GetDifferentAct(direction, acts, current) {
newAct := ""
indexShift := direction = "next" ? 1 : -1
first := ""
last := ""
Loop, % acts.Length()
{
If (A_Index = 1) {
first := acts[A_Index]
}
If (A_Index = acts.MaxIndex()) {
last := acts[A_Index]
}
If (acts[A_Index] = current) {
newAct := acts[A_Index + indexShift]
}
}
If (not StrLen(newAct)) {
newAct := direction = "next" ? first : last
}
Return newAct
}
changeAct:
Gui, Controls:Submit, NoHide
Loop, % maxImages {
Gui, Image%A_Index%:Submit, NoHide
}
GuiControl,,DdlZ, % "|" test := GetDelimitedZoneListString(data.zones, DdlA)
DdlZ := GetDefaultZone(data.zones, DdlA)
GoSub, UpdateImages
GoSub, ActivatePOE
return
changeZone:
Gui, Controls:Submit, NoHide
Loop, % maxImages {
Gui, Image%A_Index%:Submit, NoHide
}
GoSub, UpdateImages
GoSub, ActivatePOE
return
cycleZoneUp:
Gui, Controls:Submit, NoHide
_zone := GetDifferentZone("next", data.zones, DdlA, DdlZ)
GuiControl, Controls:Choose, DdlZ, % "|" _zone
GoSub, UpdateImages
GoSub, ActivatePOE
return
cycleZoneDown:
Gui, Controls:Submit, NoHide
_zone := GetDifferentZone("previous", data.zones, DdlA, DdlZ)
GuiControl, Controls:Choose, DdlZ, % "|" _zone
GoSub, UpdateImages
GoSub, ActivatePOE
return
cycleActUp:
Gui, Controls:Submit, NoHide
_zone := GetDifferentAct("next", data.acts, DdlA)
Loop, % maxImages {
Gui, Image%A_Index%:Submit, NoHide
}
GuiControl, Controls:Choose, DdlA, % "|" _zone
GoSub, UpdateImages
GoSub, ActivatePOE
return
cycleActDown:
Gui, Controls:Submit, NoHide
_zone := GetDifferentAct("previous", data.acts, DdlA)
Loop, % maxImages {
Gui, Image%A_Index%:Submit, NoHide
}
GuiControl, Controls:Choose, DdlA, % "|" _zone
GoSub, UpdateImages
GoSub, ActivatePOE
return
UpdateImages:
Loop, % maxImages {
filepath := "" A_ScriptDir "\Overlays\" DdlA "\" DdlZ "_Seed_" A_Index ".jpg" ""
id := Image%A_Index%Window
If (FileExist(filepath)) {
GuiControl,Image%A_Index%:,Pic%A_Index%, *w110 *h60 %filepath%
WinSet, Transparent, %windowTrans%, ahk_id %id%
}
Else {
WinSet, Transparent, 0, ahk_id %id%
}
Gui, Image%A_Index%:Show
Gui, Image%A_Index%:+OwnerParent
}
return
ShowGuiTimer:
; check all if one of the windows is active (focused)
poe_active := WinActive("ahk_id" PoEWindowHwnd)
xp_active := WinActive("ahk_id" XpWindow)
skills_active := WinActive("ahk_id" SkillGemsWindow)
layout_active := WinActive("ahk_id" ParentWindow)
controls_active := WinActive("ahk_id" Controls)
image_active := false
Loop, % maxImages {
iid := Image%A_Index%Window
If (WinActive("ahk_id" iid)) {
image_active := true
}
}
If (poe_active or (xp_active or skills_active or layout_active or image_active or controls_active)) {
; show all gui windows
GoSub, ShowAllWindows
} Else {
GoSub, HideAllWindows
}
return
ShowAllWindows:
If (gui_3_toggle) {
If (not layout_active) {
Gui, Parent:Show, NoActivate
}
If (not controls_active) {
Gui, Controls:Show, NoActivate
Gui, Controls:+OwnerParent
}
If (not image_active) {
Loop, % maxImages {
Gui, Image%A_Index%:Show, NoActivate
Gui, Image%A_Index%:+OwnerParent
}
}
}
If (not skills_active and gui_1_toggle) {
Gui, 1:Show, NoActivate
}
If (not xp_active and gui_2_toggle) {
Gui, 2:Show, NoActivate
}
return
HideAllWindows:
Gui, Parent:Cancel
Gui, Controls:Cancel
Loop, % maxImages {
Gui, Image%A_Index%:Cancel
}
Gui, 1:Cancel
Gui, 2:Cancel
return
; ==================================================================================================================================
; Function: CalculateCellTextDimensions
; Calculates width and height of a string. Multiline support.
; Parameters:
; value - text to measure.
; fontSize - texts font size.
; font - texts font family.
; height - ByRef variable, calculated height.
; width - ByRef variable, calculated width.
; newValue - ByRef variable, new value (for multiline text).
; Returns:
; Height, width and newValue as ByRef variables.
; ==================================================================================================================================
CalculateCellTextDimensions(value, fontSize, font, ByRef height = 0, ByRef width = 0, ByRef newValue = "") {
value := RegExReplace(value, "\r|\n$")
height := 0
width := 0
Loop, Parse, value, `n, `r
{
string := A_LoopField
StringReplace, string, string, `r,, All
StringReplace, string, string, `n,, All
emptyLine := false
If (not StrLen(string)) {
string := "A" ; don't prevent emtpy lines, just having a linebreak will break the text measuring
emptyLine := true
}
string := " " Trim(string) " " ; add spaces as table padding
If (emptyLine) {
newValue .= "`n"
} Else {
newValue .= string "`n"
}
If (StrLen(string)) {
size := Font_DrawText(string, "", "s" fontSize ", " font, "CALCRECT SINGLELINE NOCLIP")
width := width > size.W ? width : size.W
height += size.H
}
}
Return
}
; ==================================================================================================================================
; Original script by majkinetor.
; Fixed by Eruyome.
;
; https://github.com/majkinetor/mm-autohotkey/blob/master/Font/Font.ahk
;
; Function: CreateFont
; Creates the font and optinally, sets it for the control.
; Parameters:
; hCtrl - Handle of the control. If omitted, function will create font and return its handle.
; Font - AHK font defintion ("s10 italic, Courier New"). If you already have created font, pass its handle here.
; bRedraw - If this parameter is TRUE, the control redraws itself. By default 1.
; Returns:
; Font handle.
; ==================================================================================================================================
CreateFont(HCtrl="", Font="", BRedraw=1) {
static WM_SETFONT := 0x30
;if Font is not integer
if (not RegExMatch(Trim(Font), "^\d+$"))
{
StringSplit, Font, Font, `,,%A_Space%%A_Tab%
fontStyle := Font1, fontFace := Font2
;parse font
italic := InStr(Font1, "italic") ? 1 : 0
underline := InStr(Font1, "underline") ? 1 : 0
strikeout := InStr(Font1, "strikeout") ? 1 : 0
weight := InStr(Font1, "bold") ? 700 : 400
;height
RegExMatch(Font1, "(?<=[S|s])(\d{1,2})(?=[ ,]*)", height)
ifEqual, height,, SetEnv, height, 10
RegRead, LogPixels, HKEY_LOCAL_MACHINE, SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontDPI, LogPixels
height := -DllCall("MulDiv", "int", Height, "int", LogPixels, "int", 72)
IfEqual, Font2,,SetEnv Font2, MS Sans Serif
;create font
hFont := DllCall("CreateFont", "int", height, "int", 0, "int", 0, "int", 0
,"int", weight, "Uint", italic, "Uint", underline
,"uint", strikeOut, "Uint", nCharSet, "Uint", 0, "Uint", 0, "Uint", 0, "Uint", 0, "str", Font2, "Uint")
} else hFont := Font
ifNotEqual, HCtrl,,SendMessage, WM_SETFONT, hFont, BRedraw,,ahk_id %HCtrl%
return hFont
}
; ==================================================================================================================================
;
; Original script by majkinetor.
; Fixed by Eruyome.
;
; https://github.com/majkinetor/mm-autohotkey/blob/master/Font/Font.ahk
;
; Function: DrawText
; Draws text using specified font on device context or calculates width and height of the text.
; Parameters:
; Text - Text to be drawn or measured.
; DC - Device context to use. If omitted, function will use Desktop's DC.
; Font - If string, font description in AHK syntax. If number, font handle. If omitted, uses the system font to calculate text metrics.
; Flags - Drawing/Calculating flags. Space separated combination of flag names. For the description of the flags see <http://msdn.microsoft.com/en-us/library/ms901121.aspx>.
; Rect - Bounding rectangle. Space separated list of left,top,right,bottom coordinates.
; Width could also be used with CALCRECT WORDBREAK style to calculate word-wrapped height of the text given its width.
;
; Flags:
; CALCRECT, BOTTOM, CALCRECT, CENTER, VCENTER, TABSTOP, SINGLELINE, RIGHT, NOPREFIX, NOCLIP, INTERNAL, EXPANDTABS, AHKSIZE.
; Returns:
; Decimal number. Width "." Height of text. If AHKSIZE flag is set, the size will be returned as w%w% h%h%
; ==================================================================================================================================
Font_DrawText(Text, DC="", Font="", Flags="", Rect="") {
static DT_AHKSIZE=0, DT_CALCRECT=0x400, DT_WORDBREAK=0x10, DT_BOTTOM=0x8, DT_CENTER=0x1, DT_VCENTER=0x4, DT_TABSTOP=0x80, DT_SINGLELINE=0x20, DT_RIGHT=0x2, DT_NOPREFIX=0x800, DT_NOCLIP=0x100, DT_INTERNAL=0x1000, DT_EXPANDTABS=0x40
hFlag := (Rect = "") ? DT_NOCLIP : 0
StringSplit, Rect, Rect, %A_Space%
loop, parse, Flags, %A_Space%
ifEqual, A_LoopField,,continue
else hFlag |= DT_%A_LoopField%
if (RegExMatch(Trim(Font), "^\d+$")) {
hFont := Font, bUserHandle := 1
}
else if (Font != "") {
hFont := CreateFont( "", Font)
}
else {
hFlag |= DT_INTERNAL
}
IfEqual, hDC,,SetEnv, hDC, % DllCall("GetDC", "Uint", 0, "Uint")
ifNotEqual, hFont,, SetEnv, hOldFont, % DllCall("SelectObject", "Uint", hDC, "Uint", hFont)
VarSetCapacity(RECT, 16)
if (Rect0 != 0)
loop, 4
NumPut(Rect%A_Index%, RECT, (A_Index-1)*4)
h := DllCall("DrawTextA", "Uint", hDC, "Str", Text, "int", StrLen(Text), "uint", &RECT, "uint", hFlag)
;clean
ifNotEqual, hOldFont,,DllCall("SelectObject", "Uint", hDC, "Uint", hOldFont)
ifNotEqual, bUserHandle, 1, DllCall("DeleteObject", "Uint", hFont)
ifNotEqual, DC,,DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)
w := NumGet(RECT, 8, "Int")
return InStr(Flags, "AHKSIZE") ? "w" w " h" h : { "W" : w, "H": h }
}
GuiClose:
ExitApp