#SingleInstance Force
#Persistent
#NoEnv
ListLines Off
DetectHiddenWindows, on
SetBatchLines -1
SetFormat, IntegerFast, h
winid := WinExist("ahk_class IEFrame ahk_exe iexplore.exe")
name = Избранное
role = панель инструментов
hwnd := HwndFromAccName(winid, name, role)
ControlGet, thwnd, Hwnd,, ToolbarWindow324, ahk_id %winid%
MsgBox, % hwnd " " thwnd
ControlGetText, str,, ahk_id %hwnd%
MsgBox, % str
return
HwndFromAccName(winid, name, role)
{
if !winid
MsgBox, % "Окно не найдено"
else if !IsObject(AccObj := AccObjectFromWindow(winid))
MsgBox, % "Не удалось получить IAccessible"
else if !IsObject(oExist := ExistAccName(AccObj, name, role, hwnd)) || !hwnd
MsgBox, % "Элемент не найден"
else
Return hwnd
}
ExistAccName(AccObj, name, role, byref hwnd="")
{
try if (AccRole(AccObj) = role && AccObj.accName(2) = name)
Return AccObj, hwnd := AccWindowFromObject(AccObj)
for k, v in AccChildren(AccObj)
if IsObject(obj := ExistAccName(v, name, role, hwnd))
Return obj
}
AccWindowFromObject(pacc)
{
If DllCall("oleacc\WindowFromAccessibleObject", "Ptr", IsObject(pacc)?ComObjValue(pacc):pacc, "Ptr*", hWnd) = 0
Return hWnd
}
AccInit()
{
Static h
If Not h
h:=DllCall("LoadLibrary","Str","oleacc","Ptr")
}
AccObjectFromWindow(hWnd, idObject = 0)
{
AccInit()
If DllCall("oleacc\AccessibleObjectFromWindow", "Ptr", hWnd, "UInt", idObject&=0xFFFFFFFF, "Ptr", -VarSetCapacity(IID,16)+NumPut(idObject==0xFFFFFFF0?0x46000000000000C0:0x719B3800AA000C81,NumPut(idObject==0xFFFFFFF0?0x0000000000020400:0x11CF3C3D618736E0,IID,"Int64"),"Int64"), "Ptr*", pacc)=0
Return ComObjEnwrap(9,pacc,1)
}
AccRole(Acc, ChildId=0) {
try Return ComObjType(Acc,"Name")="IAccessible"?AccGetRoleText(Acc.accRole(ChildId)):""
}
AccGetRoleText(nRole) {
nSize := DllCall("oleacc\GetRoleText", "Uint", nRole, "Ptr", 0, "Uint", 0)
VarSetCapacity(sRole, (A_IsUnicode?2:1)*nSize)
DllCall("oleacc\GetRoleText", "Uint", nRole, "str", sRole, "Uint", nSize+1)
Return sRole
}
AccError(p="") {
static setting:=0
return p=""?setting:setting:=p
}
AccQuery(Acc) {
try return ComObj(9, ComObjQuery(Acc,"{618736e0-3c3d-11cf-810c-00aa00389b71}"), 1)
}
AccChildren(Acc) {
if ComObjType(Acc,"Name") != "IAccessible"
ErrorLevel := "Invalid IAccessible Object"
else {
AccInit(), cChildren:=Acc.accChildCount, Children:=[]
if DllCall("oleacc\AccessibleChildren", "Ptr",ComObjValue(Acc), "Int",0, "Int",cChildren, "Ptr",VarSetCapacity(varChildren,cChildren*(8+2*A_PtrSize),0)*0+&varChildren, "Int*",cChildren)=0 {
Loop %cChildren%
i:=(A_Index-1)*(A_PtrSize*2+8)+8, child:=NumGet(varChildren,i), Children.Insert(NumGet(varChildren,i-8)=9?AccQuery(child):child), NumGet(varChildren,i-8)=9?ObjRelease(child):
return Children.MaxIndex()?Children:
} else
ErrorLevel := "AccessibleChildren DllCall Failed"
}
if AccError()
throw Exception(ErrorLevel,-1)
}
Esc::
ExitApp