, there isn't such a built-in method, but it's rather easy to create one with a recursive function:
Code: Select all
els := GetElementsInRect(Acc.ObjectFromWindow("A"), 200, 200, 500, 500)
out := ""
for el in els
out .= el.Dump() "`n"
MsgBox out
GetElementsInRect(oAcc, l, t, r, b, containFully:=False, childrenAllowed:=False) {
RecurseElements(oAcc, &(out := []), l, t, r, b)
return out
RecurseElements(oAcc, &elements, l, t, r, b) {
for el in oAcc {
len := el.Length, loc := el.Location, l2 := loc.x, t2 := loc.y, r2 := loc.x+loc.w, b2 := loc.y+loc.h
if !IntersectRect(l, t, r, b, l2, t2, r2, b2)
continue
if (childrenAllowed || !len) && (!containFully || (containFully && l2 >= l && t2 >= t && r2 <= r && b2 <= b))
elements.Push(el)
if len
RecurseElements(el, &elements, l, t, r, b)
}
}
}
IntersectRect(l1, t1, r1, b1, l2, t2, r2, b2) {
rect1 := Buffer(16), rect2 := Buffer(16), rectOut := Buffer(16)
NumPut("int", l1, "int", t1, "int", r1, "int", b1, rect1)
NumPut("int", l2, "int", t2, "int", r2, "int", b2, rect2)
if DllCall("user32\IntersectRect", "Ptr", rectOut, "Ptr", rect1, "Ptr", rect2)
return {l:NumGet(rectOut, 0, "Int"), t:NumGet(rectOut, 4, "Int"), r:NumGet(rectOut, 8, "Int"), b:NumGet(rectOut, 12, "Int")}
}
This method assumes that elements can only contain smaller elements, and that all child elements are located within the bounds of the parent element. I'm not 100% sure this is correct though.
If this turns out to work as expected, I'll think about adding it in the main library as well.