Jump to content

Interface AutoItObject IUIAutomation


Recommended Posts

edit: updated the code sample based on the answers from trancexx now better interface definitions

* I am definitily missing the logic in how to initialize the interface and object(s).

Some advice from the more AIO experts will be helpfull?

probably not understanding the difference between the functions to create an object and the wrapper functions.

The easy (working) example in VBA (within Excel) under Windows XP with Automation API 3.0 installed (is XP + .NET 4)

the UIAutomationCore.DLL is an unmanaged DLL and should be possible to call this with autoitobject

Sub test()
'      uuid(30CBE57D-D9D0-452A-AB13-7AC5AC4825EE) interface IUIAutomation
    Dim c As New CUIAutomation                    'reference to IUIautomation object
    Debug.Print c.GetRootElement.CurrentClassName 'Just to see if the basics work
End Sub

Output of above will be #32768 (the desktop)

As there is no classname in the registry creating with functions like createobj will not do the trick to get access

Then I try converting this VBA to AutoItObject code making use of generator

and the latest AIO library

EndGOAL is to have access to this UIAutomationCore.DLL so many more objects/controls can be looked/manipulated on from within AutoIT.

Probably helpfull [

uuid(FF48DBA4-60EF-4201-AA87-54103EEF594E),

version(1.0),

helpstring("The Central Class for UIAutomation")

]

coclass CUIAutomation {

[default] interface IUIAutomation;

};

So I would assume I have to make

** The code I have so far

#include <AutoItObject.au3>
;~ Assume to have loaded the DLL first
Global Const $hUIAutomation = DllOpen("uiautomationcore.dll")

_AutoItObject_StartUp()

Global $tagIUnknown = _
    "QueryInterface long_ptr(ulong_ptr;int_ptr);" & _
    "AddRef wstr();" & _
    "Release wstr();"

Global $sCLSID_CUIAutomation="{FF48DBA4-60EF-4201-AA87-54103EEF594E}"
Global $CLSID_CUIAutomation=_AutoItObject_CLSIDFromString($sCLSID_CUIAutomation)

Global $sCLSID_IUIAutomationElement = "{D22108AA-8AC5-49A5-837B-37BBB3D7591E}"
Global $CLSID_IUIAutomationElement = _AutoItObject_CLSIDFromString($sCLSID_IUIAutomationElement)
Global $tagIUIAutomationElement = $tagIUnknown & _
    "SetFocus hresult();" & _
    "GetRuntimeId hresult(lparam*);" & _
    "FindFirst hresult(ptr;ptr;ptr*);" & _
    "FindAll hresult(ptr;ptr;ptr*);" & _
    "FindFirstBuildCache hresult(ptr;ptr;ptr;ptr*);" & _
    "FindAllBuildCache hresult(ptr;ptr;ptr;ptr*);" & _
    "BuildUpdatedCache hresult(ptr;ptr*);" & _
    "GetCurrentPropertyValue hresult(int;variant*);" & _
    "GetCurrentPropertyValueEx hresult(int;long;variant*);" & _
    "GetCachedPropertyValue hresult(int;variant*);" & _
    "GetCachedPropertyValueEx hresult(int;long;variant*);" & _
    "GetCurrentPatternAs hresult(int;ptr;none*);" & _
    "GetCachedPatternAs hresult(int;ptr;none*);" & _
    "GetCurrentPattern hresult(int;ptr*);" & _
    "GetCachedPattern hresult(int;ptr*);" & _
    "GetCachedParent hresult(ptr*);" & _
    "GetCachedChildren hresult(ptr*);" & _
    "get_CurrentProcessId hresult(int*);" & _
    "get_CurrentControlType hresult(int*);" & _
    "get_CurrentLocalizedControlType hresult(bstr*);" & _
    "get_CurrentName hresult(bstr*);" & _
    "get_CurrentAcceleratorKey hresult(bstr*);" & _
    "get_CurrentAccessKey hresult(bstr*);" & _
    "get_CurrentHasKeyboardFocus hresult(long*);" & _
    "get_CurrentIsKeyboardFocusable hresult(long*);" & _
    "get_CurrentIsEnabled hresult(long*);" & _
    "get_CurrentAutomationId hresult(bstr*);" & _
    "get_CurrentClassName hresult(bstr*);" & _
    "get_CurrentHelpText hresult(bstr*);" & _
    "get_CurrentCulture hresult(int*);" & _
    "get_CurrentIsControlElement hresult(long*);" & _
    "get_CurrentIsContentElement hresult(long*);" & _
    "get_CurrentIsPassword hresult(long*);" & _
    "get_CurrentNativeWindowHandle hresult(none*);" & _
    "get_CurrentItemType hresult(bstr*);" & _
    "get_CurrentIsOffscreen hresult(long*);" & _
    "get_CurrentOrientation hresult(ptr*);" & _
    "get_CurrentFrameworkId hresult(bstr*);" & _
    "get_CurrentIsRequiredForForm hresult(long*);" & _
    "get_CurrentItemStatus hresult(bstr*);" & _
    "get_CurrentBoundingRectangle hresult(ptr*);" & _
    "get_CurrentLabeledBy hresult(ptr*);" & _
    "get_CurrentAriaRole hresult(bstr*);" & _
    "get_CurrentAriaProperties hresult(bstr*);" & _
    "get_CurrentIsDataValidForForm hresult(long*);" & _
    "get_CurrentControllerFor hresult(ptr*);" & _
    "get_CurrentDescribedBy hresult(ptr*);" & _
    "get_CurrentFlowsTo hresult(ptr*);" & _
    "get_CurrentProviderDescription hresult(bstr*);" & _
    "get_CachedProcessId hresult(int*);" & _
    "get_CachedControlType hresult(int*);" & _
    "get_CachedLocalizedControlType hresult(bstr*);" & _
    "get_CachedName hresult(bstr*);" & _
    "get_CachedAcceleratorKey hresult(bstr*);" & _
    "get_CachedAccessKey hresult(bstr*);" & _
    "get_CachedHasKeyboardFocus hresult(long*);" & _
    "get_CachedIsKeyboardFocusable hresult(long*);" & _
    "get_CachedIsEnabled hresult(long*);" & _
    "get_CachedAutomationId hresult(bstr*);" & _
    "get_CachedClassName hresult(bstr*);" & _
    "get_CachedHelpText hresult(bstr*);" & _
    "get_CachedCulture hresult(int*);" & _
    "get_CachedIsControlElement hresult(long*);" & _
    "get_CachedIsContentElement hresult(long*);" & _
    "get_CachedIsPassword hresult(long*);" & _
    "get_CachedNativeWindowHandle hresult(none*);" & _
    "get_CachedItemType hresult(bstr*);" & _
    "get_CachedIsOffscreen hresult(long*);" & _
    "get_CachedOrientation hresult(ptr*);" & _
    "get_CachedFrameworkId hresult(bstr*);" & _
    "get_CachedIsRequiredForForm hresult(long*);" & _
    "get_CachedItemStatus hresult(bstr*);" & _
    "get_CachedBoundingRectangle hresult(ptr*);" & _
    "get_CachedLabeledBy hresult(ptr*);" & _
    "get_CachedAriaRole hresult(bstr*);" & _
    "get_CachedAriaProperties hresult(bstr*);" & _
    "get_CachedIsDataValidForForm hresult(long*);" & _
    "get_CachedControllerFor hresult(ptr*);" & _
    "get_CachedDescribedBy hresult(ptr*);" & _
    "get_CachedFlowsTo hresult(ptr*);" & _
    "get_CachedProviderDescription hresult(bstr*);" & _
    "GetClickablePoint hresult(ptr*;long*);"
; -------------------------------
Local $pUIAutomationElement
; Initialize interface pointer $pUIAutomationElement here, for example:
; _AutoItObject_CoCreateInstance(DllStructGetPtr($tCLSID_SomeClass), 0, 1, DllStructGetPtr($tIID_IUIAutomationElement), $pUIAutomationElement)
;Local $objUIAutomationElement = _AutoItObject_WrapperCreate($pUIAutomationElement, $tagIUIAutomationElement)

Global $sIID_IUIAutomation = "{30CBE57D-D9D0-452A-AB13-7AC5AC4825EE}"
Global $IID_IUIAutomation = _AutoItObject_CLSIDFromString($sIID_IUIAutomation)
Global $tagIUIAutomation = $tagIUnknown & _
    "CompareElements hresult(ptr;ptr;long*);" & _
    "CompareRuntimeIds hresult(lparam;lparam;long*);" & _
    "GetRootElement hresult(ptr*);" & _
    "ElementFromHandle hresult(none;ptr*);" & _
    "ElementFromPoint hresult(ptr;ptr*);" & _
    "GetFocusedElement hresult(ptr*);" & _
    "GetRootElementBuildCache hresult(ptr;ptr*);" & _
    "ElementFromHandleBuildCache hresult(none;ptr;ptr*);" & _
    "ElementFromPointBuildCache hresult(ptr;ptr;ptr*);" & _
    "GetFocusedElementBuildCache hresult(ptr;ptr*);" & _
    "CreateTreeWalker hresult(ptr;ptr*);" & _
    "get_ControlViewWalker hresult(ptr*);" & _
    "get_ContentViewWalker hresult(ptr*);" & _
    "get_RawViewWalker hresult(ptr*);" & _
    "get_RawViewCondition hresult(ptr*);" & _
    "get_ControlViewCondition hresult(ptr*);" & _
    "get_ContentViewCondition hresult(ptr*);" & _
    "CreateCacheRequest hresult(ptr*);" & _
    "CreateTrueCondition hresult(ptr*);" & _
    "CreateFalseCondition hresult(ptr*);" & _
    "CreatePropertyCondition hresult(int;variant;ptr*);" & _
    "CreatePropertyConditionEx hresult(int;variant;ptr;ptr*);" & _
    "CreateAndCondition hresult(ptr;ptr;ptr*);" & _
    "CreateAndConditionFromArray hresult(lparam;ptr*);" & _
    "CreateAndConditionFromNativeArray hresult(ptr;int;ptr*);" & _
    "CreateOrCondition hresult(ptr;ptr;ptr*);" & _
    "CreateOrConditionFromArray hresult(lparam;ptr*);" & _
    "CreateOrConditionFromNativeArray hresult(ptr;int;ptr*);" & _
    "CreateNotCondition hresult(ptr;ptr*);" & _
    "AddAutomationEventHandler hresult(int;ptr;ptr;ptr;ptr);" & _
    "RemoveAutomationEventHandler hresult(int;ptr;ptr);" & _
    "AddPropertyChangedEventHandlerNativeArray hresult(ptr;ptr;ptr;ptr;int;int);" & _
    "AddPropertyChangedEventHandler hresult(ptr;ptr;ptr;ptr;lparam);" & _
    "RemovePropertyChangedEventHandler hresult(ptr;ptr);" & _
    "AddStructureChangedEventHandler hresult(ptr;ptr;ptr;ptr);" & _
    "RemoveStructureChangedEventHandler hresult(ptr;ptr);" & _
    "AddFocusChangedEventHandler hresult(ptr;ptr);" & _
    "RemoveFocusChangedEventHandler hresult(ptr);" & _
    "RemoveAllEventHandlers hresult();" & _
    "IntNativeArrayToSafeArray hresult(int;int;lparam*);" & _
    "IntSafeArrayToNativeArray hresult(lparam;int*;int*);" & _
    "RectToVariant hresult(ptr;variant*);" & _
    "VariantToRect hresult(variant;ptr*);" & _
    "SafeArrayToRectNativeArray hresult(lparam;ptr*;int*);" & _
    "CreateProxyFactoryEntry hresult(ptr;ptr*);" & _
    "get_ProxyFactoryMapping hresult(ptr*);" & _
    "GetPropertyProgrammaticName hresult(int;bstr*);" & _
    "GetPatternProgrammaticName hresult(int;bstr*);" & _
    "PollForPotentialSupportedPatterns hresult(ptr;lparam*;lparam*);" & _
    "PollForPotentialSupportedProperties hresult(ptr;lparam*;lparam*);" & _
    "CheckNotSupported hresult(variant;long*);" & _
    "get_ReservedNotSupportedValue hresult(ptr*);" & _
    "get_ReservedMixedAttributeValue hresult(ptr*);" & _
    "ElementFromIAccessible hresult(ptr;int;ptr*);" & _
    "ElementFromIAccessibleBuildCache hresult(ptr;int;ptr;ptr*);"

