Opt("MustDeclareVars", 1) #AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code #AutoIt3Wrapper_Run_AU3Check=Y #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include Global $_UIA_SMART_AUTOMATION = Null Global $_UIA_SMART_DESKTOP = Null #Danyfirex #include "ErrorLog.au3" ; https://www.autoitscript.com/forum/topic/195882-errorlogau3-udf-a-logging-library/ #include "UIA_Constants.au3" ;~ #include "z:\!!!_SVN_AU3\UDF_Forum\mLipok\ErrorLog.au3" ;~ #include "z:\!!!_SVN_AU3\UDF_Forum\Other_Members\UIA_Constants.au3 " #Region - _UIASimple_*** Helpers Func _UIASimple_YesNo($sTitle, $sText, $sButton) Local $oUIA = _UIASimple_InitAutomation() Local $oWindow = _UIASimple_GetWindowByTitle($sTitle) If Not IsObj($oWindow) Then Return False Local $pCondition0 $oUIA.CreatePropertyCondition($UIA_NamePropertyId, $sText, $pCondition0) If Not $pCondition0 Then _Log(@ScriptLineNumber & " $pCondition0 ERR") Return False EndIf _Log_OnSuccess("$pCondition0 OK") Local $pText, $oText $oWindow.FindFirst($TreeScope_Subtree, $pCondition0, $pText) $oText = ObjCreateInterface($pText, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement) If Not IsObj($oText) Then _Log(@ScriptLineNumber & " $oText ERR") Return False EndIf _Log_OnSuccess("$oText OK") Local $sValue = "" $oText.GetCurrentPropertyValue($UIA_NamePropertyId, $sValue) ;~ _Log_Info($sValue) If $sValue = $sText Then Local $pCondition1 $oUIA.CreatePropertyCondition($UIA_NamePropertyId, $sButton, $pCondition1) If Not $pCondition1 Then _Log(@ScriptLineNumber & " $pCondition1 ERR") Return False EndIf Local $pButton, $oButton $oWindow.FindFirst($TreeScope_Subtree, $pCondition1, $pButton) $oButton = ObjCreateInterface($pButton, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement) If Not IsObj($oButton) Then _Log(@ScriptLineNumber & " $oButton ERR") Return False EndIf _Log_OnSuccess("$oButton OK") Local $pInvokePattern1, $oInvokePattern1 $oButton.GetCurrentPattern($UIA_InvokePatternId, $pInvokePattern1) $oInvokePattern1 = ObjCreateInterface($pInvokePattern1, $sIID_IUIAutomationInvokePattern, $dtag_IUIAutomationInvokePattern) If Not IsObj($oInvokePattern1) Then _Log(@ScriptLineNumber & " $oInvokePattern1 ERR") Return False EndIf _Log_OnSuccess("$oInvokePattern1 OK") $oInvokePattern1.Invoke() Return True EndIf Return False EndFunc ;==>_UIASimple_YesNo Func _UIASimple_WinExist($sTitle, $sText) Local $oUIA = _UIASimple_InitAutomation() Local $oWindow = _UIASimple_GetWindowByTitle($sTitle) If Not IsObj($oWindow) Then Return False Local $pCondition0 $oUIA.CreatePropertyCondition($UIA_NamePropertyId, $sText, $pCondition0) If Not $pCondition0 Then _Log(@ScriptLineNumber & " $pCondition0 ERR") Return False EndIf _Log_OnSuccess("$pCondition0 OK") Local $pText, $oText $oWindow.FindFirst($TreeScope_Subtree, $pCondition0, $pText) $oText = ObjCreateInterface($pText, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement) If Not IsObj($oText) Then _Log(@ScriptLineNumber & " $oText ERR") Return False EndIf _Log_OnSuccess("$oText OK") Local $sValue = "" $oText.GetCurrentPropertyValue($UIA_NamePropertyId, $sValue) _Log_Info($sValue) If $sValue = $sText Then Return True EndFunc ;==>_UIASimple_WinExist #EndRegion - _UIASimple_*** Helpers #Region - _UIASimple_*** Wrappers Func __UIASimple_ConsoleWrite($sData) ConsoleWrite($sData & @CRLF) EndFunc ;==>__UIASimple_ConsoleWrite Func _UIASimple_GetDesktop() If IsObj($_UIA_SMART_DESKTOP) Then Return $_UIA_SMART_DESKTOP Local $oUIA = _UIASimple_InitAutomation() ; Get Desktop element Local $pDesktop $oUIA.GetRootElement($pDesktop) Local $oDesktop = ObjCreateInterface($pDesktop, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement) If Not IsObj($oDesktop) Then Return _Log(@ScriptLineNumber & " $oDesktop ERR") _Log_OnSuccess("$oDesktop OK") $_UIA_SMART_DESKTOP = $oDesktop Return $_UIA_SMART_DESKTOP EndFunc ;==>_UIASimple_GetDesktop Func _UIASimple_InitAutomation() If IsObj($_UIA_SMART_AUTOMATION) Then Return $_UIA_SMART_AUTOMATION ; Create UI Automation object Local $oUIA = ObjCreateInterface($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtag_IUIAutomation) If Not IsObj($oUIA) Then Return _Log(@ScriptLineNumber & " $oUIA ERR") _Log_OnSuccess("$oUIA OK") $_UIA_SMART_AUTOMATION = $oUIA Return $_UIA_SMART_AUTOMATION EndFunc ;==>_UIASimple_InitAutomation Func _UIASimple_GetWindowByTitle($sTitle) Local $oUIA = _UIASimple_InitAutomation() Local $oDesktop = _UIASimple_GetDesktop() Local $pCondition ; Note that $UIA_ClassNamePropertyId maybe ia a CASE SENSITIVE condition $oUIA.CreatePropertyCondition($UIA_NamePropertyId, $sTitle, $pCondition) If Not $pCondition Then Return _Log(@ScriptLineNumber & " $pCondition ERR") _Log_OnSuccess("$pCondition OK") Local $pWindow $oDesktop.FindFirst($TreeScope_Descendants, $pCondition, $pWindow) Local $oWindow = ObjCreateInterface($pWindow, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement) If Not IsObj($oWindow) Then Return _Log(@ScriptLineNumber & " $oWindow ERR") _Log_OnSuccess("$oWindow OK") Return $oWindow EndFunc ;==>_UIASimple_GetWindowByTitle #EndRegion - _UIASimple_*** Wrappers