经过初步排查,应该是以下函数的问题,因为我单独使用一下函数,也会出现莫名其妙的退出。这个函数是对对象的处理,不知道怎么检查错误的原因了。
该函数来自于官方论坛上,别人发的用来获取元素属性的。
#RequireAdmin
#include "UIAWrappers.au3"
#include "ISimpleDOM.au3"
#include <Misc.au3>
Const $cUIA_MAXDEPTH = 50 ; The array used is 50 deep if more simplespy just will crash
Const $dQuote = """"
Const $AutoSpy = 0 ;2000 ; SPY about every 2000 milliseconds automatically, 0 is turn of use only ctrl+w
Global $oldUIElement ; To keep track of latest referenced element
Global $frmSimpleSpy, $edtCtrlInfo, $lblCapture, $lblEscape, $lblRecord, $edtCtrlRecord
Global $UIA_CodeArray ; Code array to generate code from
;~ Global $xMouse, $yMouse
Global $hUser32DLL = DllOpen("user32.dll")
HotKeySet("{ESC}", "Close") ; Set ESC as a hotkey to exit the script.
;~ HotKeySet("^w", "GetElementInfo") ; Set Hotkey Ctrl+W to get some basic information in the GUI
;~ $frmSimpleSpy = GUICreate("Simple UIA Spy", 801, 601, 181, 4)
;~ WinSetOnTop($frmSimpleSpy, "", 1)
;~ $edtCtrlInfo = GUICtrlCreateEdit("", 18, 18, 512, 580)
;~ GUICtrlSetData(-1, "")
;~ $lblCapture = GUICtrlCreateLabel("Ctrl+W to capture information", 544, 10, 528, 17)
;~ GUISetState(@SW_SHOW)
;退出脚本
GUIRegisterMsg(0x0112, "WM_SYSCOMMAND")
Local $jMouse = False
Local $hFileHandle = FileOpen("GetText.txt", 9)
While True
;~ $msg = GUIGetMsg()
Sleep(100)
;~ Local $GetElementInfo = GetElementInfo()
;~ If _IsPressed("01", $hUser32DLL) And @error > 1796 And @extended < 1876 Then
;~ FileWrite($hFileHandle, $GetElementInfo & @CRLF)
;~ EndIf
If _IsPressed("01", $hUser32DLL) And GetElementInfo() = "查 询" Then
MsgBox(0,0, "鼠标左键被按下了!")
EndIf
WEnd
Func GetElementInfo()
Local $i, $xMouse, $yMouse, $oUIElement, $oTW
Local $tStruct = DllStructCreate($tagPOINT) ; Create a structure that defines the point to be checked. 创建一个定义要检查的点的结构。
Local $oParentHandle[$cUIA_MAXDEPTH] ; Max number of (grand)parents
$xMouse = MouseGetPos(0)
$yMouse = MouseGetPos(1)
DllStructSetData($tStruct, "x", $xMouse) ;设置结构元素的数据。
DllStructSetData($tStruct, "y", $yMouse) ;设置结构元素的数据。
$UIA_oUIAutomation.ElementFromPoint($tStruct, $UIA_pUIElement) ;ElementFromPoint:返回给定坐标点下最上层的 element 元素。
$oUIElement = ObjCreateInterface($UIA_pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) ;ObjCreateInterface:从给定的类名/对象指针, 接口标识符和描述字符串创建一个对象的引用。
$UIA_oUIAutomation.RawViewWalker($UIA_pTW) ;RawViewWalker:寻找所有项目;ContentViewWalker:只寻找其 IsContentElement 屬性是 true的项目;ControlViewWalker:只寻找其 IsControlElement 屬性是 true的项目。
$oTW = ObjCreateInterface($UIA_pTW, $sIID_IUIAutomationTreeWalker, $dtagIUIAutomationTreeWalker) ;ObjCreateInterface:从给定的类名/对象指针, 接口标识符和描述字符串创建一个对象的引用。
Local $pChildHandle
Local $oTMPParentHandle
Local $pTMPParentHandle
$oTW.getparentelement($oUIElement, $pTMPParentHandle) ;获取父元素
$oTMPParentHandle = ObjCreateInterface($pTMPParentHandle, $sIID_IUIAutomationElement, $dtagIUIAutomationElement) ;ObjCreateInterface:从给定的类名/对象指针, 接口标识符和描述字符串创建一个对象的引用。
$oTW.GetFirstChildElement($oTMPParentHandle, $pChildHandle) ;获取第一个子元素
$i = 0
$oTW.getparentelement($oUIElement, $oParentHandle[$i]) ;获取父元素
$oParentHandle[$i] = ObjCreateInterface($oParentHandle[$i], $sIID_IUIAutomationElement, $dtagIUIAutomationElement) ;ObjCreateInterface:从给定的类名/对象指针, 接口标识符和描述字符串创建一个对象的引用。
If IsObj($oParentHandle[$i]) <> 0 Then
While ($i <= $cUIA_MAXDEPTH - 1) And (IsObj($oParentHandle[$i]) = True)
$i = $i + 1
$oTW.getparentelement($oParentHandle[$i - 1], $oParentHandle[$i]) ;获取父元素
$oParentHandle[$i] = ObjCreateInterface($oParentHandle[$i], $sIID_IUIAutomationElement, $dtagIUIAutomationElement) ;ObjCreateInterface:从给定的类名/对象指针, 接口标识符和描述字符串创建一个对象的引用。
WEnd
EndIf
Local $pObject, $tVarChild
If AccessibleObjectFromPoint($xMouse, $yMouse, $pObject, $tVarChild) = $S_OK Then ;检索在屏幕上的指定点处显示的对象的 IAccessible 接口指针的地址。
Local $oIA_Object, $sName = ""
$oIA_Object = ObjCreateInterface($pObject, $sIID_IAccessible, $dtagIAccessible) ;ObjCreateInterface:从给定的类名/对象指针, 接口标识符和描述字符串创建一个对象的引用。$pObject:类标识符或对象的指针. 如果是类标识符, 可以用 ProgID 或 CLSID 字符串表示形式.
$oIA_Object.get_accName($CHILDID_SELF, $sName)
;~ GUICtrlSetData($edtCtrlInfo, $sName)
Return SetError($xMouse, $yMouse, $sName)
EndIf
EndFunc ;==>GetElementInfo
Func Close()
FileClose($hFileHandle)
DllClose($hUser32DLL)
Exit
EndFunc ;==>Close
;退出脚本
Func WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
Local $iID = BitAND($wParam, 0xFFFF)
If ($iID = 0xF060) Then
GUIDelete($frmSimpleSpy)
Exit
EndIf
EndFunc ;==>WM_SYSCOMMAND
|