; -------------------------------
Global $tagIUIAutomationCondition = $tagIUnknown

Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")
Func _ErrFunc()
    ConsoleWrite("COM Error, ScriptLine(" & $oError.scriptline & ") : Number 0x" & Hex($oError.number, 8) & " - " & $oError.windescription & @CRLF)
EndFunc   ;==>_ErrFunc


_AutoItObject_StartUp()


Global $objUIAutomation = _AutoItObject_ObjCreate($sCLSID_CUIAutomation, $sIID_IUIAutomation, $tagIUIAutomation)

If IsObj($objUIAutomation) Then
    ConsoleWrite("At least it seems I have an object to start with" & @CRLF)
EndIf

ConsoleWrite("Do we get here?" & @CRLF)

Global $aCall = $objUIAutomation.GetRootElement(0)
Global $objRoot = _AutoItObject_WrapperCreate($aCall[1], $tagIUIAutomationElement)

If IsObj($objRoot) Then
    ConsoleWrite("At least it seems I have a second object to start with" & @CRLF)
EndIf

$aCall = $objRoot.get_CurrentClassName(0)
ConsoleWrite($aCall[1] & @CRLF)

$objRoot = 0
$objUIAutomation = 0
Edited by junkew
Link to comment
Share on other sites

You have made several mistakes in your code. First you have to read AutoItObject help file to see what datatypes are supported. For example there is no IUIAutomationCacheRequest type. You have to cast it to ptr because in essence that what any interface pointer is; Pointer. Same thing goes for any other similar type.

Another thing is that AutoItobject supports bstr data type (as opposed to AutoIt itself). That means that if some method of some object defined through its interface requires or outputs BSTR, you have to specify that exact data type. Here's your working example:

#include <AutoItObject.au3>

Global Const $sCLSID_CUIAutomation = "{FF48DBA4-60EF-4201-AA87-54103EEF594E}"
Global Const $sIID_IUIAutomation = "{30CBE57D-D9D0-452A-AB13-7AC5AC4825EE}"
Global $tagIUIAutomation = $dtagIUnknown & _
        "CompareElements long(ptr;ptr;int);" & _
        "CompareRuntimeIds long(lparam;lparam;int);" & _
        "GetRootElement hresult(ptr*);" & _
        "ElementFromHandle long(none;ptr);" & _
        "ElementFromPoint long(long;long;ptr);" & _
        "GetFocusedElement long(ptr);" & _
        "GetRootElementBuildCache long(ptr;ptr);" & _
        "ElementFromHandleBuildCache long(none;ptr;ptr);" & _
        "ElementFromPointBuildCache long(long;long;ptr;ptr);" & _
        "GetFocusedElementBuildCache long(ptr;ptr);" & _
        "CreateTreeWalker long(ptr;ptr);" & _
        "get_ControlViewWalker long(ptr);" & _
        "get_ContentViewWalker long(ptr);" & _
        "get_RawViewWalker long(ptr);" & _
        "get_RawViewCondition long(ptr);" & _
        "get_ControlViewCondition long(ptr);" & _
        "get_ContentViewCondition long(ptr);" & _
        "CreateCacheRequest long(ptr);" & _
        "CreateTrueCondition long(ptr);" & _
        "CreateFalseCondition long(ptr);" & _
        "CreatePropertyCondition long(int;variant;ptr);" & _
        "CreatePropertyConditionEx long(int;variant;int;ptr);" & _
        "CreateAndCondition long(ptr;ptr;ptr);" & _
        "CreateAndConditionFromArray long(lparam;ptr);" & _
        "CreateAndConditionFromNativeArray long(ptr;int;ptr);" & _
        "CreateOrCondition long(ptr;ptr;ptr);" & _
        "CreateOrConditionFromArray long(lparam;ptr);" & _
        "CreateOrConditionFromNativeArray long(ptr;int;ptr);" & _
        "CreateNotCondition long(ptr;ptr);" & _
        "AddAutomationEventHandler long(int;ptr;int;ptr;ptr);" & _
        "RemoveAutomationEventHandler long(int;ptr;ptr);" & _
        "AddPropertyChangedEventHandlerNativeArray long(ptr;int;ptr;ptr;int;int);" & _
        "AddPropertyChangedEventHandler long(ptr;int;ptr;ptr;lparam);" & _
        "RemovePropertyChangedEventHandler long(ptr;ptr);" & _
        "AddStructureChangedEventHandler long(ptr;int;ptr;ptr);" & _
        "RemoveStructureChangedEventHandler long(ptr;ptr);" & _
        "AddFocusChangedEventHandler long(ptr;ptr);" & _
        "RemoveFocusChangedEventHandler long(ptr);" & _
        "RemoveAllEventHandlers long();" & _
        "IntNativeArrayToSafeArray long(int;int;lparam);" & _
        "IntSafeArrayToNativeArray long(lparam;int;int);" & _
        "RectToVariant long(long;long;variant);" & _
        "VariantToRect long(variant;long;long);" & _
        "SafeArrayToRectNativeArray long(lparam;long;long;int);" & _
        "CreateProxyFactoryEntry long(ptr;ptr);" & _
        "get_ProxyFactoryMapping long(ptr);" & _
        "GetPropertyProgrammaticName long(int;wstr);" & _
        "GetPatternProgrammaticName long(int;wstr);" & _
        "PollForPotentialSupportedPatterns long(ptr;lparam;lparam);" & _
        "PollForPotentialSupportedProperties long(ptr;lparam;lparam);" & _
        "CheckNotSupported long(variant;int);" & _
        "get_ReservedNotSupportedValue long(ptr);" & _
        "get_ReservedMixedAttributeValue long(ptr);" & _
        "ElementFromptr long(ptr;int;ptr);" & _
        "ElementFromptrBuildCache long(ptr;int;ptr;ptr);"

; -------------------------------

Global Const $sIID_IUIAutomationElement = "{D22108AA-8AC5-49A5-837B-37BBB3D7591E}"
Global $tagIUIAutomationElement = $dtagIUnknown & _
        "SetFocus long();" & _
        "GetRuntimeId long(lparam);" & _
        "FindFirst long(int;ptr;ptr);" & _
        "FindAll long(int;ptr;ptr);" & _
        "FindFirstBuildCache long(int;ptr;ptr;ptr);" & _
        "FindAllBuildCache long(int;ptr;ptr;ptr);" & _
        "BuildUpdatedCache long(ptr;ptr);" & _
        "GetCurrentPropertyValue long(int;variant);" & _
        "GetCurrentPropertyValueEx long(int;int;variant);" & _
        "GetCachedPropertyValue long(int;variant);" & _
        "GetCachedPropertyValueEx long(int;int;variant);" & _
        "GetCurrentPatternAs long(int;ptr;none);" & _
        "GetCachedPatternAs long(int;ptr;none);" & _
        "GetCurrentPattern long(int;ptr);" & _
        "GetCachedPattern long(int;ptr);" & _
        "GetCachedParent long(ptr);" & _
        "GetCachedChildren long(ptr);" & _
        "get_CurrentProcessId long(int);" & _
        "get_CurrentControlType long(int);" & _
        "get_CurrentLocalizedControlType long(wstr);" & _
        "get_CurrentName long(wstr);" & _
        "get_CurrentAcceleratorKey long(wstr);" & _
        "get_CurrentAccessKey long(wstr);" & _
        "get_CurrentHasKeyboardFocus long(int);" & _
        "get_CurrentIsKeyboardFocusable long(int);" & _
        "get_CurrentIsEnabled long(int);" & _
        "get_CurrentAutomationId long(wstr);" & _
        "get_CurrentClassName hresult(bstr*);" & _
        "get_CurrentHelpText long(wstr);" & _
        "get_CurrentCulture long(int);" & _
        "get_CurrentIsControlElement long(int);" & _
        "get_CurrentIsContentElement long(int);" & _
        "get_CurrentIsPassword long(int);" & _
        "get_CurrentNativeWindowHandle long(none);" & _
        "get_CurrentItemType long(wstr);" & _
        "get_CurrentIsOffscreen long(int);" & _
        "get_CurrentOrientation long(int);" & _
        "get_CurrentFrameworkId long(wstr);" & _
        "get_CurrentIsRequiredForForm long(int);" & _
        "get_CurrentItemStatus long(wstr);" & _
        "get_CurrentBoundingRectangle long(long;long);" & _
        "get_CurrentLabeledBy long(ptr);" & _
        "get_CurrentAriaRole long(wstr);" & _
        "get_CurrentAriaProperties long(wstr);" & _
        "get_CurrentIsDataValidForForm long(int);" & _
        "get_CurrentControllerFor long(ptr);" & _
        "get_CurrentDescribedBy long(ptr);" & _
        "get_CurrentFlowsTo long(ptr);" & _
        "get_CurrentProviderDescription long(wstr);" & _
        "get_CachedProcessId long(int);" & _
        "get_CachedControlType long(int);" & _
        "get_CachedLocalizedControlType long(wstr);" & _
        "get_CachedName long(wstr);" & _
        "get_CachedAcceleratorKey long(wstr);" & _
        "get_CachedAccessKey long(wstr);" & _
        "get_CachedHasKeyboardFocus long(int);" & _
        "get_CachedIsKeyboardFocusable long(int);" & _
        "get_CachedIsEnabled long(int);" & _
        "get_CachedAutomationId long(wstr);" & _
        "get_CachedClassName long(wstr);" & _
        "get_CachedHelpText long(wstr);" & _
        "get_CachedCulture long(int);" & _
        "get_CachedIsControlElement long(int);" & _
        "get_CachedIsContentElement long(int);" & _
        "get_CachedIsPassword long(int);" & _
        "get_CachedNativeWindowHandle long(none);" & _
        "get_CachedItemType long(wstr);" & _
        "get_CachedIsOffscreen long(int);" & _
        "get_CachedOrientation long(int);" & _
        "get_CachedFrameworkId long(wstr);" & _
        "get_CachedIsRequiredForForm long(int);" & _
        "get_CachedItemStatus long(wstr);" & _
        "get_CachedBoundingRectangle long(long;long);" & _
        "get_CachedLabeledBy long(ptr);" & _
        "get_CachedAriaRole long(wstr);" & _
        "get_CachedAriaProperties long(wstr);" & _
        "get_CachedIsDataValidForForm long(int);" & _
        "get_CachedControllerFor long(ptr);" & _
        "get_CachedDescribedBy long(ptr);" & _
        "get_CachedFlowsTo long(ptr);" & _
        "get_CachedProviderDescription long(wstr);" & _
        "GetClickablePoint long(long;long;int);"

