forked from HaujetZhao/CapsWriter-Offline
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGetCaretPosEx.ahk
422 lines (386 loc) · 22.3 KB
/
GetCaretPosEx.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
/**
* @link https://github.com/abgox/InputTip/blob/main/src/v2/InputTip.ahk
*
* @link https://github.com/Tebayaki/AutoHotkeyScripts/blob/main/lib/GetCaretPosEx/GetCaretPosEx.ahk
*/
GetCaretPosEx(&left?, &top?, &right?, &bottom?) {
exe_name := ""
try {
exe_name := ProcessGetName(WinGetPID("A"))
DllCall("SetThreadDpiAwarenessContext", "ptr", -2, "ptr")
; ToolTip(exe_name)
}
IniFile := A_ScriptDir "\hint_while_recording.ini"
hintAtCursorPositionList := IniRead(IniFile, "List", "hintAtCursorPositionList")
hwnd := getHwnd()
disable_list := hintAtCursorPositionList . ""
Wpf_list := ":powershell_ise.exe:"
UIA_list := ":WINWORD.EXE:WindowsTerminal.exe:wt.exe:OneCommander.exe:YoudaoDict.exe:Mempad.exe:Taskmgr.exe:"
; MSAA 可能有符号残留
MSAA_list := ":EXCEL.EXE:DingTalk.exe:Notepad.exe:Notepad3.exe:Quicker.exe:skylark.exe:aegisub32.exe:aegisub64.exe:aegisub.exe:PandaOCR.exe:PandaOCR.Pro.exe:VStart6.exe:TIM.exe:PowerToys.PowerLauncher.exe:Foxmail.exe:"
; ACC_list := ":explorer.exe:ApplicationFrameHost.exe:"
Gui_UIA_list := ":POWERPNT.EXE:Notepad++.exe:firefox.exe:devenv.exe:"
; 需要调用有兼容性问题的 dll 来更新光标位置的应用列表
Hook_list_with_dll := ":WeChat.exe:"
if (InStr(disable_list, ":" exe_name ":")) {
return 0
}
else if (InStr(UIA_list, ":" exe_name ":")) {
return getCaretPosFromUIA()
}
else if (InStr(MSAA_list, ":" exe_name ":")) {
return getCaretPosFromMSAA()
}
else if (InStr(Gui_UIA_list, ":" exe_name ":")) {
if (getCaretPosFromGui(&hwnd := 0)) {
return 1
}
return getCaretPosFromUIA()
}
else if (InStr(Hook_list_with_dll, ":" exe_name ":")) {
return getCaretPosFromHook(1)
}
else if (InStr(Wpf_list, ":" exe_name ":")) {
return getCaretPosFromWpfCaret()
}
else {
if (getCaretPosFromHook(0)) {
return 1
}
functions := [getCaretPosFromMSAA, getCaretPosFromUIA]
for fn in functions {
if (fn()) {
return 1
}
}
}
return 0
getHwnd(hwnd := 0) {
x64 := A_PtrSize == 8
guiThreadInfo := Buffer(x64 ? 72 : 48)
NumPut("uint", guiThreadInfo.Size, guiThreadInfo)
if DllCall("GetGUIThreadInfo", "uint", 0, "ptr", guiThreadInfo) {
hwnd := NumGet(guiThreadInfo, x64 ? 16 : 12, "ptr")
}
return hwnd
}
getCaretPosFromGui(&hwnd) {
x64 := A_PtrSize == 8
guiThreadInfo := Buffer(x64 ? 72 : 48)
NumPut("uint", guiThreadInfo.Size, guiThreadInfo)
if DllCall("GetGUIThreadInfo", "uint", 0, "ptr", guiThreadInfo) {
if hwnd := NumGet(guiThreadInfo, x64 ? 48 : 28, "ptr") {
getRect(guiThreadInfo.Ptr + (x64 ? 56 : 32), &left, &top, &right, &bottom)
scaleRect(getWindowScale(hwnd), &left, &top, &right, &bottom)
clientToScreenRect(hwnd, &left, &top, &right, &bottom)
return true
}
hwnd := NumGet(guiThreadInfo, x64 ? 16 : 12, "ptr")
}
return false
}
getCaretPosFromMSAA() {
if !hOleacc := DllCall("LoadLibraryW", "str", "oleacc.dll", "ptr")
return false
hOleacc := { Ptr: hOleacc, __Delete: (_) => DllCall("FreeLibrary", "ptr", _) }
static IID_IAccessible := guidFromString("{618736e0-3c3d-11cf-810c-00aa00389b71}")
if !DllCall("oleacc\AccessibleObjectFromWindow", "ptr", hwnd, "uint", 0xfffffff8, "ptr", IID_IAccessible, "ptr*", accCaret := ComValue(13, 0), "int") {
if A_PtrSize == 8 {
varChild := Buffer(24, 0)
NumPut("ushort", 3, varChild)
hr := ComCall(22, accCaret, "int*", &x := 0, "int*", &y := 0, "int*", &w := 0, "int*", &h := 0, "ptr", varChild, "int")
}
else {
hr := ComCall(22, accCaret, "int*", &x := 0, "int*", &y := 0, "int*", &w := 0, "int*", &h := 0, "int64", 3, "int64", 0, "int")
}
if !hr {
pt := x | y << 32
DllCall("ScreenToClient", "ptr", hwnd, "int64*", &pt)
left := pt & 0xffffffff
top := pt >> 32
right := left + w
bottom := top + h
scaleRect(getWindowScale(hwnd), &left, &top, &right, &bottom)
clientToScreenRect(hwnd, &left, &top, &right, &bottom)
return true
}
}
return false
}
getCaretPosFromUIA() {
try {
uia := ComObject("{E22AD333-B25F-460C-83D0-0581107395C9}", "{30CBE57D-D9D0-452A-AB13-7AC5AC4825EE}")
ComCall(20, uia, "ptr*", cacheRequest := ComValue(13, 0)) ; uia->CreateCacheRequest(&cacheRequest);
if !cacheRequest.Ptr
return false
ComCall(4, cacheRequest, "ptr", 10014) ; cacheRequest->AddPattern(UIA_TextPatternId);
ComCall(4, cacheRequest, "ptr", 10024) ; cacheRequest->AddPattern(UIA_TextPattern2Id);
ComCall(12, uia, "ptr", cacheRequest, "ptr*", focusedEle := ComValue(13, 0)) ; uia->GetFocusedElementBuildCache(cacheRequest, &focusedEle);
if !focusedEle.Ptr
return false
static IID_IUIAutomationTextPattern2 := guidFromString("{506a921a-fcc9-409f-b23b-37eb74106872}")
range := ComValue(13, 0)
ComCall(15, focusedEle, "int", 10024, "ptr", IID_IUIAutomationTextPattern2, "ptr*", textPattern := ComValue(13, 0)) ; focusedEle->GetCachedPatternAs(UIA_TextPattern2Id, IID_PPV_ARGS(&textPattern));
if textPattern.Ptr {
ComCall(10, textPattern, "int*", &isActive := 0, "ptr*", range) ; textPattern->GetCaretRange(&isActive, &range);
if range.Ptr
goto getRangeInfo
}
; If no caret range, get selection range.
static IID_IUIAutomationTextPattern := guidFromString("{32eba289-3583-42c9-9c59-3b6d9a1e9b6a}")
ComCall(15, focusedEle, "int", 10014, "ptr", IID_IUIAutomationTextPattern, "ptr*", textPattern) ; focusedEle->GetCachedPatternAs(UIA_TextPatternId, IID_PPV_ARGS(&textPattern));
if textPattern.Ptr {
ComCall(5, textPattern, "ptr*", ranges := ComValue(13, 0)) ; textPattern->GetSelection(&ranges);
if ranges.Ptr {
; Retrieve the last selection range.
ComCall(3, ranges, "int*", &len := 0) ; ranges->get_Length(&len);
if len > 0 {
ComCall(4, ranges, "int", len - 1, "ptr*", range) ; ranges->GetElement(len - 1, &range);
if range.Ptr {
; Collapse the range.
ComCall(15, range, "int", 0, "ptr", range, "int", 1) ; range->MoveEndpointByRange(TextPatternRangeEndpoint_Start, range, TextPatternRangeEndpoint_End);
goto getRangeInfo
}
}
}
}
return false
getRangeInfo:
psa := 0
; This is a degenerate text range, we have to expand it.
ComCall(6, range, "int", 0) ; range->ExpandToEnclosingUnit(TextUnit_Character);
ComCall(10, range, "ptr*", &psa) ; range->GetBoundingRectangles(&psa);
if psa {
rects := ComValue(0x2005, psa, 1) ; SafeArray<double>
if rects.MaxIndex() >= 3 {
rects[2] := 0
goto end
}
}
; ExpandToEnclosingUnit by character may be invalid in some control if the range is at the end of the document.
; Assume that the range is at the end of the document and not in an empty line, try to expand it by line.
ComCall(6, range, "int", 3) ; range->ExpandToEnclosingUnit(TextUnit_Line)
ComCall(10, range, "ptr*", &psa) ; range->GetBoundingRectangles(&psa);
if psa {
rects := ComValue(0x2005, psa, 1) ; SafeArray<double>
if rects.MaxIndex() >= 3 {
; Here rects is {x, y, w, h}, we take the end endpoint as the caret position.
rects[0] := rects[0] + rects[2]
rects[2] := 0
goto end
}
}
return false
end:
left := Round(rects[0])
top := Round(rects[1])
right := left + Round(rects[2])
bottom := top + Round(rects[3])
return true
}
return false
}
getCaretPosFromWpfCaret() {
try {
uia := ComObject("{E22AD333-B25F-460C-83D0-0581107395C9}", "{30CBE57D-D9D0-452A-AB13-7AC5AC4825EE}")
ComCall(8, uia, "ptr*", focusedEle := ComValue(13, 0)) ; uia->GetFocusedElement(&focusedEle);
if !focusedEle.Ptr
return false
ComCall(20, uia, "ptr*", cacheRequest := ComValue(13, 0)) ; uia->CreateCacheRequest(&cacheRequest);
if !cacheRequest.Ptr
return false
ComCall(17, uia, "ptr*", rawViewCondition := ComValue(13, 0)) ; uia->get_RawViewCondition(&rawViewCondition);
if !rawViewCondition.Ptr
return false
ComCall(9, cacheRequest, "ptr", rawViewCondition) ; cacheRequest->put_TreeFilter(rawViewCondition);
ComCall(3, cacheRequest, "int", 30001) ; cacheRequest->AddProperty(UIA_BoundingRectanglePropertyId);
var := Buffer(24, 0)
ref := ComValue(0x400C, var.Ptr)
ref[] := ComValue(8, "WpfCaret")
ComCall(23, uia, "int", 30012, "ptr", var, "ptr*", condition := ComValue(13, 0)) ; uia->CreatePropertyCondition(UIA_ClassNamePropertyId, CComVariant(L"WpfCaret"), &classNameCondition);
if !condition.Ptr
return false
ComCall(7, focusedEle, "int", 4, "ptr", condition, "ptr", cacheRequest, "ptr*", wpfCaret := ComValue(13, 0)) ; focusedEle->FindFirstBuildCache(TreeScope_Descendants, condition, cacheRequest, &wpfCaret);
if !wpfCaret.Ptr
return false
ComCall(75, wpfCaret, "ptr", rect := Buffer(16)) ; wpfCaret->get_CachedBoundingRectangle(&rect);
getRect(rect, &left, &top, &right, &bottom)
return true
}
return false
}
getCaretPosFromHook(flag) {
static WM_GET_CARET_POS := DllCall("RegisterWindowMessageW", "str", "WM_GET_CARET_POS", "uint")
if !tid := DllCall("GetWindowThreadProcessId", "ptr", hwnd, "ptr*", &pid := 0, "uint")
return false
if (flag) {
; ! 有兼容性问题的 dll 调用,部分应用会因为它触发意外错误
; ! 如: 崩溃,自动复制/输入/删除/等
; Update caret position
try {
SendMessage(0x010f, 0, 0, hwnd) ; WM_IME_COMPOSITION
}
}
; PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ
if !hProcess := DllCall("OpenProcess", "uint", 1082, "int", false, "uint", pid, "ptr")
return false
hProcess := { Ptr: hProcess, __Delete: (_) => DllCall("CloseHandle", "ptr", _) }
isX64 := isX64Process(hProcess)
if isX64 && A_PtrSize == 4
return false
if !moduleBaseMap := getModulesBases(hProcess, ["kernel32.dll", "user32.dll", "combase.dll"])
return false
if isX64 {
static shellcode64 := compile(true)
shellcode := shellcode64
}
else {
static shellcode32 := compile(false)
shellcode := shellcode32
}
if !mem := DllCall("VirtualAllocEx", "ptr", hProcess, "ptr", 0, "ptr", shellcode.Size, "uint", 0x1000, "uint", 0x40, "ptr")
return false
mem := { Ptr: mem, __Delete: (_) => DllCall("VirtualFreeEx", "ptr", hProcess, "ptr", _, "uptr", 0, "uint", 0x8000) }
link(isX64, shellcode, mem.Ptr, moduleBaseMap["user32.dll"], moduleBaseMap["combase.dll"], hwnd, tid, WM_GET_CARET_POS, &pThreadProc, &pRect)
if !DllCall("WriteProcessMemory", "ptr", hProcess, "ptr", mem, "ptr", shellcode, "uptr", shellcode.Size, "ptr", 0)
return false
DllCall("FlushInstructionCache", "ptr", hProcess, "ptr", mem, "uptr", shellcode.Size)
if !hThread := DllCall("CreateRemoteThread", "ptr", hProcess, "ptr", 0, "uptr", 0, "ptr", pThreadProc, "ptr", mem, "uint", 0, "uint*", &remoteTid := 0, "ptr")
return false
hThread := { Ptr: hThread, __Delete: (_) => DllCall("CloseHandle", "ptr", _) }
if msgWaitForSingleObject(hThread)
return false
if !DllCall("GetExitCodeThread", "ptr", hThread, "uint*", exitCode := 0) || exitCode !== 0
return false
rect := Buffer(16)
if !DllCall("ReadProcessMemory", "ptr", hProcess, "ptr", pRect, "ptr", rect, "uptr", rect.Size, "uptr*", &bytesRead := 0) || bytesRead !== rect.Size
return false
getRect(rect, &left, &top, &right, &bottom)
scaleRect(getWindowScale(hwnd), &left, &top, &right, &bottom)
return true
static isX64Process(hProcess) {
DllCall("IsWow64Process", "ptr", hProcess, "int*", &isWow64 := 0)
if isWow64
return false
if A_PtrSize == 8
return true
DllCall("IsWow64Process", "ptr", DllCall("GetCurrentProcess", "ptr"), "int*", &isWow64)
return isWow64
}
static getModulesBases(hProcess, modules) {
hModules := Buffer(A_PtrSize * 350)
if !DllCall("K32EnumProcessModulesEx", "ptr", hProcess, "ptr", hModules, "uint", hModules.Size, "uint*", &needed := 0, "uint", 3)
return
moduleBaseMap := Map()
moduleBaseMap.CaseSense := false
for v in modules
moduleBaseMap[v] := 0
cnt := modules.Length
loop Min(350, needed) {
hModule := NumGet(hModules, A_PtrSize * (A_Index - 1), "ptr")
VarSetStrCapacity(&name, 12)
if DllCall("K32GetModuleBaseNameW", "ptr", hProcess, "ptr", hModule, "str", &name, "uint", 13) {
if moduleBaseMap.Has(name) {
moduleInfo := Buffer(24)
if !DllCall("K32GetModuleInformation", "ptr", hProcess, "ptr", hModule, "ptr", moduleInfo, "uint", moduleInfo.Size)
return
if !base := NumGet(moduleInfo, "ptr")
return
moduleBaseMap[name] := base
cnt--
}
}
} until cnt == 0
if cnt == 0
return moduleBaseMap
}
static compile(x64) {
if x64
shellcodeBase64 := "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABrnppSh2UjT6uenH1oPjxQAeiAqiEg0hGT4ABgsGe4blNldFdpbmRvd3NIb29rRXhXAAAAVW5ob29rV2luZG93c0hvb2tFeABDYWxsTmV4dEhvb2tFeAAAAAAAAFNlbmRNZXNzYWdlVGltZW91dFcAQ29DcmVhdGVJbnN0YW5jZQAAAAAAAAAASIlcJAhIiXQkEFdIg+wgSYvYSIvyi/mFyXgjSIXbdB6LBQb///9BOUAQdRJIjQ3d/v//6JgBAACJBfL+//9Iiw3L/v//SI0VdP///+jnAgAASIXAdRBIi1wkMEiLdCQ4SIPEIF/DTIvLTIvGi9czyUiLXCQwSIt0JDhIg8QgX0j/4MzMzMzMzDPAw8zMzMzMQFNWSIPsSIvySIvZSIXJdQy4VwAHgEiDxEheW8NIi0kISI1UJGBIiVQkKEG4/////0iNVCQwSIl8JEAz/0iJVCQgiXwkYIvWSIsBRI1PAf9QKIXAeHJIOXwkMHRrOXwkYHRlSItLCEiNVCR4SIl8JHhIiwH/UEiL+IXAeDJIi0wkeEiFyXQoSIsBSI1UJHBMi0QkMEyNSxBIiVQkIIvW/1AgSItMJHiL+E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AUGoXagCNRkDHRCQYAAAAAFDHRCQgAAAAAMdEJCQBAAAA/9GFwA+IywAAAItMJASFyQ+EvwAAAIsBjVQkDFdSUf9QDIXAeHCLTCQIjVQkHFJRiwH/UByFwHhdi0wkHIXJdFmLAY1UJAxSUf9QGIXAeEaLfCQMhf90UI1OMIl+HLjcAQAAiU4YA8aNVhiJAYvGBRwBAACNTCQUUYlGNIlGOLgkAQAAagMDxlL/dCQciUY8iwdX/1AMi0wkHItUJAyF0nQKiwJS/1AIi0wkHF+FyXQGiwFR/1AIi0wkBIXJdAaLAVH/UAiLRCQQ99heG8CD4ASDxBDDuAQAAABeg8QQw7gAAAAAw8zMg+wIU1VWV4t8JByF/w+EgQAAAItcJCCF23R5i0c8g3w4fAB0b4tEOHiFwHRni0w4JDP2i1Q4IAPPi2w4GAPXiUwkEItMOBwDz4lUJByJTCQUTYorixSyA9c6KnUTis2LwyvThMl0FIpIAUA6DAJ080Y79Xcfi1QkHOvZi0QkEItMJBQPtwRwiwSBA8dfXl1bg8QIw19eXTPAW4PECMPMzFNVVleLfCQUizeNR2BQVuhM////iUQkHI2HnAAAAFBW6Dv///+L2I1HdFBW6C////+LTCQsg8QYi+iFyXRshdt0aIXtdGSLxwWUAwAAiXgBuMQAAAD/dwwDx2oAUGoE/9GJRCQUhcB1DF9eXbgCAAAAW8IEAGoAaMgAAABqAGoAagD/dxD/dwj/0/90JBSL8P/VhfZ1Cl+NRgNeXVvCBACLRxRfXl1bwgQAX15duAEAAABbwgQA"
len := StrLen(shellcodeBase64)
shellcode := Buffer(len * 0.75)
if !DllCall("crypt32\CryptStringToBinary", "str", shellcodeBase64, "uint", len, "uint", 1, "ptr", shellcode, "uint*", shellcode.Size, "ptr", 0, "ptr", 0)
return
return shellcode
}
static link(x64, shellcode, shellcodeBase, user32Base, combaseBase, hwnd, tid, msg, &pThreadProc, &pRect) {
if x64 {
NumPut("uint64", user32Base, shellcode, 0)
NumPut("uint64", combaseBase, shellcode, 8)
NumPut("uint64", hwnd, shellcode, 16)
NumPut("uint", tid, shellcode, 24)
NumPut("uint", msg, shellcode, 28)
pThreadProc := shellcodeBase + 0x4e0
pRect := shellcodeBase + 56
}
else {
NumPut("uint", user32Base, shellcode, 0)
NumPut("uint", combaseBase, shellcode, 4)
NumPut("uint", hwnd, shellcode, 8)
NumPut("uint", tid, shellcode, 12)
NumPut("uint", msg, shellcode, 16)
pThreadProc := shellcodeBase + 0x43c
pRect := shellcodeBase + 32
}
}
static msgWaitForSingleObject(handle) {
while 1 == res := DllCall("MsgWaitForMultipleObjects", "uint", 1, "ptr*", handle, "int", false, "uint", -1, "uint", 7423) { ; QS_ALLINPUT := 7423
msg := Buffer(A_PtrSize == 8 ? 48 : 28)
while DllCall("PeekMessageW", "ptr", msg, "ptr", 0, "uint", 0, "uint", 0, "uint", 1) { ; PM_REMOVE := 1
DllCall("TranslateMessage", "ptr", msg)
DllCall("DispatchMessageW", "ptr", msg)
}
}
return res
}
}
getCaretPosFromACC() {
static _ := DllCall("LoadLibrary", "Str", "oleacc", "Ptr")
try {
idObject := 0xFFFFFFF8 ; OBJID_CARET
if DllCall("oleacc\AccessibleObjectFromWindow", "ptr", WinExist("A"), "uint", idObject &= 0xFFFFFFFF
, "ptr", -16 + NumPut("int64", idObject == 0xFFFFFFF0 ? 0x46000000000000C0 : 0x719B3800AA000C81, NumPut("int64", idObject == 0xFFFFFFF0 ? 0x0000000000020400 : 0x11CF3C3D618736E0, IID := Buffer(16)))
, "ptr*", oAcc := ComValue(9, 0)) = 0 {
x := Buffer(4), y := Buffer(4), w := Buffer(4), h := Buffer(4)
oAcc.accLocation(ComValue(0x4003, x.ptr, 1), ComValue(0x4003, y.ptr, 1), ComValue(0x4003, w.ptr, 1), ComValue(0x4003, h.ptr, 1), 0)
left := NumGet(x, 0, "int"), top := NumGet(y, 0, "int"), right := NumGet(w, 0, "int"), bottom := NumGet(h, 0, "int")
if (left | top) != 0
return 0
return 1
}
}
}
static guidFromString(str) {
DllCall("ole32\CLSIDFromString", "str", str, "ptr", buf := Buffer(16), "hresult")
return buf
}
static getRect(buf, &left, &top, &right, &bottom) {
left := NumGet(buf, 0, "int")
top := NumGet(buf, 4, "int")
right := NumGet(buf, 8, "int")
bottom := NumGet(buf, 12, "int")
}
static getWindowScale(hwnd) {
if winDpi := DllCall("GetDpiForWindow", "ptr", hwnd, "uint")
return A_ScreenDPI / winDpi
return 1
}
static scaleRect(scale, &left, &top, &right, &bottom) {
left := Round(left * scale)
top := Round(top * scale)
right := Round(right * scale)
bottom := Round(bottom * scale)
}
static clientToScreenRect(hwnd, &left, &top, &right, &bottom) {
w := right - left
h := bottom - top
pt := left | top << 32
DllCall("ClientToScreen", "ptr", hwnd, "int64*", &pt)
left := pt & 0xffffffff
top := pt >> 32
right := left + w
bottom := top + h
}
}