【函数】利用ACC和UIA后台获取文本 By FeiYue

;--------------------------------------
;  利用ACC和UIA后台获取文本  By FeiYue
;
;  后台获取文本时每个坐标第一次会激活窗口
;--------------------------------------


F8::
; arr:=ACC获取文本()
arr:=后台ACC获取文本("记事本", 100, 100)
MsgBox 4096,, % "Name --> " arr.Name "`n`nText --> " arr.Value
return


F9::
; arr:=UIA获取文本()
arr:=后台UIA获取文本("记事本", 100, 100)
MsgBox 4096,, % "Name --> " arr.Name "`n`nText --> " arr.Value
return

;===========

;使用窗口标题和相对窗口的坐标
后台ACC获取文本(WinTitle, x, y)
{
  static tab:=[]
  if !(r:=tab[WinTitle "|" x "|" y])
  {
    SetTitleMatchMode, 2
    ifWinNotExist, %WinTitle%,, return
    WinActivate
    WinWaitActive
    WinGetPos, winx, winy
    arr:=ACC获取文本(winx+x, winy+y, Acc, child)
    tab[WinTitle "|" x "|" y]:=[Acc, child]
    return arr
  }
  Acc:=r[1], child:=r[2], arr:=[]
  Try arr["Name"]:=Acc.accName(child)
  Try arr["Value"]:=Acc.accValue(child)
  return arr
}

;使用窗口标题和相对窗口的坐标
后台UIA获取文本(WinTitle, x, y)
{
  static tab:=[]
  if !(Element:=tab[WinTitle "|" x "|" y])
  {
    SetTitleMatchMode, 2
    ifWinNotExist, %WinTitle%,, return
    WinActivate
    WinWaitActive
    WinGetPos, winx, winy
    arr:=UIA获取文本(winx+x, winy+y, Element)
    tab[WinTitle "|" x "|" y]:=Element
    return arr
  }
  arr:=[], VarSetCapacity(var, 8+2*A_PtrSize), NumPut(8, var, "Short")
  For k, v in { "Name":30005, "Value":30045 }
  {
    ;-- Element.GetCurrentPropertyValue == 10
    DllCall(NumGet(NumGet(Element+0)+10*A_PtrSize),"Ptr",Element,"Int",v,"Ptr",&var)
    arr[k]:=StrGet(pstr:=NumGet(var, 8, "Ptr"), "utf-16")
    DllCall("oleaut32\SysFreeString", "Ptr",pstr)
  }
  return arr
}

UIA获取文本(x="", y="", ByRef Element="")
{
  static UIA:=ComObjCreate("{ff48dba4-60ef-4201-aa87-54103eef594e}"
    , "{30cbe57d-d9d0-452a-ab13-7ac5ac4825ee}")
    , h:=DllCall("LoadLibrary", "Str","oleaut32.dll")
  ;--------
  pos:=(x=""||y="" ? 0*DllCall("GetCursorPos","Int64*",pt)+pt : x&0xFFFFFFFF|y<<32)
  id:=DllCall("WindowFromPoint", "Int64",pos)
  SendMessage, WM_GETOBJECT:=0x3D, 0, 1,, ahk_id %id%
  ;-- UIA.ElementFromPoint == 7
  DllCall(NumGet(NumGet(UIA+0)+7*A_PtrSize), "Ptr",UIA, "Int64",pos, "Ptr*",Element)
  ;--------
  arr:=[], VarSetCapacity(var, 8+2*A_PtrSize), NumPut(8, var, "Short")
  For k, v in { "Name":30005, "Value":30045 }
  {
    ;-- Element.GetCurrentPropertyValue == 10
    DllCall(NumGet(NumGet(Element+0)+10*A_PtrSize),"Ptr",Element,"Int",v,"Ptr",&var)
    arr[k]:=StrGet(pstr:=NumGet(var, 8, "Ptr"), "utf-16")
    DllCall("oleaut32\SysFreeString", "Ptr",pstr)
  }
  return arr
}

ACC获取文本(x="", y="", ByRef Acc="", ByRef child="")
{
  static h:=DllCall("LoadLibrary", "Str","oleacc.dll")
  ;--------
  pos:=(x=""||y="" ? 0*DllCall("GetCursorPos","Int64*",pt)+pt : x&0xFFFFFFFF|y<<32)
  id:=DllCall("WindowFromPoint", "Int64",pos)
  SendMessage, WM_GETOBJECT:=0x3D, 0, 1,, ahk_id %id%
  Acc:=child:="", VarSetCapacity(var,8+2*A_PtrSize,0)
  if DllCall("oleacc\AccessibleObjectFromPoint","Int64",pos,"Ptr*",pacc,"Ptr",&var)=0
    Acc:=ComObjEnwrap(9,pacc,1), child:=NumGet(var,8,"UInt")
  ;--------
  arr:=[]
  Try arr["Name"]:=Acc.accName(child)
  Try arr["Value"]:=Acc.accValue(child)
  return arr
}

 

给TA捐赠
共{{data.count}}人
人已捐赠
其他教程

托盘图标鼠标按键触发更改

2021-11-24 8:59:03

其他函数教程

【函数】调出文件夹选择对话框

2021-11-24 8:59:23

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
有新私信 私信列表
搜索