; -------------------------------


; Error monitoring
Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")
Func _ErrFunc()
    ConsoleWrite("COM Error, ScriptLine(" & $oError.scriptline & ") : Number 0x" & Hex($oError.number, 8) & " - " & $oError.windescription & @CRLF)
EndFunc   ;==>_ErrFunc


_AutoItObject_StartUp()


Global $objUIAutomation = _AutoItObject_ObjCreate($sCLSID_CUIAutomation, $sIID_IUIAutomation, $tagIUIAutomation)

If IsObj($objUIAutomation) Then
    ConsoleWrite("At least it seems I have an object to start with" & @CRLF)
EndIf

ConsoleWrite("Do we get here?" & @CRLF)

Global $aCall = $objUIAutomation.GetRootElement(0)
Global $objRoot = _AutoItObject_WrapperCreate($aCall[1], $tagIUIAutomationElement)

If IsObj($objRoot) Then
    ConsoleWrite("At least it seems I have a second object to start with" & @CRLF)
EndIf

$aCall = $objRoot.get_CurrentClassName(0)
ConsoleWrite($aCall[1] & @CRLF)

$objRoot = 0
$objUIAutomation = 0

I haven't corrected all data types, only types of those methods that I have used. You do it for other for practice, if nothing.

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

thanx a zillion times this will help me definitely in the right direction.

Will correct the AIO generator to generate better matching interface (will post corrected code in that specific thread).

** One specific question for this UIAutomationCore.DLL.

to me it looks like a normal COM object DLL as I can use in VBA the construction NEW CUIAutomation and after that its a normal COM object.

Shouldn't it then be possible with AIO library to do this? (as there is no instantiation string in the registry)

;~ method 3
Global $objUIAutomation = _AutoItObject_ObjCreateEx("c:\windows\system32\uiautomationcore.dll", $sIID_IUIAutomation)

;~and after that use it as a "normal" COM object like below?

consolewrite($objUIAutomation.getRootElement.CurrentClassName)

Compared to VBA it seems so clumsy to get to the same result in AutoIT with all those interface definitions to make

Link to comment
Share on other sites

VBA will load typelib resource of that dll and construct the usable interface from it.

To make one thing clear, this could be done with AutoIt/AutoItObject too, but it will hit the wall on AutoIt's inability to handle byref situations properly. Any variable passed to any method by reference should be processed like that. Considering AutoIt is not enough advanced we have to use array to collect byref-ed. For example, that's why

c.GetRootElement.CurrentClassName
...is impossible with current AutoIt and that's why you are forced to use interface definitions even if typlib is available.

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

thx.

I am studying now on the bstr* types you referred to and I understand what you are saying but not fully sure if I read thru the sources of

WIN32API wtypes.h enum VARENUM and thru

AIO main.cpp the vartype function it seems that

VT_BSTR = 8 is translated to VT_UI4, // ulong in static VARTYPE VarTypeArray[]

How should I read those functions in AIO? I would assume that its translating the Win32 variant types to a matching AIO type.

Actually I see the function is doing that by going sequentially thru the list but only returns the first match.

At first sight I thought you just did a direct lookup based on the variant wtype.h values

As there are multiple matches in the array when will a second match be returned? Looking at the code I think its impossible.

Or are they there for future improvement(s)?

edit: Stupid of myself see the answer already. Reading the function in the incorrect order. Its to match the string back to the variant of wtypes instead of wtypes to AIO

Edited by junkew
Link to comment
Share on other sites

updated first post with better interface(s)

Later to convert this to AutoIT

IUIAutomationElement* GetTopLevelWindowByName(LPWSTR windowName)
{
    if (!windowName)
    {
        return NULL;
    }

    IUIAutomationElement* pRoot;
    IUIAutomationElement* pFound;
    VARIANT varProp;
    varProp.vt = VT_BSTR;
    varProp.bstrVal = SysAllocString(windowName);

    // Get the desktop element
    HRESULT hr = g_pAutomation->GetRootElement(&pRoot);

    // Get a top-level element by name, such as "Program Manager"
    if (pRoot)
    {
        IUIAutomationCondition* pCondition;
        g_pAutomation->CreatePropertyCondition(UIA_NamePropertyId,
            varProp, &pCondition);
        pRoot->FindFirst(TreeScope_Children, pCondition, &pFound);
        pRoot->Release();
        pCondition->Release();
    }

    VariantClear(&varProp);
    return pFound;
}
Link to comment
Share on other sites

still learning

made the full UIAutomation.AU3 file (still errors in it, but main stuff works)

#include <AutoItObject.au3>
#include "CUIAutomation.au3"

;~ Assume to have loaded the DLL first
Global Const $hUIAutomation = DllOpen("uiautomationcore.dll")

_AutoItObject_StartUp()

Local $pUIAutomationElement

Global $tagIUIAutomationCondition = $dtagIUnknown

Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")
Func _ErrFunc()
    ConsoleWrite("COM Error, ScriptLine(" & $oError.scriptline & ") : Number 0x" & Hex($oError.number, 8) & " - " & $oError.windescription & @CRLF)
EndFunc   ;==>_ErrFunc

_AutoItObject_StartUp()

Global $objUIAutomation = _AutoItObject_ObjCreate($sCLSID_CUIAutomation, $sIID_IUIAutomation, $tagIUIAutomation)

If IsObj($objUIAutomation) Then
    ConsoleWrite("At least it seems I have an object to start with" & @CRLF)
EndIf

ConsoleWrite("Do we get here?" & @CRLF)

Global $aCall = $objUIAutomation.GetRootElement(0)
Global $objRoot = _AutoItObject_WrapperCreate($aCall[1], $tagIUIAutomationElement)

If IsObj($objRoot) Then
    ConsoleWrite("At least it seems I have a second object to start with" & @CRLF)
EndIf

;~ $aCall = $objRoot.get_CurrentClassName(0)
$aCall = $objRoot.CurrentClassName(0)
ConsoleWrite($aCall[1] & @CRLF)

$objRoot = 0
$objUIAutomation = 0

edit 17-05-2011: Based on comments of Trancexx changed to use $dTagIUnknown

CUIAutomation.au3

Edited by junkew
Link to comment
Share on other sites

I have a question or two.

Why do you insist on defining $tagIUnknown? Besides the fact that $dtagIUnknown is defined inside AutoItObject.au3, your definition have completely wrong datatypes.

Another question is what's with _AutoItObject_CLSIDFromString() inside CUIAutomation.au3? Why do you need all that "active" constants/variables?

Regarding interfaces definitions, AutoItObject suggests so called, interface files. In AutoItObject package you have folder named Interfaces. Inside of it there are number of intfc files, definition files. That's how your CUIAutomation.au3 should look like.

edit: and parameter separator is ";", not comma.

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

thx for the direction. Changed the cuiautomation.au3 in previous post to be more in line with the intfc files.

As I am learning a lot of stuff at the same time

- TLBINFO object and your post(s) on doing it from the ground up

- As AIOWrapperGenerator gave some good direction

- Your TLB Viewer inspired me to combine the stuff

- With CUIAutomation we can do a lot of nice stuff (if events work you can build a macrorecorder easily in AutoIt)

- Constants are there as I generate everything and I am sure I need some of those constants later on like

-- PropertyId's

-- EventID's

This is one of the areas I am interested in to get working ($tagIUIAutomation )

"AddAutomationEventHandler hresult(int,ptr,long,ptr,ptr);" & _ ;AddAutomationEventHandler hresult([in] int ,[in] IUIAutomationElement *,[in] TreeScope ,[in] IUIAutomationCacheRequest *,[in] IUIAutomationEventHandler *)

"RemoveAutomationEventHandler hresult(int,ptr,ptr);" & _ ;RemoveAutomationEventHandler hresult([in] int ,[in] IUIAutomationElement *,[in] IUIAutomationEventHandler *)

"AddPropertyChangedEventHandlerNativeArray hresult(ptr,long,ptr,ptr,int,int);" & _ ;AddPropertyChangedEventHandlerNativeArray hresult([in] IUIAutomationElement *,[in] TreeScope ,[in] IUIAutomationCacheRequest *,[in] IUIAutomationpropertychangedEventHandler *,[in] int ,[in] int )

"AddPropertyChangedEventHandler hresult(ptr,long,ptr,ptr,ptr);" & _ ;AddPropertyChangedEventHandler hresult([in] IUIAutomationElement *,[in] TreeScope ,[in] IUIAutomationCacheRequest *,[in] IUIAutomationpropertychangedEventHandler *,[in] ne )

"RemovePropertyChangedEventHandler hresult(ptr,ptr);" & _ ;RemovePropertyChangedEventHandler hresult([in] IUIAutomationElement *,[in] IUIAutomationpropertychangedEventHandler *)

"AddStructureChangedEventHandler hresult(ptr,long,ptr,ptr);" & _ ;AddStructureChangedEventHandler hresult([in] IUIAutomationElement *,[in] TreeScope ,[in] IUIAutomationCacheRequest *,[in] IUIAutomationStructureChangedEventHandler *)

