F1:: CoordMode, ToolTip, Screen if (hwnd := GetCaretPosEx(x, y, w, h)) { WinGetClass, classname, ahk_id %hwnd% ToolTip, classname, x, y + h } else { ToolTip } return GetCaretPosEx(byref x = 0, byref y = 0, byref w = 0, byref h = 0) { VarSetCapacity(guiThreadInfo, size := (A_PtrSize == 8 ? 72 : 48)), NumPut(size, guiThreadInfo, "uint") if (DllCall("GetGUIThreadInfo", "uint", DllCall("GetWindowThreadProcessId", "ptr", WinExist("A"), "ptr", 0, "uint"), "ptr", &guiThreadInfo)) hwndFocus := NumGet(guiThreadInfo, A_PtrSize == 8 ? 16 : 12, "ptr") if (!hwndFocus) hwndFocus := WinExist() ; Plan A applies to windows with MSAA OBJID_CARET support, such as chrome static hOleacc := DllCall("LoadLibrary", "str", "Oleacc.dll", "ptr") VarSetCapacity(iid, 16), NumPut(0x11CF3C3D618736E0, iid, "int64"), NumPut(0x719B3800AA000C81, iid, 8, "int64") if (!DllCall("Oleacc\AccessibleObjectFromWindow", "ptr", hwndFocus, "uint", 0xFFFFFFF8, "ptr", &iid, "ptr*", caretAcc) && caretAcc) { VarSetCapacity(id, 24, 0), NumPut(3, id, "ushort") if (!DllCall(NumGet(NumGet(caretAcc + 0), 22 * A_PtrSize), "ptr", caretAcc, "int*", x, "int*", y, "int*", w, "int*", h, "ptr", &id)) { ObjRelease(caretAcc) return hwndFocus } ObjRelease(caretAcc) } ; Plan B applies to windows that implement IUIAutomationTextPattern2, such as UWP window static iUIAutomation := ComObjCreate("{E22AD333-B25F-460C-83D0-0581107395C9}", "{30CBE57D-D9D0-452A-AB13-7AC5AC4825EE}") if (!DllCall(NumGet(NumGet(iUIAutomation + 0), 8 * A_PtrSize), "ptr", iUIAutomation, "ptr*", eleFocus) && eleFocus) { if (!DllCall(NumGet(NumGet(eleFocus + 0), 16 * A_PtrSize), "ptr", eleFocus, "int", 10024, "ptr*", textPattern2, "int") && textPattern2) { if (!DllCall(NumGet(NumGet(textPattern2 + 0), 10 * A_PtrSize), "ptr", textPattern2, "int*", isActive, "ptr*", textRange) && textRange && isActive) { if (!DllCall(NumGet(NumGet(textRange + 0), 10 * A_PtrSize), "ptr", textRange, "ptr*", rects) && rects) { rects := ComObject(0x2005, rects, 1) if (3 <= rects.MaxIndex()) { x := rects[0], y := rects[1], w := rects[2], h := rects[3] ObjRelease(textRange), ObjRelease(textPattern2), ObjRelease(eleFocus) return hwndFocus } } ObjRelease(textRange) } ObjRelease(textPattern2) } ; Plan C applies to windows that implement IUIAutomationTextPattern, such as Windows Terminal if (!DllCall(NumGet(NumGet(eleFocus + 0), 16 * A_PtrSize), "ptr", eleFocus, "int", 10014, "ptr*", textPattern) && textPattern) { if (!DllCall(NumGet(NumGet(textPattern + 0), 5 * A_PtrSize), "ptr", textPattern, "ptr*", textRangeArray) && textRangeArray) { if (!DllCall(NumGet(NumGet(textRangeArray + 0), 3 * A_PtrSize), "ptr", textRangeArray, "int*", length) && length) { if (!DllCall(NumGet(NumGet(textRangeArray + 0), 4 * A_PtrSize), "ptr", textRangeArray, "int", 0, "ptr*", textRange) && textRange) { VarSetCapacity(varIsReadOnly, 24) if (!DllCall(NumGet(NumGet(textRange + 0), 9 * A_PtrSize), "ptr", textRange, "int", 40015, "ptr", &varIsReadOnly, "int") && !NumGet(varIsReadOnly, 8, "int")) { if (!DllCall(NumGet(NumGet(textRange + 0), 10 * A_PtrSize), "ptr", textRange, "ptr*", rects) && rects) { rects := ComObject(0x2005, rects, 1) if (3 > rects.MaxIndex()) { if (DllCall(NumGet(NumGet(textRange + 0), 6 * A_PtrSize), "ptr", textRange, "int", 0) || DllCall(NumGet(NumGet(textRange + 0), 10 * A_PtrSize), "ptr", textRange, "ptr*", rects) || !rects) goto end rects := ComObject(0x2005, rects, 1) if (3 > rects.MaxIndex()) goto end } x := rects[0], y := rects[1], w := rects[2], h := rects[3] ObjRelease(textRange), ObjRelease(textRangeArray), ObjRelease(textPattern), ObjRelease(eleFocus) return hwndFocus } } end: ObjRelease(textRange) } } ObjRelease(textRangeArray) } ObjRelease(textPattern) } ObjRelease(eleFocus) } }
声明:站内资源为整理优化好的代码上传分享与学习研究,如果是开源代码基本都会标明出处,方便大家扩展学习路径。请不要恶意搬运,破坏站长辛苦整理维护的劳动成果。本站为爱好者分享站点,所有内容不作为商业行为。如若本站上传内容侵犯了原著者的合法权益,请联系我们进行删除下架。
评论(0)