Sexan, It was already in your code, as you found track window, you can also find Envelope window:
Code:
function msg(m)
reaper.ShowConsoleMsg(tostring(m) .. "\n")
end
env = reaper.GetSelectedEnvelope(0)
main_wnd = reaper.GetMainHwnd()
retval, found = reaper.JS_Window_ListAllChild(main_wnd)
msg(env)
for adr in found:gmatch("%w+") do
local handl = reaper.JS_Window_HandleFromAddress(tonumber(adr))
if reaper.JS_Window_GetLongPtr(handl, "USER") == env then
retval, left, top, right, bottom = reaper.JS_Window_GetRect(handl)
msg(bottom-top) break
end
end