"RemoveStructureChangedEventHandler hresult(ptr,ptr);" & _ ;RemoveStructureChangedEventHandler hresult([in] IUIAutomationElement *,[in] IUIAutomationStructureChangedEventHandler *)

"AddFocusChangedEventHandler hresult(ptr,ptr);" & _ ;AddFocusChangedEventHandler hresult([in] IUIAutomationCacheRequest *,[in] IUIAutomationfocusChangedEventHandler *)

"RemoveFocusChangedEventHandler hresult(ptr);" & _ ;RemoveFocusChangedEventHandler hresult([in] IUIAutomationfocusChangedEventHandler *)

"RemoveAllEventHandlers hresult();" & _ ;RemoveAllEventHandlers hresult()

but for the moment I just start with trying to understand the "simple" stuff unfortunately this is already not working

COM Error, ScriptLine(39) : Number 0x80028027

#include <AutoItObject.au3>
#include "CUIAutomation.au3"

;~ Assume to have loaded the DLL first
Global Const $hUIAutomation = DllOpen("uiautomationcore.dll")

_AutoItObject_StartUp()

Local $pUIAutomationElement

Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")
Func _ErrFunc()
    ConsoleWrite("COM Error, ScriptLine(" & $oError.scriptline & ") : Number 0x" & Hex($oError.number, 8) & " - " & $oError.windescription & @CRLF)
EndFunc   ;==>_ErrFunc

_AutoItObject_StartUp()

;~ The main object with acces to the windows automation api 3.0
Global $objUIAutomation = _AutoItObject_ObjCreate($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation)

If IsObj($objUIAutomation) Then
    ConsoleWrite("At least it seems I have an object to start with" & @CRLF)
EndIf

;~ Try to get the desktop
Global $aCall
$aCall= $objUIAutomation.GetRootElement(0)
Global $oDesktop = _AutoItObject_WrapperCreate($aCall[1], $dtagIUIAutomationElement)
If IsObj($oDesktop) Then
    ConsoleWrite("At least it seems I have a second object to start with" & @CRLF)
EndIf

;~ $aCall = $oDesktop.get_CurrentClassName(0)
$aCall = $oDesktop.CurrentClassName(0)
ConsoleWrite("Yes, we did get the classname of the desktop" & $aCall[1] & @CRLF)

;~ Lets try to find 2 applications based on their name (Calc.Exe with title in dutch Rekenmachine)
;- TO DO ** Not working bound to invalid type***
$aCall= $objUIAutomation.CreatePropertyCondition($UIA_NamePropertyId, "Program Manager",0)
$oCondition1 = _AutoItObject_WrapperCreate($aCall[3],$dtagIUIAutomationCondition )
$aCall= $objUIAutomation.CreatePropertyCondition($UIA_NamePropertyId, "Rekenmachine",0)
$oCondition2 = _AutoItObject_WrapperCreate($aCall[3],$dtagIUIAutomationCondition )
$aCall= $objUIAutomation.CreateOrCondition($oCondition1, $oCondition2,0)
$oCondition3 = _AutoItObject_WrapperCreate($aCall[3],$dtagIUIAutomationCondition )

$aCall = $oDesktop.FindAll($TreeScope_Children, $oCondition3, 0)
$Childs=$aCall[3]   ;~ Can we receiven an array?

;~ TODO
;~ Some VB code to translate to AutoIt object
;~ ' Lets show all the items of the desktop with a treewalker
;~     Set oTW = oAutomation.ControlViewWalker
;~
;~     'Get the first child of the desktop
;~     Set oItem = oTW.GetFirstChildElement(oDesktop)
;~     While Not oItem Is Nothing
;~         Debug.Print i & oItem.CurrentName & oItem.CurrentClassName
;~         Set oItem = oTW.GetNextSiblingElement(oItem)
;~     Wend

;~ And close down the stuff
$oDesktop = 0
$objUIAutomation = 0

I have a question or two.

Why do you insist on defining $tagIUnknown? Besides the fact that $dtagIUnknown is defined inside AutoItObject.au3, your definition have completely wrong datatypes.

didn't know, copied from other post

Another question is what's with _AutoItObject_CLSIDFromString() inside CUIAutomation.au3? Why do you need all that "active" constants/variables?

still learning and as I generate stuff its no hurdle for me at the moment

Regarding interfaces definitions, AutoItObject suggests so called, interface files. In AutoItObject package you have folder named Interfaces. Inside of it there are number of intfc files, definition files. That's how your CUIAutomation.au3 should look like.

made it to be in line with the intfc files, updated file attached to one of the previous post(s)

edit: and parameter separator is ";", not comma.

regenerated with ";" Edited by junkew
Link to comment
Share on other sites

Probably should be something like this:

_AutoItObject_StartUp()

Local $pUIAutomationElement

Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")
Func _ErrFunc()
    ConsoleWrite("COM Error, ScriptLine(" & $oError.scriptline & ") : Number 0x" & Hex($oError.number, 8) & " - " & $oError.windescription & @CRLF)
EndFunc   ;==>_ErrFunc

_AutoItObject_StartUp()

;~ The main object with acces to the windows automation api 3.0
Global $objUIAutomation = _AutoItObject_ObjCreate($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation)

If IsObj($objUIAutomation) Then
    ConsoleWrite("At least it seems I have an object to start with" & @CRLF)
EndIf

;~ Try to get the desktop
Global $aCall
$aCall = $objUIAutomation.GetRootElement(0)
Global $oDesktop = _AutoItObject_WrapperCreate($aCall[1], $dtagIUIAutomationElement)
If IsObj($oDesktop) Then
    ConsoleWrite("At least it seems I have a second object to start with" & @CRLF)
EndIf

$aCall = $oDesktop.CurrentClassName(0)
ConsoleWrite("Yes, we did get the classname of the desktop: " & $aCall[1] & @CRLF)


;~ Lets try to find 2 applications based on their name (Calc.Exe with title in dutch Rekenmachine)

$aCall = $objUIAutomation.CreatePropertyCondition($UIA_NamePropertyId, "Program Manager", 0)
$oCondition1 = _AutoItObject_WrapperCreate($aCall[3], $dtagIUIAutomationCondition)

$aCall = $objUIAutomation.CreatePropertyCondition($UIA_NamePropertyId, "Rekenmachine", 0)
$oCondition2 = _AutoItObject_WrapperCreate($aCall[3], $dtagIUIAutomationCondition)

$aCall = $objUIAutomation.CreateOrCondition($oCondition1.__ptr__, $oCondition2.__ptr__, 0)
$oCondition3 = _AutoItObject_WrapperCreate($aCall[3], $dtagIUIAutomationCondition)


$aCall = $oDesktop.FindAll($TreeScope_Children, $oCondition3.__ptr__, 0)
$oAutomationElementArray = _AutoItObject_WrapperCreate($aCall[3], $dtagIUIAutomationElementArray)

$aCall = $oAutomationElementArray.Length(0)
$iLength = $aCall[1]

For $i = 0 To $iLength - 1; it's zero based
    $aCall = $oAutomationElementArray.GetElement($i, 0)
    $pElem = $aCall[2]
    $oElem = _AutoItObject_WrapperCreate($pElem, $dtagIUIAutomationElement)
    $aCall = $oElem.CurrentClassName(0)
    ConsoleWrite("Classname of the element No" & $i & ": " & $aCall[1] & @CRLF)
Next

$oElem = 0
$oAutomationElementArray = 0
$oCondition1 = 0
$oCondition2 = 0
$oCondition3 = 0
$oDesktop = 0
$objUIAutomation = 0
Exit

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

thx. It works correctly. Still a lot for me to study on but I think I am getting there slowly in understanding this stuff

__ptr__ some kind of special syntax to get a pointer?

Do you know of eventhandling stuff can work? http://msdn.microsoft.com/en-us/library/dd388739(v=vs.85).aspx

"AddFocusChangedEventHandler hresult(ptr,ptr);" & _         ;AddFocusChangedEventHandler hresult([in] IUIAutomationCacheRequest *,[in] IUIAutomationFocusChangedEventHandler *)
"RemoveFocusChangedEventHandler hresult(ptr);" & _          ;RemoveFocusChangedEventHandler hresult([in] IUIAutomationFocusChangedEventHandler *)
Link to comment
Share on other sites

Man, too bad I hadn't seen this thread before... I already have the entire UI Automation interface defined in my own code, but have yet to start experimenting with it. I also have worked on the IAccessible interface in the past, but found it to be lacking in certain areas (plus some programs implement it wrong)..

The IUIAutomation interface is definitely the future for program automation, and the developers of AutoIt would be wise to look into it if they still want AutoIt to be relevant today (its already failing to work for a number of programs).

Link to comment
Share on other sites

How can I handle an array thats returned or other complex type? (UIA_RuntimeIdPropertyId VT_I4|VT_ARRAY)

These are the descriptions for returned types http://msdn.microsoft.com/en-us/library/dd319579(v=vs.85).aspx

This works for a single property

$aCall= $oDesktop.GetCurrentPropertyValue($UIA_ProcessIdPropertyId,0)
$x=$aCall[2]
ConsoleWrite("Yes, we did get the $UIA_ProcessIdPropertyId: " & $x & @CRLF)

This works not (breaks the executable)

as it returns an array

$aCall= $oDesktop.GetCurrentPropertyValue($UIA_RuntimeIdPropertyId,0)
$x=_AutoItObject_VariantRead($aCall[2])
ConsoleWrite("No, we did notget the $UIA_ProcessIdPropertyId: " & $x[2] & @CRLF)

This works not as it returns an array

$aCall= $oDesktop.GetCurrentPropertyValue($UIA_RuntimeIdPropertyId,0)
$x=$aCall[2]
ConsoleWrite("No, we did notget the $UIA_ProcessIdPropertyId: " & $x[2] & @CRLF)

This works not as it returns an array

$aCall= $oDesktop.GetCurrentPropertyValue($UIA_RuntimeIdPropertyId,0)
ConsoleWrite("No, we did notget the $UIA_ProcessIdPropertyId: " & $acall[2][1] & @CRLF)
Link to comment
Share on other sites

There are arrays and there are arrays. AutoIt will accept only array of variants. You have array of int-s.

Workaround (for now) could be to write your own _AutoItObject_VariantRead function.

;...

$pVAR = Number(_AutoItObject_VariantSet(0, 0))

$aCall = $oDesktop.GetCurrentPropertyValue($UIA_RuntimeIdPropertyId, $pVAR)
$x = $aCall[2]

$aArray = _My_VariantRead($x)

_ArrayDisplay($aArray )


Func _My_VariantRead($pVariant)

    Local $var = DllStructCreate($__Au3Obj_tagVARIANT, $pVariant)
    Local $VT = DllStructGetData($var, "vt"), $type
    Switch $VT
        Case BitOR($__Au3Obj_VT_ARRAY, $__Au3Obj_VT_I4)
            Local $pSafeArray = DllStructGetData($var, "data")
            Local $iBound, $pData, $iLbound, $aOut[1]
            If 0 = __Au3Obj_SafeArrayGetUBound($pSafeArray, 1, $iBound) Then
                __Au3Obj_SafeArrayGetLBound($pSafeArray, 1, $iLbound)
                $iBound += 1 - $iLbound
                If 0 = __Au3Obj_SafeArrayAccessData($pSafeArray, $pData) Then
                    Local $tData = DllStructCreate("int[" & $iBound & "]", $pData)
                    ReDim $aOut[$iBound]
                    For $i = 1 To $iBound
                        $aOut[$i - 1] = DllStructGetData($tData, 1, $i)
                    Next
                    __Au3Obj_SafeArrayUnaccessData($pSafeArray)
                EndIf
            EndIf
            Return $aOut
        Case Else
            Return SetError(1, 0, '')
    EndSwitch

EndFunc

For that you have to change definition of GetCurrentPropertyValue method to

"GetCurrentPropertyValue hresult(int;ptr);"

It will be built-in in some new release of AutoItObject.

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

thx.

Probably also to add in new version of AutoIt: $__Au3Obj_VT_R8 as a double

needed for

UIA_ClickablePointPropertyId VT_R8|VT_ARRAY NULL Screen coordinates of any clickable point within the control.

Case BitOR($__Au3Obj_VT_ARRAY, $__Au3Obj_VT_R8)
            Local $pSafeArray = DllStructGetData($var, "data")
            Local $iBound, $pData, $iLbound, $aOut[1]
            If 0 = __Au3Obj_SafeArrayGetUBound($pSafeArray, 1, $iBound) Then
                __Au3Obj_SafeArrayGetLBound($pSafeArray, 1, $iLbound)
                $iBound += 1 - $iLbound
                If 0 = __Au3Obj_SafeArrayAccessData($pSafeArray, $pData) Then
                    Local $tData = DllStructCreate("double[" & $iBound & "]", $pData)
                    ReDim $aOut[$iBound]
                    For $i = 1 To $iBound
                        $aOut[$i - 1] = DllStructGetData($tData, 1, $i)
                    Next
                    __Au3Obj_SafeArrayUnaccessData($pSafeArray)
                EndIf
            EndIf
            Return $aOut
Link to comment
Share on other sites

thx.

Probably also to add in new version of AutoIt: $__Au3Obj_VT_R8 as a double

needed for

UIA_ClickablePointPropertyId VT_R8|VT_ARRAY NULL Screen coordinates of any clickable point within the control.

Case BitOR($__Au3Obj_VT_ARRAY, $__Au3Obj_VT_R8)
            Local $pSafeArray = DllStructGetData($var, "data")
            Local $iBound, $pData, $iLbound, $aOut[1]
            If 0 = __Au3Obj_SafeArrayGetUBound($pSafeArray, 1, $iBound) Then
                __Au3Obj_SafeArrayGetLBound($pSafeArray, 1, $iLbound)
                $iBound += 1 - $iLbound
                If 0 = __Au3Obj_SafeArrayAccessData($pSafeArray, $pData) Then
                    Local $tData = DllStructCreate("double[" & $iBound & "]", $pData)
                    ReDim $aOut[$iBound]
                    For $i = 1 To $iBound
                        $aOut[$i - 1] = DllStructGetData($tData, 1, $i)
                    Next
                    __Au3Obj_SafeArrayUnaccessData($pSafeArray)
                EndIf
            EndIf
            Return $aOut

All is added already. It's dealt with on lower level. Don't use that code and leave variant*.

I'll make new release of AutoItObject. You just continue working on your automation thing, I'll follow you.

edit: AutoItObject 1.2.8.2.

#include <Array.au3>

;...
$aCall = $oDesktop.GetCurrentPropertyValue($UIA_BoundingRectanglePropertyId, 0)
$aArray = $aCall[2]

ConsoleWrite(VarGetType($aArray) & "    " & $aArray & @CRLF)
_ArrayDisplay($aArray)
Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

just a new sample (works only with latest version of AutoIt Object library for returning arrays)

#include <AutoItObject.au3>
#include "CUIAutomation.au3"

;~ Assume to have loaded the DLL first
Global Const $hUIAutomation = DllOpen("uiautomationcore.dll")
Global $objUIAutomation  ;For creating the uiautomation instance
Global $oDesktop         ;Desktop will be frequently the starting point
Global $aCall            ;For handling the return values

_AutoItObject_StartUp()  ;Starting the autoit object library

Local $pUIAutomationElement

Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")
Func _ErrFunc()
    ConsoleWrite("COM Error, ScriptLine(" & $oError.scriptline & ") : Number 0x" & Hex($oError.number, 8) & " - " & $oError.windescription & @CRLF)
EndFunc   ;==>_ErrFunc

;~ The main object with acces to the windows automation api 3.0
$objUIAutomation = _AutoItObject_ObjCreate($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation)
If IsObj($objUIAutomation) Then
    ConsoleWrite("At least it seems I have an object to start with" & @CRLF)
EndIf

;~ Try to get the desktop
$aCall = $objUIAutomation.GetRootElement(0)
$oDesktop = _AutoItObject_WrapperCreate($aCall[1], $dtagIUIAutomationElement)
If IsObj($oDesktop) Then
    ConsoleWrite("At least it seems I have a second object to start with" & @CRLF)
EndIf

;~ Just show the classname as a starting sample
$aCall = $oDesktop.CurrentClassName(0)
ConsoleWrite("We did get for classname of the desktop: " & $aCall[1] & @CRLF)
$aCall = $oDesktop.CurrentClassName(0)

;~ Just try to show all the property values that could be applicable to this element
showAllPropertyValues($oDesktop)

;~ Some other samples
Sample1()
Sample2()

$oElem = 0
$oAutomationElementArray = 0
$oCondition1 = 0
$oCondition2 = 0
$oCondition3 = 0
$oDesktop = 0
$objUIAutomation = 0

Exit
;~ Lets try to find 2 applications based on their name (Calc.Exe with title in dutch Rekenmachine)
;~ Unfortunately uiautomation is not supporting regexpressions or wildcards to search
func Sample1()
    $aCall = $objUIAutomation.CreatePropertyCondition($UIA_NamePropertyId, "Program Manager", 0)
    $oCondition1 = _AutoItObject_WrapperCreate($aCall[3], $dtagIUIAutomationCondition)
;~  $aCall = $objUIAutomation.CreatePropertyCondition($UIA_NamePropertyId, "Rekenmachine", 0)
;~  $oCondition2 = _AutoItObject_WrapperCreate($aCall[3], $dtagIUIAutomationCondition)
    $aCall = $objUIAutomation.CreatePropertyCondition($UIA_ClassNamePropertyId, "SciCalc", 0)
    $oCondition2 = _AutoItObject_WrapperCreate($aCall[3], $dtagIUIAutomationCondition)

;~ Combine the 2 to be an or condition
    $aCall = $objUIAutomation.CreateOrCondition($oCondition1.__ptr__, $oCondition2.__ptr__, 0)
    $oCondition3 = _AutoItObject_WrapperCreate($aCall[3], $dtagIUIAutomationCondition)
    ;- Find them based on the or condition
    $aCall = $oDesktop.FindAll($TreeScope_Children, $oCondition3.__ptr__, 0)
    $oAutomationElementArray = _AutoItObject_WrapperCreate($aCall[3], $dtagIUIAutomationElementArray)

    $aCall = $oAutomationElementArray.Length(0)
    $iLength = $aCall[1]
    consolewrite("Showing 1 or 2 windows depending if (dutch) calculator is opened " & @CRLF)
    For $i = 0 To $iLength - 1; it's zero based
        $aCall = $oAutomationElementArray.GetElement($i, 0)
        $pElem = $aCall[2]
        $oElem = _AutoItObject_WrapperCreate($pElem, $dtagIUIAutomationElement)
        $aCall = $oElem.CurrentClassName(0)
        ConsoleWrite("Classname of the element No" & $i & ": " & $aCall[1] & @CRLF)
    Next
EndFunc

;~ Do something similar by showing all main windows with all their properties
func sample2()
    consolewrite("Showing all windows " & @CRLF)
    $aCall = $objUIAutomation.CreateTrueCondition(0)
    $oCondition1 = _AutoItObject_WrapperCreate($aCall[1], $dtagIUIAutomationCondition)
    $aCall = $oDesktop.FindAll($TreeScope_Children, $oCondition1.__ptr__, 0)
    $oAutomationElementArray = _AutoItObject_WrapperCreate($aCall[3], $dtagIUIAutomationElementArray)

    $aCall = $oAutomationElementArray.Length(0)
    $iLength = $aCall[1]

    For $i = 0 To $iLength - 1; it's zero based
        $pElem=0
        $oElem=0
        $aCall = $oAutomationElementArray.GetElement($i, 0)
        $pElem = $aCall[2]
        $oElem = _AutoItObject_WrapperCreate($pElem, $dtagIUIAutomationElement)
        $aCall = $oElem.CurrentClassName(0)
        ConsoleWrite("Classname of the element No " & $i & ": " & $aCall[1] & getPVal($oElem,$UIA_ClassNamePropertyId) & getPVal($oElem,$UIA_NamePropertyId)  & @CRLF)
        showAllPropertyValues($oElem)
    ;~  consolewrite($tVal)
    Next
EndFunc

;~ Just return a single property of if its an array string them together
func getPVal($obj, $id)
    $aCall= $obj.GetCurrentPropertyValue($Id,0)
    $tVal=$aCall[2]
    $tStr=""
    if isarray($tVal) Then
        for $i=0 to ubound($tval)-1
            $tStr=$tStr & $tVal[$i]
            if $i <> ubound($tVal)-1 Then
                $tStr=$tStr & ";"
            endif
        Next
;~      consolewrite($id & " is an array")
        return $tStr
    endIf
    return $tVal
EndFunc

;~ Just display all available properties for desktop/should work on all IUIAutomationElements depending on ControlTypePropertyID they work yes/no
;~ http://msdn.microsoft.com/en-us/library/dd319579(v=vs.85).aspx
func showAllPropertyValues($oUIElement)
    ConsoleWrite("  We did get for UIA_AcceleratorKeyPropertyId : " & getPVal($oUIElement, $UIA_AcceleratorKeyPropertyId) & @CRLF);Shortcut key for the element's default action.
    ConsoleWrite("  We did get for UIA_AccessKeyPropertyId : " & getPVal($oUIElement, $UIA_AccessKeyPropertyId) & @CRLF);Keys used to move focus to a control.
    ConsoleWrite("  We did get for UIA_AriaPropertiesPropertyId : " & getPVal($oUIElement, $UIA_AriaPropertiesPropertyId) & @CRLF);A collection of Accessible Rich Internet Application (ARIA) properties, each consisting of a name/value pair delimited by ‘-’ and ‘;’ (for example, ("checked=true;disabled=false").
    ConsoleWrite("  We did get for UIA_AriaRolePropertyId : " & getPVal($oUIElement, $UIA_AriaRolePropertyId) & @CRLF);ARIA role information.
    ConsoleWrite("  We did get for UIA_AutomationIdPropertyId : " & getPVal($oUIElement, $UIA_AutomationIdPropertyId) & @CRLF);UI Automation identifier.
    ConsoleWrite("  We did get for UIA_BoundingRectanglePropertyId : " & getPVal($oUIElement, $UIA_BoundingRectanglePropertyId) & @CRLF);Coordinates of the rectangle that completely encloses the element.
    ConsoleWrite("  We did get for UIA_ClassNamePropertyId : " & getPVal($oUIElement, $UIA_ClassNamePropertyId) & @CRLF);Class name of the element as assigned by the control developer.
    ConsoleWrite("  We did get for UIA_ClickablePointPropertyId : " & getPVal($oUIElement, $UIA_ClickablePointPropertyId) & @CRLF);Screen coordinates of any clickable point within the control.
    ConsoleWrite("  We did get for UIA_ControllerForPropertyId : " & getPVal($oUIElement, $UIA_ControllerForPropertyId) & @CRLF);Array of elements controlled by the automation element that supports this property.
    ConsoleWrite("  We did get for UIA_ControlTypePropertyId : " & getPVal($oUIElement, $UIA_ControlTypePropertyId) & @CRLF);Control Type of the element.
    ConsoleWrite("  We did get for UIA_CulturePropertyId : " & getPVal($oUIElement, $UIA_CulturePropertyId) & @CRLF);Locale identifier of the element.
    ConsoleWrite("  We did get for UIA_DescribedByPropertyId : " & getPVal($oUIElement, $UIA_DescribedByPropertyId) & @CRLF);Array of elements that provide more information about the element.
    ConsoleWrite("  We did get for UIA_DockDockPositionPropertyId : " & getPVal($oUIElement, $UIA_DockDockPositionPropertyId) & @CRLF);Docking position.
    ConsoleWrite("  We did get for UIA_ExpandCollapseExpandCollapseStatePropertyId : " & getPVal($oUIElement, $UIA_ExpandCollapseExpandCollapseStatePropertyId) & @CRLF);The expand/collapse state.
    ConsoleWrite("  We did get for UIA_FlowsToPropertyId : " & getPVal($oUIElement, $UIA_FlowsToPropertyId) & @CRLF);Array of elements that suggest the reading order after the corresponding element.
    ConsoleWrite("  We did get for UIA_FrameworkIdPropertyId : " & getPVal($oUIElement, $UIA_FrameworkIdPropertyId) & @CRLF);Underlying UI framework that the element is part of.
    ConsoleWrite("  We did get for UIA_GridColumnCountPropertyId : " & getPVal($oUIElement, $UIA_GridColumnCountPropertyId) & @CRLF);Number of columns.
    ConsoleWrite("  We did get for UIA_GridItemColumnPropertyId : " & getPVal($oUIElement, $UIA_GridItemColumnPropertyId) & @CRLF);Column the item is in.
    ConsoleWrite("  We did get for UIA_GridItemColumnSpanPropertyId : " & getPVal($oUIElement, $UIA_GridItemColumnSpanPropertyId) & @CRLF);number of columns that the item spans.
    ConsoleWrite("  We did get for UIA_GridItemContainingGridPropertyId : " & getPVal($oUIElement, $UIA_GridItemContainingGridPropertyId) & @CRLF);UI Automation provider that implements IGridProvider and represents the container of the cell or item.
    ConsoleWrite("  We did get for UIA_GridItemRowPropertyId : " & getPVal($oUIElement, $UIA_GridItemRowPropertyId) & @CRLF);Row the item is in.
    ConsoleWrite("  We did get for UIA_GridItemRowSpanPropertyId : " & getPVal($oUIElement, $UIA_GridItemRowSpanPropertyId) & @CRLF);Number of rows that the item spzns.
    ConsoleWrite("  We did get for UIA_GridRowCountPropertyId : " & getPVal($oUIElement, $UIA_GridRowCountPropertyId) & @CRLF);Number of rows.
    ConsoleWrite("  We did get for UIA_HasKeyboardFocusPropertyId : " & getPVal($oUIElement, $UIA_HasKeyboardFocusPropertyId) & @CRLF);Whether the element has the keyboard focus.
    ConsoleWrite("  We did get for UIA_HelpTextPropertyId : " & getPVal($oUIElement, $UIA_HelpTextPropertyId) & @CRLF);Additional information about how to use the element.
    ConsoleWrite("  We did get for UIA_IsContentElementPropertyId : " & getPVal($oUIElement, $UIA_IsContentElementPropertyId) & @CRLF);Whether the element appears in the content view of the automation element tree.
    ConsoleWrite("  We did get for UIA_IsControlElementPropertyId : " & getPVal($oUIElement, $UIA_IsControlElementPropertyId) & @CRLF);Whether the element appears in the control view of the automation element tree.
    ConsoleWrite("  We did get for UIA_IsDataValidForFormPropertyId : " & getPVal($oUIElement, $UIA_IsDataValidForFormPropertyId) & @CRLF);Whether the data in a form is valid.
    ConsoleWrite("  We did get for UIA_IsDockPatternAvailablePropertyId : " & getPVal($oUIElement, $UIA_IsDockPatternAvailablePropertyId) & @CRLF);Whether the Dock control pattern is available on the element.
    ConsoleWrite("  We did get for UIA_IsEnabledPropertyId : " & getPVal($oUIElement, $UIA_IsEnabledPropertyId) & @CRLF);Whether the control is enabled.
    ConsoleWrite("  We did get for UIA_IsExpandCollapsePatternAvailablePropertyId : " & getPVal($oUIElement, $UIA_IsExpandCollapsePatternAvailablePropertyId) & @CRLF);Whether the ExpandCollapse control pattern is available on the element.
    ConsoleWrite("  We did get for UIA_IsGridItemPatternAvailablePropertyId : " & getPVal($oUIElement, $UIA_IsGridItemPatternAvailablePropertyId) & @CRLF);Whether the GridItem control pattern is available on the element.
    ConsoleWrite("  We did get for UIA_IsGridPatternAvailablePropertyId : " & getPVal($oUIElement, $UIA_IsGridPatternAvailablePropertyId) & @CRLF);Whether the Grid control pattern is available on the element.
    ConsoleWrite("  We did get for UIA_IsInvokePatternAvailablePropertyId : " & getPVal($oUIElement, $UIA_IsInvokePatternAvailablePropertyId) & @CRLF);Whether the Invoke control pattern is available on the element.
    ConsoleWrite("  We did get for UIA_IsItemContainerPatternAvailablePropertyId : " & getPVal($oUIElement, $UIA_IsItemContainerPatternAvailablePropertyId) & @CRLF);Whether the ItemContainer control pattern is available on the element.
    ConsoleWrite("  We did get for UIA_IsKeyboardFocusablePropertyId : " & getPVal($oUIElement, $UIA_IsKeyboardFocusablePropertyId) & @CRLF);Whether the element can accept the keyboard focus.
    ConsoleWrite("  We did get for UIA_IsLegacyIAccessiblePatternAvailablePropertyId : " & getPVal($oUIElement, $UIA_IsLegacyIAccessiblePatternAvailablePropertyId) & @CRLF);Whether the LegacyIAccessible control pattern is available on the control.
    ConsoleWrite("  We did get for UIA_IsMultipleViewPatternAvailablePropertyId : " & getPVal($oUIElement, $UIA_IsMultipleViewPatternAvailablePropertyId) & @CRLF);Whether the pattern is available on the control.
    ConsoleWrite("  We did get for UIA_IsOffscreenPropertyId : " & getPVal($oUIElement, $UIA_IsOffscreenPropertyId) & @CRLF);Whether the element is scrolled or collapsed out of view.
    ConsoleWrite("  We did get for UIA_IsPasswordPropertyId : " & getPVal($oUIElement, $UIA_IsPasswordPropertyId) & @CRLF);Whether the element contains protected content or a password.
    ConsoleWrite("  We did get for UIA_IsRangeValuePatternAvailablePropertyId : " & getPVal($oUIElement, $UIA_IsRangeValuePatternAvailablePropertyId) & @CRLF);Whether the RangeValue pattern is available on the control.
    ConsoleWrite("  We did get for UIA_IsRequiredForFormPropertyId : " & getPVal($oUIElement, $UIA_IsRequiredForFormPropertyId) & @CRLF);Whether the element is a required field on a form.
    ConsoleWrite("  We did get for UIA_IsScrollItemPatternAvailablePropertyId : " & getPVal($oUIElement, $UIA_IsScrollItemPatternAvailablePropertyId) & @CRLF);Whether the ScrollItem control pattern is available on the element.
    ConsoleWrite("  We did get for UIA_IsScrollPatternAvailablePropertyId : " & getPVal($oUIElement, $UIA_IsScrollPatternAvailablePropertyId) & @CRLF);Whether the Scroll control pattern is available on the element.
    ConsoleWrite("  We did get for UIA_IsSelectionItemPatternAvailablePropertyId : " & getPVal($oUIElement, $UIA_IsSelectionItemPatternAvailablePropertyId) & @CRLF);Whether the SelectionItem control pattern is available on the element.
    ConsoleWrite("  We did get for UIA_IsSelectionPatternAvailablePropertyId : " & getPVal($oUIElement, $UIA_IsSelectionPatternAvailablePropertyId) & @CRLF);Whether the pattern is available on the element.
    ConsoleWrite("  We did get for UIA_IsSynchronizedInputPatternAvailablePropertyId : " & getPVal($oUIElement, $UIA_IsSynchronizedInputPatternAvailablePropertyId) & @CRLF);Whether the SynchronizedInput control pattern is available on the element.
    ConsoleWrite("  We did get for UIA_IsTableItemPatternAvailablePropertyId : " & getPVal($oUIElement, $UIA_IsTableItemPatternAvailablePropertyId) & @CRLF);Whether the TableItem control pattern is available on the element.
    ConsoleWrite("  We did get for UIA_IsTablePatternAvailablePropertyId : " & getPVal($oUIElement, $UIA_IsTablePatternAvailablePropertyId) & @CRLF);Whether the Table conntrol pattern is available on the element.
    ConsoleWrite("  We did get for UIA_IsTextPatternAvailablePropertyId : " & getPVal($oUIElement, $UIA_IsTextPatternAvailablePropertyId) & @CRLF);Whether the Text control pattern is available on the element.
    ConsoleWrite("  We did get for UIA_IsTogglePatternAvailablePropertyId : " & getPVal($oUIElement, $UIA_IsTogglePatternAvailablePropertyId) & @CRLF);Whether the Toggle control pattern is available on the element.
    ConsoleWrite("  We did get for UIA_IsTransformPatternAvailablePropertyId : " & getPVal($oUIElement, $UIA_IsTransformPatternAvailablePropertyId) & @CRLF);Whether the Transform control pattern is available on the element.
    ConsoleWrite("  We did get for UIA_IsValuePatternAvailablePropertyId : " & getPVal($oUIElement, $UIA_IsValuePatternAvailablePropertyId) & @CRLF);Whether the Value control pattern is available on the element.
    ConsoleWrite("  We did get for UIA_IsVirtualizedItemPatternAvailablePropertyId : " & getPVal($oUIElement, $UIA_IsVirtualizedItemPatternAvailablePropertyId) & @CRLF);Whether the VirtualizedItem control pattern is available on the element.
    ConsoleWrite("  We did get for UIA_IsWindowPatternAvailablePropertyId : " & getPVal($oUIElement, $UIA_IsWindowPatternAvailablePropertyId) & @CRLF);Whether the Window control pattern is available on the element.
    ConsoleWrite("  We did get for UIA_ItemStatusPropertyId : " & getPVal($oUIElement, $UIA_ItemStatusPropertyId) & @CRLF);Control-specific status.
    ConsoleWrite("  We did get for UIA_ItemTypePropertyId : " & getPVal($oUIElement, $UIA_ItemTypePropertyId) & @CRLF);Description of the item type, such as "Document File" or "Folder".
    ConsoleWrite("  We did get for UIA_LabeledByPropertyId : " & getPVal($oUIElement, $UIA_LabeledByPropertyId) & @CRLF);Element that contains the text label for this element.
    ConsoleWrite("  We did get for UIA_LegacyIAccessibleChildIdPropertyId : " & getPVal($oUIElement, $UIA_LegacyIAccessibleChildIdPropertyId) & @CRLF);MSAA child ID of the element.
    ConsoleWrite("  We did get for UIA_LegacyIAccessibleDefaultActionPropertyId : " & getPVal($oUIElement, $UIA_LegacyIAccessibleDefaultActionPropertyId) & @CRLF);MSAA default action.
    ConsoleWrite("  We did get for UIA_LegacyIAccessibleDescriptionPropertyId : " & getPVal($oUIElement, $UIA_LegacyIAccessibleDescriptionPropertyId) & @CRLF);MSAA description.
    ConsoleWrite("  We did get for UIA_LegacyIAccessibleHelpPropertyId : " & getPVal($oUIElement, $UIA_LegacyIAccessibleHelpPropertyId) & @CRLF);MSAA help string.
    ConsoleWrite("  We did get for UIA_LegacyIAccessibleKeyboardShortcutPropertyId : " & getPVal($oUIElement, $UIA_LegacyIAccessibleKeyboardShortcutPropertyId) & @CRLF);MSAA shortcut key.
    ConsoleWrite("  We did get for UIA_LegacyIAccessibleNamePropertyId : " & getPVal($oUIElement, $UIA_LegacyIAccessibleNamePropertyId) & @CRLF);MSAA name.
    ConsoleWrite("  We did get for UIA_LegacyIAccessibleRolePropertyId : " & getPVal($oUIElement, $UIA_LegacyIAccessibleRolePropertyId) & @CRLF);MSAA role.
    ConsoleWrite("  We did get for UIA_LegacyIAccessibleSelectionPropertyId : " & getPVal($oUIElement, $UIA_LegacyIAccessibleSelectionPropertyId) & @CRLF);MSAA selection.
    ConsoleWrite("  We did get for UIA_LegacyIAccessibleStatePropertyId : " & getPVal($oUIElement, $UIA_LegacyIAccessibleStatePropertyId) & @CRLF);MSAA state.
    ConsoleWrite("  We did get for UIA_LegacyIAccessibleValuePropertyId : " & getPVal($oUIElement, $UIA_LegacyIAccessibleValuePropertyId) & @CRLF);MSAA value.
    ConsoleWrite("  We did get for UIA_LocalizedControlTypePropertyId : " & getPVal($oUIElement, $UIA_LocalizedControlTypePropertyId) & @CRLF);Localized string describing the control type of element.
    ConsoleWrite("  We did get for UIA_MultipleViewCurrentViewPropertyId : " & getPVal($oUIElement, $UIA_MultipleViewCurrentViewPropertyId) & @CRLF);Current view state of the control.
    ConsoleWrite("  We did get for UIA_MultipleViewSupportedViewsPropertyId : " & getPVal($oUIElement, $UIA_MultipleViewSupportedViewsPropertyId) & @CRLF);Supported control-specific views.
    ConsoleWrite("  We did get for UIA_NamePropertyId : " & getPVal($oUIElement, $UIA_NamePropertyId) & @CRLF);Name of the control.
    ConsoleWrite("  We did get for UIA_NativeWindowHandlePropertyId : " & getPVal($oUIElement, $UIA_NativeWindowHandlePropertyId) & @CRLF);Underlying HWND of the element, if one exists.
    ConsoleWrite("  We did get for UIA_OrientationPropertyId : " & getPVal($oUIElement, $UIA_OrientationPropertyId) & @CRLF);Orientation of the element.
    ConsoleWrite("  We did get for UIA_ProcessIdPropertyId : " & getPVal($oUIElement, $UIA_ProcessIdPropertyId) & @CRLF);Identifier of the process that the element resides in.
    ConsoleWrite("  We did get for UIA_ProviderDescriptionPropertyId : " & getPVal($oUIElement, $UIA_ProviderDescriptionPropertyId) & @CRLF);Description of the UI Automation provider.
    ConsoleWrite("  We did get for UIA_RangeValueIsReadOnlyPropertyId : " & getPVal($oUIElement, $UIA_RangeValueIsReadOnlyPropertyId) & @CRLF);Whether the value is read-only.
    ConsoleWrite("  We did get for UIA_RangeValueLargeChangePropertyId : " & getPVal($oUIElement, $UIA_RangeValueLargeChangePropertyId) & @CRLF);Amount by which the value is adjusted by input such as PgDn.
    ConsoleWrite("  We did get for UIA_RangeValueMaximumPropertyId : " & getPVal($oUIElement, $UIA_RangeValueMaximumPropertyId) & @CRLF);Maximum value in the range.
    ConsoleWrite("  We did get for UIA_RangeValueMinimumPropertyId : " & getPVal($oUIElement, $UIA_RangeValueMinimumPropertyId) & @CRLF);Minimum value in the range.
    ConsoleWrite("  We did get for UIA_RangeValueSmallChangePropertyId : " & getPVal($oUIElement, $UIA_RangeValueSmallChangePropertyId) & @CRLF);Amount by which the value is adjusted by input such as an arrow key.
    ConsoleWrite("  We did get for UIA_RangeValueValuePropertyId : " & getPVal($oUIElement, $UIA_RangeValueValuePropertyId) & @CRLF);Current value.
    ConsoleWrite("  We did get for UIA_RuntimeIdPropertyId : " & getPVal($oUIElement, $UIA_RuntimeIdPropertyId) & @CRLF);Run time identifier of the element.
    ConsoleWrite("  We did get for UIA_ScrollHorizontallyScrollablePropertyId : " & getPVal($oUIElement, $UIA_ScrollHorizontallyScrollablePropertyId) & @CRLF);Whether the control can be scrolled horizontally.
    ConsoleWrite("  We did get for UIA_ScrollHorizontalScrollPercentPropertyId : " & getPVal($oUIElement, $UIA_ScrollHorizontalScrollPercentPropertyId) & @CRLF);How far the element is currently scrolled.
    ConsoleWrite("  We did get for UIA_ScrollHorizontalViewSizePropertyId : " & getPVal($oUIElement, $UIA_ScrollHorizontalViewSizePropertyId) & @CRLF);The viewable width of the control.
    ConsoleWrite("  We did get for UIA_ScrollVerticallyScrollablePropertyId : " & getPVal($oUIElement, $UIA_ScrollVerticallyScrollablePropertyId) & @CRLF);Whether the control can be scrolled vertically.
    ConsoleWrite("  We did get for UIA_ScrollVerticalScrollPercentPropertyId : " & getPVal($oUIElement, $UIA_ScrollVerticalScrollPercentPropertyId) & @CRLF);How far the element is currently scrolled.
    ConsoleWrite("  We did get for UIA_ScrollVerticalViewSizePropertyId : " & getPVal($oUIElement, $UIA_ScrollVerticalViewSizePropertyId) & @CRLF);The viewable height of the control.
    ConsoleWrite("  We did get for UIA_SelectionCanSelectMultiplePropertyId : " & getPVal($oUIElement, $UIA_SelectionCanSelectMultiplePropertyId) & @CRLF);Whether multiple items can be in the selection.
    ConsoleWrite("  We did get for UIA_SelectionIsSelectionRequiredPropertyId : " & getPVal($oUIElement, $UIA_SelectionIsSelectionRequiredPropertyId) & @CRLF);Whether at least one item must be in the selection at all times.
    ConsoleWrite("  We did get for UIA_SelectionSelectionPropertyId : " & getPVal($oUIElement, $UIA_SelectionSelectionPropertyId) & @CRLF);The items in the selection.
    ConsoleWrite("  We did get for UIA_SelectionItemIsSelectedPropertyId : " & getPVal($oUIElement, $UIA_SelectionItemIsSelectedPropertyId) & @CRLF);Whether the item can be selected.
    ConsoleWrite("  We did get for UIA_SelectionItemSelectionContainerPropertyId : " & getPVal($oUIElement, $UIA_SelectionItemSelectionContainerPropertyId) & @CRLF);The control that contains the item.
    ConsoleWrite("  We did get for UIA_TableColumnHeadersPropertyId : " & getPVal($oUIElement, $UIA_TableColumnHeadersPropertyId) & @CRLF);Collection of column header providers.
    ConsoleWrite("  We did get for UIA_TableItemColumnHeaderItemsPropertyId : " & getPVal($oUIElement, $UIA_TableItemColumnHeaderItemsPropertyId) & @CRLF);Column headers.
    ConsoleWrite("  We did get for UIA_TableRowHeadersPropertyId : " & getPVal($oUIElement, $UIA_TableRowHeadersPropertyId) & @CRLF);Collection of row header providers.
    ConsoleWrite("  We did get for UIA_TableRowOrColumnMajorPropertyId : " & getPVal($oUIElement, $UIA_TableRowOrColumnMajorPropertyId) & @CRLF);Whether the table is primarily organized by row or column.
    ConsoleWrite("  We did get for UIA_TableItemRowHeaderItemsPropertyId : " & getPVal($oUIElement, $UIA_TableItemRowHeaderItemsPropertyId) & @CRLF);Row headers.
    ConsoleWrite("  We did get for UIA_ToggleToggleStatePropertyId : " & getPVal($oUIElement, $UIA_ToggleToggleStatePropertyId) & @CRLF);The toggle state of the control.
    ConsoleWrite("  We did get for UIA_TransformCanMovePropertyId : " & getPVal($oUIElement, $UIA_TransformCanMovePropertyId) & @CRLF);Whether the element can be moved.
    ConsoleWrite("  We did get for UIA_TransformCanResizePropertyId : " & getPVal($oUIElement, $UIA_TransformCanResizePropertyId) & @CRLF);Whether the element can be resized.
    ConsoleWrite("  We did get for UIA_TransformCanRotatePropertyId : " & getPVal($oUIElement, $UIA_TransformCanRotatePropertyId) & @CRLF);Whether the element can be rotated.
    ConsoleWrite("  We did get for UIA_ValueIsReadOnlyPropertyId : " & getPVal($oUIElement, $UIA_ValueIsReadOnlyPropertyId) & @CRLF);Whether the value is read-only.
    ConsoleWrite("  We did get for UIA_ValueValuePropertyId : " & getPVal($oUIElement, $UIA_ValueValuePropertyId) & @CRLF);Current value.
    ConsoleWrite("  We did get for UIA_WindowCanMaximizePropertyId : " & getPVal($oUIElement, $UIA_WindowCanMaximizePropertyId) & @CRLF);Whether the window can be maximized.
    ConsoleWrite("  We did get for UIA_WindowCanMinimizePropertyId : " & getPVal($oUIElement, $UIA_WindowCanMinimizePropertyId) & @CRLF);Whether the window can be minimized.
    ConsoleWrite("  We did get for UIA_WindowIsModalPropertyId : " & getPVal($oUIElement, $UIA_WindowIsModalPropertyId) & @CRLF);Whether the window is modal.
    ConsoleWrite("  We did get for UIA_WindowIsTopmostPropertyId : " & getPVal($oUIElement, $UIA_WindowIsTopmostPropertyId) & @CRLF);Whether the window is on top of other windows.
    ConsoleWrite("  We did get for UIA_WindowWindowInteractionStatePropertyId : " & getPVal($oUIElement, $UIA_WindowWindowInteractionStatePropertyId) & @CRLF);Whether the window can receive input.
    ConsoleWrite("  We did get for UIA_WindowWindowVisualStatePropertyId : " & getPVal($oUIElement, $UIA_WindowWindowVisualStatePropertyId) & @CRLF);Whether the window is maximized, minimized, or restored (normal).
endFunc

edit: 21 may 2011 updated the sample and cleaned it up

Edited by junkew
Link to comment
Share on other sites

Any help appreciated on catching the UIAutomation events in AutoIT object code?

1. HandleFocusChangedEvent I should implement myself somehow with func _HandleFocusChangedEvent($oElem)

Do I have to convert $Element back to an interface/object

2. IUIAutomationfocusChangedEventHandler I should create myself

How can I implement/add the method HandleFocusChangedEvente so it can be called from ui automation (callbackfunction logic)

3. Register the event with something like

$objUIAutomation.AddFocusChangedEventHandler(0,$oFocusHandler) ;- Use pointer?

#include <AutoItObject.au3>
#include "CUIAutomation.au3"

HotKeySet("{ESC}", "Terminate")

;~ Assume to have loaded the DLL first
Global Const $hUIAutomation = DllOpen("uiautomationcore.dll")
Global $objUIAutomation  ;For creating the uiautomation instance
Global $oDesktop         ;Desktop will be frequently the starting point
Global $aCall            ;For handling the return values

_AutoItObject_StartUp()  ;Starting the autoit object library

Local $pUIAutomationElement

Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")
Func _ErrFunc()
    ConsoleWrite("COM Error, ScriptLine(" & $oError.scriptline & ") : Number 0x" & Hex($oError.number, 8) & " - " & $oError.windescription & @CRLF)
EndFunc   ;==>_ErrFunc

;~ The main object with acces to the windows automation api 3.0
$objUIAutomation = _AutoItObject_ObjCreate($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation)
If IsObj($objUIAutomation) Then
    ConsoleWrite("At least it seems I have an object to start with" & @CRLF)
EndIf

;~ HRESULT AddFocusHandler(IUIAutomation* pAutomation)
;~ {
;~     // CFocusHandler is a class that implements IUIAutomationFocusChangedEventHandler.
;~     CFocusHandler* pFocusHandler = new CFocusHandler();
;~     if (!pFocusHandler)
;~     {
;~         return E_OUTOFMEMORY;
;~     }
;~     IUIAutomationFocusChangedEventHandler* pHandler;
;~     pFocusHandler->QueryInterface(IID_IUIAutomationFocusChangedEventHandler, (void**)&pHandler);
;~     HRESULT hr = pAutomation->AddFocusChangedEventHandler(NULL, pHandler);
;~     pFocusHandler->Release();
;~     return hr;
;~ }
;~ HRESULT HandleFocusChangedEvent(
;~   [in]  IUIAutomationElement *sender
;~ );

;~*** Approach 1 not working ***
;~ Func _oFocusHandler()
;~     Local $oClass = _AutoItObject_Class()
;~     With $oClass
;~         .AddMethod("HandleFocusChangedEvent", "_HandleFocusChangedEvent")
;~     EndWith
;~     Return $oClass.Object
;~ EndFunc

;~ Global $oFocusHandler = _oFocusHandler()                              ;This is the object
;~ Global $pFocusHandler = _AutoItObject_IDispatchToPtr($oFocusHandler)  ;This is the pointer to the object

;~ $objUIAutomation.AddFocusChangedEventHandler(0,$oFocusHandler.__ptr__)

;~*** Approach 2 not working ***
;~ Create object
;~ Global $oIUIAutomationFocusChangedEventHandler = _AutoItObject_ObjCreate($sCLSID_IUIAutomationFocusChangedEventHandler, $sIID_IUIAutomationFocusChangedEventHandler)
;~ If IsObj($oIUIAutomationFocusChangedEventHandler) Then
;~     ConsoleWrite("At least it seems I have an handler object to start with" & @CRLF)
;~ EndIf
;~ _AutoItObject_WrapperAddMethod($oIUIAutomationFocusChangedEventHandler, "hresult", "HandleFocusChangedEvent", "ptr", 1) ; function No3 in vtable of this object is 

While 1
    Sleep(100)
WEnd

Func Terminate()
    Exit 0
EndFunc

func _HandleFocusChangedEvent($oElem)
    $aCall = $oElem.CurrentClassName(0)
    consolewrite("Somebody is changing the focus " & $aCall[1])
EndFunc
Link to comment
Share on other sites

That's done like this with AutoItObject:

#include <WinAPI.au3>
#include <AutoItObject.au3>
#include "CUIAutomation.au3"

HotKeySet("{ESC}", "Terminate")

_AutoItObject_StartUp() ;Starting the autoit object library

Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")
Func _ErrFunc()
    ConsoleWrite("COM Error, ScriptLine(" & $oError.scriptline & ") : Number 0x" & Hex($oError.number, 8) & " - " & $oError.windescription & @CRLF)
EndFunc   ;==>_ErrFunc

;~ The main object with acces to the windows automation api 3.0
Global $objUIAutomation = _AutoItObject_ObjCreate($sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation)

;~ Focus Changed Handler
Global $oFCEHandler = _AutoItObject_ObjectFromDtag("_MyHandler_", $dtagIUIAutomationFocusChangedEventHandler)

$objUIAutomation.AddFocusChangedEventHandler(0, $oFCEHandler.__ptr__)


While 1
    Sleep(100)
WEnd

Func Terminate()
    $objUIAutomation.RemoveAllEventHandlers()
    $objUIAutomation = 0
    $oFCEHandler = 0
    Exit 0
EndFunc   ;==>Terminate


; Handler methods. "_MyHandler_" is the specified prefix:
Func _MyHandler_QueryInterface($pSelf, $pRIID, $pObj)
    ConsoleWrite("_MyHandler_QueryInterface called " & $pSelf & "    " & _WinAPI_StringFromGUID($pRIID) & "    ")
    Local $tStruct = DllStructCreate("ptr", $pObj)
    Switch _WinAPI_StringFromGUID($pRIID)
        Case $sIID_IUnknown
            ConsoleWrite("IUnknown" & @CRLF)
        Case $sIID_IUIAutomationFocusChangedEventHandler
            ConsoleWrite("IUIAutomationFocusChangedEventHandler" & @CRLF)
        Case Else
            ConsoleWrite(@CRLF)
            Return 0x80004002 ; E_NOINTERFACE
    EndSwitch
    DllStructSetData($tStruct, 1, $pSelf)
    Return 0 ; S_OK
EndFunc   ;==>_MyHandler_QueryInterface
Func _MyHandler_AddRef($pSelf)
    #forceref $pSelf
    ConsoleWrite("_MyHandler_AddRef called" & @CRLF)
    Return 0 ; S_OK
EndFunc   ;==>_MyHandler_AddRef
Func _MyHandler_Release($pSelf)
    #forceref $pSelf
    ConsoleWrite("_MyHandler_Release called" & @CRLF)
    Return 0 ; S_OK
EndFunc   ;==>_MyHandler_Release
Func _MyHandler_HandleFocusChangedEvent($pSelf, $pElem)
    #forceref $pSelf
    ConsoleWrite("! _MyHandler_HandleFocusChangedEvent called: $pElem = " & $pElem & @CRLF)
    If $pElem Then
        Local $oElem = _AutoItObject_WrapperCreate($pElem, $dtagIUIAutomationElement)
        $oElem.AddRef()
        Local $aCall = $oElem.CurrentClassName(0)
        ConsoleWrite(">>>     Somebody is changing the focus to: " & $aCall[1] & @CRLF)
    EndIf
    Return 0 ; S_OK
EndFunc   ;==>_MyHandler_HandleFocusChangedEvent

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...