Jump to content
junkew

IUIAutomation MS framework automate chrome, FF, IE, ....

Recommended Posts

Excellent trancexx. Thank you very much. If you knew how much time ...

One minor issue with your string expression. If a method contains the word "object" as a part of the name this word will be replaced with "idispatch". This is for example the case for the BrowseObject method of IShellBrowser:

Global Const $S_OK = 0x00000000
Global Const $E_NOTIMPL = 0x80004001
Global Const $E_NOINTERFACE = 0x80004002

Global Const $sIID_IShellBrowser = "{000214E2-0000-0000-C000-000000000046}"
Global Const $dtag_IShellBrowser = _
  "GetWindow hresult(hwnd*);" & _               ; IOleWindow:    ; Gets a window handle.
  "ContextSensitiveHelp hresult(int);" & _                       ; Controls enabling of context-sensitive help.
  "InsertMenusSB hresult(handle;ptr);" & _      ; IShellBrowser: ; Allows the container to insert its menu groups into the composite menu that is displayed when an extended namespace is being viewed or used.
  "SetMenuSB hresult(handle;handle;hwnd);" & _                   ; Installs the composite menu in the view window.
  "RemoveMenusSB hresult(handle);" & _                           ; Permits the container to remove any of its menu elements from the in-place composite menu and to free all associated resources.
  "SetStatusTextSB hresult(ptr);" & _                            ; Sets and displays status text about the in-place object in the container's frame-window status bar.
  "EnableModelessSB hresult(int);" & _                           ; Tells Windows Explorer to enable or disable its modeless dialog boxes.
  "TranslateAcceleratorSB hresult(ptr;word);" & _                ; Translates accelerator keystrokes intended for the browser's frame while the view is active.
  "BrowseObject hresult(ptr;uint);" & _                          ; Informs Microsoft Windows Explorer to browse to another folder.
  "GetViewStateStream hresult(dword;long_ptr*);" & _             ; Gets an IStream interface that can be used for storage of view-specific state information.
  "GetControlWindow hresult(uint;hwnd);" & _                     ; Gets the window handle to a browser control.
  "SendControlMsg hresult(uint;uint;wparam;lparam;lresult);" & _ ; Sends control messages to either the toolbar or the status bar in a Windows Explorer window.
  "QueryActiveShellView hresult(ptr*);" & _                      ; Retrieves the currently active (displayed) Shell view object.
  "OnViewWindowActive hresult(ptr);" & _                         ; Called by the Shell view when the view window or one of its child windows gets the focus or becomes active.
  "SetToolbarItems hresult(ptr;uint;uint);"                      ; Adds toolbar items to Windows Explorer's toolbar.

Global $tIShellBrowser, $oIShellBrowser, $dwRef = 0

MainFunc()

Func MainFunc()

  $oIShellBrowser = ObjectFromTag( "oIShellBrowser_", $dtag_IShellBrowser, $tIShellBrowser, True )
  If Not IsObj( $oIShellBrowser ) Then Return

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

  While Sleep(100)
  WEnd

EndFunc

Func Quit()
  $oIShellBrowser = 0
  DeleteObjectFromTag( $tIShellBrowser )
  Exit
EndFunc



Func oIShellBrowser_QueryInterface( $pSelf, $pRIID, $pObj )
  ConsoleWrite( "oIShellBrowser_QueryInterface" & @CRLF )
  Return $E_NOINTERFACE
EndFunc

Func oIShellBrowser_AddRef( $pSelf )
  ConsoleWrite( "oIShellBrowser_AddRef" & @CRLF )
  $dwRef += 1
  Return $dwRef
EndFunc

Func oIShellBrowser_Release( $pSelf )
  ConsoleWrite( "oIShellBrowser_Release" & @CRLF )
  $dwRef -= 1
  Return $dwRef
EndFunc

Func oIShellBrowser_GetWindow( $pSelf, $phwnd )
  ConsoleWrite( "oIShellBrowser_GetWindow" & @CRLF )
  Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_ContextSensitiveHelp( $pSelf, $fEnterMode )
  ConsoleWrite( "oIShellBrowser_ContextSensitiveHelp" & @CRLF )
  Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_InsertMenusSB( $pSelf, $hmenuShared, $lpMenuWidths )
  ConsoleWrite( "oIShellBrowser_InsertMenusSB" & @CRLF )
  Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_SetMenuSB( $pSelf, $hmenuShared, $holemenuRes, $hwndActiveObject )
  ConsoleWrite( "oIShellBrowser_SetMenuSB" & @CRLF )
  Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_RemoveMenusSB( $pSelf, $hmenuShared )
  ConsoleWrite( "oIShellBrowser_RemoveMenusSB" & @CRLF )
  Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_SetStatusTextSB( $pSelf, $lpszStatusText )
  ConsoleWrite( "oIShellBrowser_SetStatusTextSB" & @CRLF )
  Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_EnableModelessSB( $pSelf, $fEnable )
  ConsoleWrite( "oIShellBrowser_EnableModelessSB" & @CRLF )
  Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_TranslateAcceleratorSB( $pSelf, $lpmsg, $wID )
  ConsoleWrite( "oIShellBrowser_TranslateAcceleratorSB" & @CRLF )
  Return $E_NOTIMPL
EndFunc

;Func oIShellBrowser_Browseidispatch( $pSelf, $pidl, $wFlags )
Func oIShellBrowser_BrowseObject( $pSelf, $pidl, $wFlags )
  ConsoleWrite( "oIShellBrowser_BrowseObject" & @CRLF )
  Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_GetViewStateStream( $pSelf, $grfMode, $ppStrm )
  ConsoleWrite( "oIShellBrowser_GetViewStateStream" & @CRLF )
  Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_GetControlWindow( $pSelf, $id, $lphwnd )
  ConsoleWrite( "oIShellBrowser_GetControlWindow" & @CRLF )
  Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_SendControlMsg( $pSelf, $id, $uMsg, $wParam, $lParam, $pret )
  ConsoleWrite( "oIShellBrowser_SendControlMsg" & @CRLF )
  Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_QueryActiveShellView( $pSelf, $ppshv )
  ConsoleWrite( "oIShellBrowser_QueryActiveShellView" & @CRLF )
  Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_OnViewWindowActive( $pSelf, $ppshv )
  ConsoleWrite( "oIShellBrowser_OnViewWindowActive" & @CRLF )
  Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_SetToolbarItems( $pSelf, $lpButtons, $nButtons, $uFlags )
  ConsoleWrite( "oIShellBrowser_SetToolbarItems" & @CRLF )
  Return $E_NOTIMPL
EndFunc



Func ObjectFromTag($sFunctionPrefix, $tagInterface, ByRef $tInterface, $fPrint = False, $bIsUnknown = Default, $sIID = "{00000000-0000-0000-C000-000000000046}") ; last param is IID_IUnknown by default
    If $bIsUnknown = Default Then $bIsUnknown = True
    Local $sInterface = $tagInterface ; copy interface description
    Local $tagIUnknown = "QueryInterface hresult(ptr;ptr*);" & _
            "AddRef dword();" & _
            "Release dword();"
    ; Adding IUnknown methods
    If $bIsUnknown Then $tagInterface = $tagIUnknown & $tagInterface
    ; Below line is really simple even though it looks super complex. It's just written weird to fit in one line, not to steal your attention
    Local $aMethods = StringSplit(StringReplace(StringReplace(StringReplace(StringReplace(StringTrimRight(StringReplace(StringRegExpReplace(StringRegExpReplace($tagInterface, "\w+\*", "ptr"), "\h*(\w+)\h*(\w+\*?)\h*(\((.*?)\))\h*(;|;*\z)", "$1\|$2;$4" & @LF), ";" & @LF, @LF), 1), "object", "idispatch"), "hresult", "long"), "bstr", "ptr"), "variant", "ptr"), @LF, 3)
    Local $iUbound = UBound($aMethods)
    Local $sMethod, $aSplit, $sNamePart, $aTagPart, $sTagPart, $sRet, $sParams, $hCallback
    ; Allocation
    $tInterface = DllStructCreate("int RefCount;int Size;ptr Object;ptr Methods[" & $iUbound & "];int_ptr Callbacks[" & $iUbound & "];ulong_ptr Slots[16]") ; 16 pointer sized elements more to create space for possible private props
    If @error Then Return SetError(1, 0, 0)
    For $i = 0 To $iUbound - 1
        $aSplit = StringSplit($aMethods[$i], "|", 2)
        If UBound($aSplit) <> 2 Then ReDim $aSplit[2]
        $sNamePart = $aSplit[0]
        $sTagPart = $aSplit[1]
        $sMethod = $sFunctionPrefix & $sNamePart
        If $fPrint Then
            Local $iPar = StringInStr( $sTagPart, ";", 2 ), $t
            If $iPar Then
                $t = "Ret: " & StringLeft( $sTagPart, $iPar - 1 ) & "  " & _
                     "Par: " & StringRight( $sTagPart, StringLen( $sTagPart ) - $iPar )
            Else
                $t = "Ret: " & $sTagPart
            EndIf
            Local $s = "Func " & $sMethod & _
                "( $pSelf ) ; " & $t & @CRLF & _
                "EndFunc" & @CRLF
            ConsoleWrite( $s )
        EndIf
        $aTagPart = StringSplit($sTagPart, ";", 2)
        $sRet = $aTagPart[0]
        $sParams = StringReplace($sTagPart, $sRet, "", 1)
        $sParams = "ptr" & $sParams
        $hCallback = DllCallbackRegister($sMethod, $sRet, $sParams)
        ConsoleWrite(@error & @CRLF & @CRLF)
        DllStructSetData($tInterface, "Methods", DllCallbackGetPtr($hCallback), $i + 1) ; save callback pointer
        DllStructSetData($tInterface, "Callbacks", $hCallback, $i + 1) ; save callback handle
    Next
    DllStructSetData($tInterface, "RefCount", 1) ; initial ref count is 1
    DllStructSetData($tInterface, "Size", $iUbound) ; number of interface methods
    DllStructSetData($tInterface, "Object", DllStructGetPtr($tInterface, "Methods")) ; Interface method pointers
    Return ObjCreateInterface(DllStructGetPtr($tInterface, "Object"), $sIID, $sInterface, $bIsUnknown) ; pointer that's wrapped into object
EndFunc

Func DeleteObjectFromTag(ByRef $tInterface)
    For $i = 1 To DllStructGetData($tInterface, "Size")
        DllCallbackFree(DllStructGetData($tInterface, "Callbacks", $i))
    Next
    $tInterface = 0
EndFunc

You should definitely create a new thread and add this function.

And one question. The function I was using was copied from _AutoItObject_ObjectFromDtag. This probably means that _AutoItObject_ObjectFromDtag also has this issue (not working properly in all cases as in my example)?

junkew, the problem with missing "get_" and "put_" strings is also the case for IAccessible (accName, accValue) and IUIAutomationProxyFactoryEntry (ClassName, ImageName, AllowSubstringMatch, CanCheckBaseClass, NeedsAdviseEvents).

(AddPropertyChangedEventHandlerNativeArray is using an ordinary array (as the name says).)

Edited by LarsJ

Share this post


Link to post
Share on other sites

Ok, I got it. You don't need special reference counter variable because you can use object's space to sore it:

Global Const $S_OK = 0x00000000
Global Const $E_NOTIMPL = 0x80004001
Global Const $E_NOINTERFACE = 0x80004002
Global Const $sIID_IUnknown = "{00000000-0000-0000-C000-000000000046}"

Global Const $sIID_IShellBrowser = "{000214E2-0000-0000-C000-000000000046}"
Global Const $dtag_IShellBrowser = _
        "GetWindow hresult(hwnd*);" & _               ; IOleWindow:    ; Gets a window handle.
        "ContextSensitiveHelp hresult(int);" & _                       ; Controls enabling of context-sensitive help.
        "InsertMenusSB hresult(handle;ptr);" & _      ; IShellBrowser: ; Allows the container to insert its menu groups into the composite menu that is displayed when an extended namespace is being viewed or used.
        "SetMenuSB hresult(handle;handle;hwnd);" & _                   ; Installs the composite menu in the view window.
        "RemoveMenusSB hresult(handle);" & _                           ; Permits the container to remove any of its menu elements from the in-place composite menu and to free all associated resources.
        "SetStatusTextSB hresult(ptr);" & _                            ; Sets and displays status text about the in-place object in the container's frame-window status bar.
        "EnableModelessSB hresult(int);" & _                           ; Tells Windows Explorer to enable or disable its modeless dialog boxes.
        "TranslateAcceleratorSB hresult(ptr;word);" & _                ; Translates accelerator keystrokes intended for the browser's frame while the view is active.
        "BrowseObject hresult(ptr;uint);" & _                          ; Informs Microsoft Windows Explorer to browse to another folder.
        "GetViewStateStream hresult(dword;long_ptr*);" & _             ; Gets an IStream interface that can be used for storage of view-specific state information.
        "GetControlWindow hresult(uint;hwnd);" & _                     ; Gets the window handle to a browser control.
        "SendControlMsg hresult(uint;uint;wparam;lparam;lresult);" & _ ; Sends control messages to either the toolbar or the status bar in a Windows Explorer window.
        "QueryActiveShellView hresult(ptr*);" & _                      ; Retrieves the currently active (displayed) Shell view object.
        "OnViewWindowActive hresult(ptr);" & _                         ; Called by the Shell view when the view window or one of its child windows gets the focus or becomes active.
        "SetToolbarItems hresult(ptr;uint;uint);"                      ; Adds toolbar items to Windows Explorer's toolbar.

Global $tIShellBrowser, $oIShellBrowser

MainFunc()

Func MainFunc()

    $oIShellBrowser = ObjectFromTag("oIShellBrowser_", $dtag_IShellBrowser, $tIShellBrowser, Default, $sIID_IShellBrowser)
    If Not IsObj($oIShellBrowser) Then Return

    ; Try calling some methods to see if the object is functional:
    ConsoleWrite("--------------------------------------" & @CRLF)
    $oIShellBrowser.AddRef()
    $oIShellBrowser.AddRef()
    $oIShellBrowser.AddRef()
    ConsoleWrite("--------------------------------------" & @CRLF)
    $oIShellBrowser.Release()
    $oIShellBrowser.Release()
    $oIShellBrowser.Release()
    ConsoleWrite("--------------------------------------" & @CRLF)

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

    While Sleep(100)
    WEnd

EndFunc

Func Quit()
    ConsoleWrite(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" & @CRLF)
    $oIShellBrowser = 0 ; kill the object (ref count should be 0 now and it's safe to call function below)
    ConsoleWrite("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" & @CRLF)
    DeleteObjectFromTag($tIShellBrowser)
    Exit
EndFunc

Func StringFromGUID($pGUID)
    Local $aResult = DllCall("ole32.dll", "int", "StringFromGUID2", "struct*", $pGUID, "wstr", "", "int", 40)
    If @error Then Return SetError(@error, @extended, "")
    Return SetExtended($aResult[0], $aResult[2])
EndFunc

Func oIShellBrowser_QueryInterface($pSelf, $pRIID, $pObj)
    Local $tRef = DllStructCreate("int", $pSelf - 8) ; reference counter is size of two ints before
    Local $sIID = StringFromGUID($pRIID)
    ConsoleWrite("oIShellBrowser_QueryInterface: " & $sIID & @CRLF)
    If $sIID = $sIID_IUnknown Or $sIID = $sIID_IShellBrowser Then
        DllStructSetData(DllStructCreate("ptr", $pObj), 1, $pSelf)
        DllStructSetData($tRef, 1, DllStructGetData($tRef, 1) + 1) ; increase ref count
        Return $S_OK
    EndIf
    ; For all other cases
    Return $E_NOINTERFACE
EndFunc

Func oIShellBrowser_AddRef($pSelf)
    Local $tRef = DllStructCreate("int", $pSelf - 8) ; reference counter is size of two ints before
    Local $iRef = DllStructGetData($tRef, 1) + 1 ; increment
    DllStructSetData($tRef, 1, $iRef)
    ConsoleWrite("oIShellBrowser_AddRef ref count = " & $iRef & @CRLF)
    Return $iRef
EndFunc

Func oIShellBrowser_Release($pSelf)
    Local $tRef = DllStructCreate("int", $pSelf - 8) ; reference counter is size of two ints before
    Local $iRef = DllStructGetData($tRef, 1) - 1 ; decrement
    DllStructSetData($tRef, 1, $iRef)
    ConsoleWrite("oIShellBrowser_Release ref count = " & $iRef & @CRLF)
    Return $iRef
EndFunc

Func oIShellBrowser_GetWindow($pSelf, $phwnd)
    ConsoleWrite("oIShellBrowser_GetWindow" & @CRLF)
    Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_ContextSensitiveHelp($pSelf, $fEnterMode)
    ConsoleWrite("oIShellBrowser_ContextSensitiveHelp" & @CRLF)
    Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_InsertMenusSB($pSelf, $hmenuShared, $lpMenuWidths)
    ConsoleWrite("oIShellBrowser_InsertMenusSB" & @CRLF)
    Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_SetMenuSB($pSelf, $hmenuShared, $holemenuRes, $hwndActiveObject)
    ConsoleWrite("oIShellBrowser_SetMenuSB" & @CRLF)
    Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_RemoveMenusSB($pSelf, $hmenuShared)
    ConsoleWrite("oIShellBrowser_RemoveMenusSB" & @CRLF)
    Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_SetStatusTextSB($pSelf, $lpszStatusText)
    ConsoleWrite("oIShellBrowser_SetStatusTextSB" & @CRLF)
    Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_EnableModelessSB($pSelf, $fEnable)
    ConsoleWrite("oIShellBrowser_EnableModelessSB" & @CRLF)
    Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_TranslateAcceleratorSB($pSelf, $lpmsg, $wID)
    ConsoleWrite("oIShellBrowser_TranslateAcceleratorSB" & @CRLF)
    Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_BrowseObject($pSelf, $pidl, $wFlags)
    ConsoleWrite("oIShellBrowser_BrowseObject" & @CRLF)
    Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_GetViewStateStream($pSelf, $grfMode, $ppStrm)
    ConsoleWrite("oIShellBrowser_GetViewStateStream" & @CRLF)
    Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_GetControlWindow($pSelf, $id, $lphwnd)
    ConsoleWrite("oIShellBrowser_GetControlWindow" & @CRLF)
    Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_SendControlMsg($pSelf, $id, $uMsg, $wParam, $lParam, $pret)
    ConsoleWrite("oIShellBrowser_SendControlMsg" & @CRLF)
    Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_QueryActiveShellView($pSelf, $ppshv)
    ConsoleWrite("oIShellBrowser_QueryActiveShellView" & @CRLF)
    Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_OnViewWindowActive($pSelf, $ppshv)
    ConsoleWrite("oIShellBrowser_OnViewWindowActive" & @CRLF)
    Return $E_NOTIMPL
EndFunc

Func oIShellBrowser_SetToolbarItems($pSelf, $lpButtons, $nButtons, $uFlags)
    ConsoleWrite("oIShellBrowser_SetToolbarItems" & @CRLF)
    Return $E_NOTIMPL
EndFunc




Func ObjectFromTag($sFunctionPrefix, $tagInterface, ByRef $tInterface, $bIsUnknown = Default, $sIID = "{00000000-0000-0000-C000-000000000046}") ; last param is IID_IUnknown by default
    If $bIsUnknown = Default Then $bIsUnknown = True
    Local $sInterface = $tagInterface ; copy interface description
    Local $tagIUnknown = "QueryInterface hresult(ptr;ptr*);" & _
            "AddRef dword();" & _
            "Release dword();"
    ; Adding IUnknown methods
    If $bIsUnknown Then $tagInterface = $tagIUnknown & $tagInterface
    ; Below line is really simple even though it looks super complex. It's just written weird to fit in one line, not to steal your attention
    Local $aMethods = StringSplit(StringTrimRight(StringReplace(StringRegExpReplace(StringRegExpReplace($tagInterface, "\w+\*", "ptr"), "\h*(\w+)\h*(\w+\*?)\h*(\((.*?)\))\h*(;|;*\z)", "$1\|$2;$4" & @LF), ";" & @LF, @LF), 1), @LF, 3)
    Local $iUbound = UBound($aMethods)
    Local $sMethod, $aSplit, $sNamePart, $aTagPart, $sTagPart, $sRet, $sParams, $hCallback
    ; Allocation
    $tInterface = DllStructCreate("int RefCount;int Size;ptr Object;ptr Methods[" & $iUbound & "];int_ptr Callbacks[" & $iUbound & "];ulong_ptr Slots[16]") ; 16 pointer sized elements more to create space for possible private props
    If @error Then Return SetError(1, 0, 0)
    For $i = 0 To $iUbound - 1
        $aSplit = StringSplit($aMethods[$i], "|", 2)
        If UBound($aSplit) <> 2 Then ReDim $aSplit[2]
        $sNamePart = $aSplit[0]
        ; Replace COM types by matching dllcallback types
        $sTagPart = StringReplace(StringReplace(StringReplace(StringReplace($aSplit[1], "object", "idispatch"), "hresult", "long"), "bstr", "ptr"), "variant", "ptr")
        $sMethod = $sFunctionPrefix & $sNamePart
        $aTagPart = StringSplit($sTagPart, ";", 2)
        $sRet = $aTagPart[0]
        $sParams = StringReplace($sTagPart, $sRet, "", 1)
        $sParams = "ptr" & $sParams
        $hCallback = DllCallbackRegister($sMethod, $sRet, $sParams)
        DllStructSetData($tInterface, "Methods", DllCallbackGetPtr($hCallback), $i + 1) ; save callback pointer
        DllStructSetData($tInterface, "Callbacks", $hCallback, $i + 1) ; save callback handle
    Next
    DllStructSetData($tInterface, "RefCount", 1) ; initial ref count is 1
    DllStructSetData($tInterface, "Size", $iUbound) ; number of interface methods
    DllStructSetData($tInterface, "Object", DllStructGetPtr($tInterface, "Methods")) ; Interface method pointers
    Return ObjCreateInterface(DllStructGetPtr($tInterface, "Object"), $sIID, $sInterface, $bIsUnknown) ; pointer that's wrapped into object
EndFunc

Func DeleteObjectFromTag(ByRef $tInterface)
    For $i = 1 To DllStructGetData($tInterface, "Size")
        DllCallbackFree(DllStructGetData($tInterface, "Callbacks", $i))
    Next
    $tInterface = 0
EndFunc
I added comments inside your Quit() function.

edit: Oh and don't try to delete the object from within its methods. AutoIt doesn't support that.

Edited by trancexx

Share this post


Link to post
Share on other sites

Thank you. I'm sorry that I have not responded to the previous post. You should not have spent time on this little issue. I have simply deleted that part of the string expression. Seems not to be used.

Share this post


Link to post
Share on other sites

I have made some tests with event handler interfaces. For a start just to verify whether I could get some events at all.

I succeeded to get events for IUIAutomationEventHandler, IUIAutomationFocusChangedEventHandler and UIAutomationStructureChangedEventHandler but not for IUIAutomationPropertyChangedEventHandler.

IUIAutomationFocusChangedEventHandler

If you test with Calculator you'll get events when you click a number button and the focus changes between the button and the edit box.

 

This cool focus event handler can also expose control in focus with help ToolTip near mouse cursor.

FocusTracker.au3:

#include "CUIAutomation2.au3"
;If you test with Calculator you'll get events when you click a number button and 
;the focus changes between the button and the edit box

Opt( "MustDeclareVars", 1 )

Global Const $S_OK = 0x00000000
Global Const $E_NOINTERFACE = 0x80004002
Global Const $sIID_IUnknown = "{00000000-0000-0000-C000-000000000046}"

Global $tIUIAutomationFocusChangedEventHandler, $oIUIAutomationFocusChangedEventHandler

Global $oUIAutomation

MainFunc()

Func MouseToolTip($Text)
Local $MousePos
 $MousePos = MouseGetPos()
 ToolTip($Text,$MousePos[0],$MousePos[1]+50)
 Sleep(1000)
EndFunc

Func MainFunc()

  $oIUIAutomationFocusChangedEventHandler = ObjectFromTag( "oIUIAutomationFocusChangedEventHandler_", $dtagIUIAutomationFocusChangedEventHandler, $tIUIAutomationFocusChangedEventHandler, True )
  If Not IsObj( $oIUIAutomationFocusChangedEventHandler ) Then Return

  $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation )
  If Not IsObj( $oUIAutomation ) Then Return

  Local $pUIElement
  $oUIAutomation.GetRootElement( $pUIElement ) ; Desktop
  If Not $pUIElement Then Return

  If $oUIAutomation.AddFocusChangedEventHandler( 0, $oIUIAutomationFocusChangedEventHandler ) Then Exit

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

  While Sleep(10)
  WEnd

EndFunc

Func Quit()
  $oIUIAutomationFocusChangedEventHandler = 0
  DeleteObjectFromTag( $tIUIAutomationFocusChangedEventHandler )
  Exit
EndFunc

Func _UIA_getPropertyValue( $obj, $id )
  Local $tVal
  $obj.GetCurrentPropertyValue( $id, $tVal )
  Return $tVal
EndFunc

Func oIUIAutomationFocusChangedEventHandler_HandleFocusChangedEvent( $pSelf, $pSender ) ; Ret: long  Par: ptr
  Local $sText
  ConsoleWrite( "oIUIAutomationFocusChangedEventHandler_HandleFocusChangedEvent: " & $pSender & @CRLF )
  Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  $oSender.AddRef()
  $sText = "Title     = " & _UIA_getPropertyValue( $oSender, $UIA_NamePropertyId ) & @CRLF & _
           "Class     = " & _UIA_getPropertyValue( $oSender, $UIA_ClassNamePropertyId ) & @CRLF & _
           "Ctrl type = " & _UIA_getPropertyValue( $oSender, $UIA_ControlTypePropertyId ) & @CRLF & _
           "Ctrl name = " & _UIA_getPropertyValue( $oSender, $UIA_LocalizedControlTypePropertyId ) & @CRLF & _
           "Value     = " & _UIA_getPropertyValue( $oSender, $UIA_LegacyIAccessibleValuePropertyId ) & @CRLF & _
           "Handle    = " & Hex( _UIA_getPropertyValue( $oSender, $UIA_NativeWindowHandlePropertyId ) ) & @CRLF & @CRLF
  MouseToolTip($sText)
  ConsoleWrite($sText)
  Return $S_OK
EndFunc

Func oIUIAutomationFocusChangedEventHandler_QueryInterface( $pSelf, $pRIID, $pObj ) ; Ret: long  Par: ptr;ptr*
  Local $sIID = StringFromGUID( $pRIID )
  If $sIID = $sIID_IUnknown Then
    ConsoleWrite( "oIUIAutomationFocusChangedEventHandler_QueryInterface: IUnknown" & @CRLF )
    DllStructSetData( DllStructCreate( "ptr", $pObj ), 1, $pSelf )
    oIUIAutomationFocusChangedEventHandler_AddRef( $pSelf )
    Return $S_OK
  ElseIf $sIID = $sIID_IUIAutomationFocusChangedEventHandler Then
    ConsoleWrite( "oIUIAutomationFocusChangedEventHandler_QueryInterface: IUIAutomationFocusChangedEventHandler" & @CRLF )
    DllStructSetData( DllStructCreate( "ptr", $pObj ), 1, $pSelf )
    oIUIAutomationFocusChangedEventHandler_AddRef( $pSelf )
    Return $S_OK
  Else
    ConsoleWrite( "oIUIAutomationFocusChangedEventHandler_QueryInterface: " & $sIID & @CRLF )
    Return $E_NOINTERFACE
  EndIf
EndFunc

Func oIUIAutomationFocusChangedEventHandler_AddRef( $pSelf ) ; Ret: ulong
  ConsoleWrite( "oIUIAutomationFocusChangedEventHandler_AddRef" & @CRLF )
  Return 1
EndFunc

Func oIUIAutomationFocusChangedEventHandler_Release( $pSelf ) ; Ret: ulong
  ConsoleWrite( "oIUIAutomationFocusChangedEventHandler_Release" & @CRLF )
  Return 1
EndFunc

Func StringFromGUID( $pGUID )
  Local $aResult = DllCall( "ole32.dll", "int", "StringFromGUID2", "struct*", $pGUID, "wstr", "", "int", 40 )
  If @error Then Return SetError( @error, @extended, "" )
  Return SetExtended( $aResult[0], $aResult[2] )
EndFunc

Func ObjectFromTag($sFunctionPrefix, $tagInterface, ByRef $tInterface, $fPrint = False, $bIsUnknown = Default, $sIID = "{00000000-0000-0000-C000-000000000046}") ; last param is IID_IUnknown by default
    If $bIsUnknown = Default Then $bIsUnknown = True
    Local $sInterface = $tagInterface ; copy interface description
    Local $tagIUnknown = "QueryInterface hresult(ptr;ptr*);" & _
            "AddRef dword();" & _
            "Release dword();"
    ; Adding IUnknown methods
    If $bIsUnknown Then $tagInterface = $tagIUnknown & $tagInterface
    ; Below line is really simple even though it looks super complex. It's just written weird to fit in one line, not to steal your attention
    Local $aMethods = StringSplit(StringReplace(StringReplace(StringReplace(StringReplace(StringTrimRight(StringReplace(StringRegExpReplace(StringRegExpReplace($tagInterface, "\w+\*", "ptr"), "\h*(\w+)\h*(\w+\*?)\h*(\((.*?)\))\h*(;|;*\z)", "$1\|$2;$4" & @LF), ";" & @LF, @LF), 1), "object", "idispatch"), "hresult", "long"), "bstr", "ptr"), "variant", "ptr"), @LF, 3)
    Local $iUbound = UBound($aMethods)
    Local $sMethod, $aSplit, $sNamePart, $aTagPart, $sTagPart, $sRet, $sParams, $hCallback
    ; Allocation
    $tInterface = DllStructCreate("int RefCount;int Size;ptr Object;ptr Methods[" & $iUbound & "];int_ptr Callbacks[" & $iUbound & "];ulong_ptr Slots[16]") ; 16 pointer sized elements more to create space for possible private props
    If @error Then Return SetError(1, 0, 0)
    For $i = 0 To $iUbound - 1
        $aSplit = StringSplit($aMethods[$i], "|", 2)
        If UBound($aSplit) <> 2 Then ReDim $aSplit[2]
        $sNamePart = $aSplit[0]
        $sTagPart = $aSplit[1]
        $sMethod = $sFunctionPrefix & $sNamePart
        If $fPrint Then
            Local $iPar = StringInStr( $sTagPart, ";", 2 ), $t
            If $iPar Then
                $t = "Ret: " & StringLeft( $sTagPart, $iPar - 1 ) & "  " & _
                     "Par: " & StringRight( $sTagPart, StringLen( $sTagPart ) - $iPar )
            Else
                $t = "Ret: " & $sTagPart
            EndIf
            Local $s = "Func " & $sMethod & _
                "( $pSelf ) ; " & $t & @CRLF & _
                "EndFunc" & @CRLF
;            MouseToolTip($s)
            ConsoleWrite($s)
        EndIf
        $aTagPart = StringSplit($sTagPart, ";", 2)
        $sRet = $aTagPart[0]
        $sParams = StringReplace($sTagPart, $sRet, "", 1)
        $sParams = "ptr" & $sParams
        $hCallback = DllCallbackRegister($sMethod, $sRet, $sParams)
        ConsoleWrite(@error & @CRLF & @CRLF)
        DllStructSetData($tInterface, "Methods", DllCallbackGetPtr($hCallback), $i + 1) ; save callback pointer
        DllStructSetData($tInterface, "Callbacks", $hCallback, $i + 1) ; save callback handle
    Next
    DllStructSetData($tInterface, "RefCount", 1) ; initial ref count is 1
    DllStructSetData($tInterface, "Size", $iUbound) ; number of interface methods
    DllStructSetData($tInterface, "Object", DllStructGetPtr($tInterface, "Methods")) ; Interface method pointers
    Return ObjCreateInterface(DllStructGetPtr($tInterface, "Object"), $sIID, $sInterface, $bIsUnknown) ; pointer that's wrapped into object
EndFunc

Func DeleteObjectFromTag(ByRef $tInterface)
    For $i = 1 To DllStructGetData($tInterface, "Size")
        DllCallbackFree(DllStructGetData($tInterface, "Callbacks", $i))
    Next
    $tInterface = 0
EndFunc

Thank you

Share this post


Link to post
Share on other sites

ValeryVal, This could be useful if you not have too many events.

By the way, all four examples in post #112 works now.

Here is an example with the structure change event handler.

When you download exe-files in IE9, IE10 or IE11 a notification bar shows up in the bottom of the window. This example automatically clicks the save and close buttons when the notification shows up. If a security scan notification or a download completed notification shows up the close button will be clicked.

Here is the code:

#include "CUIAutomation2.au3"

Opt( "MustDeclareVars", 1 )

Global Const $S_OK = 0x00000000
Global Const $E_NOINTERFACE = 0x80004002
Global Const $sIID_IUnknown = "{00000000-0000-0000-C000-000000000046}"

Global $tIUIAutomationStructureChangedEventHandler, $oIUIAutomationStructureChangedEventHandler

Global $oUIAutomation

MainFunc()



Func MainFunc()

  ; Create custom event handler object for structure change events
  $oIUIAutomationStructureChangedEventHandler = ObjectFromTag( "oIUIAutomationStructureChangedEventHandler_", $dtagIUIAutomationStructureChangedEventHandler, $tIUIAutomationStructureChangedEventHandler, True )
  If Not IsObj( $oIUIAutomationStructureChangedEventHandler ) Then Return

  ; Create UI Automation object
  $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation )
  If Not IsObj( $oUIAutomation ) Then Return

  ; Create UI element
  ;Local $pUIElement
  ;$oUIAutomation.GetRootElement( $pUIElement ) ; Desktop
  ;If Not $pUIElement Then Return

  ; Create UI element
  Local $hWindow, $pUIElement
  $hWindow = WinGetHandle( "[CLASS:IEFrame]" ) ; Internet Explorer
  $oUIAutomation.ElementFromHandle( $hWindow, $pUIElement )
  If Not $pUIElement Then Return

  ; Add structure change event handler
  If $oUIAutomation.AddStructureChangedEventHandler( $pUIElement, $TreeScope_Subtree, 0, $oIUIAutomationStructureChangedEventHandler ) Then Exit

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

  While Sleep(100)
  WEnd

EndFunc

Func Quit()
  $oIUIAutomationStructureChangedEventHandler = 0
  DeleteObjectFromTag( $tIUIAutomationStructureChangedEventHandler )
  Exit
EndFunc



; Get property ($id) for UI element ($obj)
Func _UIA_getPropertyValue( $obj, $id )
  Local $tVal
  $obj.GetCurrentPropertyValue( $id, $tVal )
  If Not IsArray( $tVal ) Then Return $tVal
  Local $tStr = $tVal[0]
  For $i = 1 To UBound( $tVal ) - 1
    $tStr &= "; " & $tVal[$i]
  Next
  Return $tStr
EndFunc

; List all descendants of the parent UI element
; in a hierarchical structure like a treeview.
Func ListDescendants( $oParent, $iLevel, $iLevels = 0 )

  If Not IsObj( $oParent ) Then Return
  If $iLevels And $iLevel = $iLevels Then Return

  Local $pRawWalker, $oRawWalker
  $oUIAutomation.RawViewWalker( $pRawWalker )
  $oRawWalker = ObjCreateInterface( $pRawWalker, $sIID_IUIAutomationTreeWalker, $dtagIUIAutomationTreeWalker )

  Local $pUIElement, $oUIElement
  $oRawWalker.GetFirstChildElement( $oParent, $pUIElement )
  $oUIElement = ObjCreateInterface( $pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )

  Local $sIndent = ""
  For $i = 0 To $iLevel - 1
    $sIndent &= "    "
  Next

  While IsObj( $oUIElement )
    ConsoleWrite( $sIndent & "Title     = " & _UIA_getPropertyValue( $oUIElement, $UIA_NamePropertyId ) & @CRLF & _
                  $sIndent & "Class     = " & _UIA_getPropertyValue( $oUIElement, $UIA_ClassNamePropertyId ) & @CRLF & _
                  $sIndent & "Ctrl type = " & _UIA_getPropertyValue( $oUIElement, $UIA_ControlTypePropertyId ) & @CRLF & _
                  $sIndent & "Ctrl name = " & _UIA_getPropertyValue( $oUIElement, $UIA_LocalizedControlTypePropertyId ) & @CRLF & _
                  $sIndent & "Value     = " & _UIA_getPropertyValue( $oUIElement, $UIA_LegacyIAccessibleValuePropertyId ) & @CRLF & _
                  $sIndent & "Handle    = " & Hex( _UIA_getPropertyValue( $oUIElement, $UIA_NativeWindowHandlePropertyId ) ) & @CRLF & @CRLF )

    ListDescendants( $oUIElement, $iLevel + 1, $iLevels )

    $oRawWalker.GetNextSiblingElement( $oUIElement, $pUIElement )
    $oUIElement = ObjCreateInterface( $pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  WEnd

EndFunc



Func oIUIAutomationStructureChangedEventHandler_HandleStructureChangedEvent( $pSelf, $pSender, $iChangeType, $pRuntimeId ) ; Ret: long  Par: ptr;long;ptr

  ; Create sender object
  Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  $oSender.AddRef()

  ; Get object class
  Local $sClass
  $oSender.GetCurrentPropertyValue( $UIA_ClassNamePropertyId, $sClass )

  ; Only handle objects of class "Frame Notification Bar"
  If $sClass = "Frame Notification Bar" Then

    ; Print object properties
    ConsoleWrite( @CRLF & _
                  "Title     = " & _UIA_getPropertyValue( $oSender, $UIA_NamePropertyId ) & @CRLF & _
                  "Class     = " & _UIA_getPropertyValue( $oSender, $UIA_ClassNamePropertyId ) & @CRLF & _
                  "Ctrl type = " & _UIA_getPropertyValue( $oSender, $UIA_ControlTypePropertyId ) & @CRLF & _
                  "Ctrl name = " & _UIA_getPropertyValue( $oSender, $UIA_LocalizedControlTypePropertyId ) & @CRLF & _
                  "Value     = " & _UIA_getPropertyValue( $oSender, $UIA_LegacyIAccessibleValuePropertyId ) & @CRLF & _
                  "Handle    = " & Hex( _UIA_getPropertyValue( $oSender, $UIA_NativeWindowHandlePropertyId ) ) & @CRLF & @CRLF )

    If $iChangeType = 0 Then ; Window open event
      ConsoleWrite( "Notification Bar opened" & @CRLF & @CRLF )
    Else ; $iChangeType = 1  ; Window close event
      ConsoleWrite( "Notification Bar closed" & @CRLF & @CRLF )
      Return $S_OK
    EndIf

    ; List descendants of the object
    ConsoleWrite( "Descendants of the Frame Notification Bar:" & @CRLF & @CRLF )
    ListDescendants( $oSender, 0, 0 )

    ; Condition to find Save button (split button)
    Local $pCondition
    $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_SplitButtonControlTypeId, $pCondition )
    If Not $pCondition Then Return $S_OK

    ; Find Save button
    Local $pSave, $oSave
    $oSender.FindFirst( $TreeScope_Descendants, $pCondition, $pSave )

    If $pSave Then

      ; Click Save and Close buttons in the first "Frame Notification Bar" window

      $oSave = ObjCreateInterface( $pSave, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
      If Not IsObj( $oSave ) Then Return $S_OK

      ; Click (invoke) Save button
      Local $pInvoke, $oInvoke
      $oSave.GetCurrentPattern( $UIA_InvokePatternId, $pInvoke )
      $oInvoke = ObjCreateInterface( $pInvoke, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern )
      If Not IsObj( $oInvoke ) Then Return $S_OK
      $oInvoke.Invoke()
      ConsoleWrite( "Save button clicked" & @CRLF & @CRLF )

      ; Condition to find Close button
      Local $pCondition1, $pCondition2
      $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition1 )
      $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Close", $pCondition2 )
      $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition )
      If Not $pCondition Then Return $S_OK

      ; Find Close button
      Local $pClose, $oClose
      $oSender.FindFirst( $TreeScope_Descendants, $pCondition, $pClose )
      $oClose = ObjCreateInterface( $pClose, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
      If Not IsObj( $oClose ) Then Return $S_OK

      ; Click (invoke) Close button
      Local $pInvoke, $oInvoke
      $oClose.GetCurrentPattern( $UIA_InvokePatternId, $pInvoke )
      $oInvoke = ObjCreateInterface( $pInvoke, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern )
      If Not IsObj( $oInvoke ) Then Return $S_OK
      $oInvoke.Invoke()
      ConsoleWrite( "Close button clicked" & @CRLF & @CRLF )

    Else

      ; Click Close button in the next "Frame Notification Bar" windows

      ; Condition to find Close button
      Local $pCondition1, $pCondition2
      $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition1 )
      $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Close", $pCondition2 )
      $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition )
      If Not $pCondition Then Return $S_OK

      ; Find Close button
      Local $pClose, $oClose
      $oSender.FindFirst( $TreeScope_Descendants, $pCondition, $pClose )
      $oClose = ObjCreateInterface( $pClose, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
      If Not IsObj( $oClose ) Then Return $S_OK

      ; Click (invoke) Close button
      Local $pInvoke, $oInvoke
      $oClose.GetCurrentPattern( $UIA_InvokePatternId, $pInvoke )
      $oInvoke = ObjCreateInterface( $pInvoke, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern )
      If Not IsObj( $oInvoke ) Then Return $S_OK
      $oInvoke.Invoke()
      ConsoleWrite( "Close button clicked" & @CRLF & @CRLF )

    EndIf

  EndIf

  Return $S_OK

EndFunc

Func oIUIAutomationStructureChangedEventHandler_QueryInterface( $pSelf, $pRIID, $pObj ) ; Ret: long  Par: ptr;ptr*
  Local $sIID = StringFromGUID( $pRIID )
  If $sIID = $sIID_IUnknown Then
    ConsoleWrite( "oIUIAutomationStructureChangedEventHandler_QueryInterface: IUnknown" & @CRLF )
    DllStructSetData( DllStructCreate( "ptr", $pObj ), 1, $pSelf )
    oIUIAutomationStructureChangedEventHandler_AddRef( $pSelf )
    Return $S_OK
  ElseIf $sIID = $sIID_IUIAutomationStructureChangedEventHandler Then
    ConsoleWrite( "oIUIAutomationStructureChangedEventHandler_QueryInterface: IUIAutomationStructureChangedEventHandler" & @CRLF )
    DllStructSetData( DllStructCreate( "ptr", $pObj ), 1, $pSelf )
    oIUIAutomationStructureChangedEventHandler_AddRef( $pSelf )
    Return $S_OK
  Else
    ConsoleWrite( "oIUIAutomationStructureChangedEventHandler_QueryInterface: " & $sIID & @CRLF )
    Return $E_NOINTERFACE
  EndIf
EndFunc

Func oIUIAutomationStructureChangedEventHandler_AddRef( $pSelf ) ; Ret: ulong
  ConsoleWrite( "oIUIAutomationStructureChangedEventHandler_AddRef" & @CRLF )
  Return 1
EndFunc

Func oIUIAutomationStructureChangedEventHandler_Release( $pSelf ) ; Ret: ulong
  ConsoleWrite( "oIUIAutomationStructureChangedEventHandler_Release" & @CRLF )
  Return 1
EndFunc



Func StringFromGUID( $pGUID )
  Local $aResult = DllCall( "ole32.dll", "int", "StringFromGUID2", "struct*", $pGUID, "wstr", "", "int", 40 )
  If @error Then Return SetError( @error, @extended, "" )
  Return SetExtended( $aResult[0], $aResult[2] )
EndFunc

; Copied and slightly modified (print methods) from this post by trancexx:
; http://www.autoitscript.com/forum/topic/153520-iuiautomation-ms-framework-automate-chrome-ff-ie/page*#entry1143566
Func ObjectFromTag($sFunctionPrefix, $tagInterface, ByRef $tInterface, $fPrint = False, $bIsUnknown = Default, $sIID = "{00000000-0000-0000-C000-000000000046}") ; last param is IID_IUnknown by default
    If $bIsUnknown = Default Then $bIsUnknown = True
    Local $sInterface = $tagInterface ; copy interface description
    Local $tagIUnknown = "QueryInterface hresult(ptr;ptr*);" & _
            "AddRef dword();" & _
            "Release dword();"
    ; Adding IUnknown methods
    If $bIsUnknown Then $tagInterface = $tagIUnknown & $tagInterface
    ; Below line is really simple even though it looks super complex. It's just written weird to fit in one line, not to steal your attention
    Local $aMethods = StringSplit(StringReplace(StringReplace(StringReplace(StringReplace(StringTrimRight(StringReplace(StringRegExpReplace(StringRegExpReplace($tagInterface, "\w+\*", "ptr"), "\h*(\w+)\h*(\w+\*?)\h*(\((.*?)\))\h*(;|;*\z)", "$1\|$2;$4" & @LF), ";" & @LF, @LF), 1), "object", "idispatch"), "hresult", "long"), "bstr", "ptr"), "variant", "ptr"), @LF, 3)
    Local $iUbound = UBound($aMethods)
    Local $sMethod, $aSplit, $sNamePart, $aTagPart, $sTagPart, $sRet, $sParams, $hCallback
    ; Allocation
    $tInterface = DllStructCreate("int RefCount;int Size;ptr Object;ptr Methods[" & $iUbound & "];int_ptr Callbacks[" & $iUbound & "];ulong_ptr Slots[16]") ; 16 pointer sized elements more to create space for possible private props
    If @error Then Return SetError(1, 0, 0)
    For $i = 0 To $iUbound - 1
        $aSplit = StringSplit($aMethods[$i], "|", 2)
        If UBound($aSplit) <> 2 Then ReDim $aSplit[2]
        $sNamePart = $aSplit[0]
        $sTagPart = $aSplit[1]
        $sMethod = $sFunctionPrefix & $sNamePart
        If $fPrint Then
            Local $iPar = StringInStr( $sTagPart, ";", 2 ), $t
            If $iPar Then
                $t = "Ret: " & StringLeft( $sTagPart, $iPar - 1 ) & "  " & _
                     "Par: " & StringRight( $sTagPart, StringLen( $sTagPart ) - $iPar )
            Else
                $t = "Ret: " & $sTagPart
            EndIf
            Local $s = "Func " & $sMethod & _
                "( $pSelf ) ; " & $t & @CRLF & _
                "EndFunc" & @CRLF
            ConsoleWrite( $s )
        EndIf
        $aTagPart = StringSplit($sTagPart, ";", 2)
        $sRet = $aTagPart[0]
        $sParams = StringReplace($sTagPart, $sRet, "", 1)
        $sParams = "ptr" & $sParams
        $hCallback = DllCallbackRegister($sMethod, $sRet, $sParams)
        ConsoleWrite(@error & @CRLF & @CRLF)
        DllStructSetData($tInterface, "Methods", DllCallbackGetPtr($hCallback), $i + 1) ; save callback pointer
        DllStructSetData($tInterface, "Callbacks", $hCallback, $i + 1) ; save callback handle
    Next
    DllStructSetData($tInterface, "RefCount", 1) ; initial ref count is 1
    DllStructSetData($tInterface, "Size", $iUbound) ; number of interface methods
    DllStructSetData($tInterface, "Object", DllStructGetPtr($tInterface, "Methods")) ; Interface method pointers
    Return ObjCreateInterface(DllStructGetPtr($tInterface, "Object"), $sIID, $sInterface, $bIsUnknown) ; pointer that's wrapped into object
EndFunc

Func DeleteObjectFromTag(ByRef $tInterface)
    For $i = 1 To DllStructGetData($tInterface, "Size")
        DllCallbackFree(DllStructGetData($tInterface, "Callbacks", $i))
    Next
    $tInterface = 0
EndFunc

One issue with the code: I think the button name "Close" is localized. You should use your own button name.

And here is the output in Scite console:

Func oIUIAutomationStructureChangedEventHandler_QueryInterface( $pSelf ) ; Ret: long  Par: ptr;ptr
EndFunc
0

Func oIUIAutomationStructureChangedEventHandler_AddRef( $pSelf ) ; Ret: dword
EndFunc
0

Func oIUIAutomationStructureChangedEventHandler_Release( $pSelf ) ; Ret: dword
EndFunc
0

Func oIUIAutomationStructureChangedEventHandler_HandleStructureChangedEvent( $pSelf ) ; Ret: long  Par: ptr;long;ptr
EndFunc
0

oIUIAutomationStructureChangedEventHandler_QueryInterface: IUnknown
oIUIAutomationStructureChangedEventHandler_AddRef
oIUIAutomationStructureChangedEventHandler_Release
oIUIAutomationStructureChangedEventHandler_AddRef
oIUIAutomationStructureChangedEventHandler_QueryInterface: {0000001B-0000-0000-C000-000000000046}
oIUIAutomationStructureChangedEventHandler_QueryInterface: {00000003-0000-0000-C000-000000000046}
oIUIAutomationStructureChangedEventHandler_AddRef
oIUIAutomationStructureChangedEventHandler_QueryInterface: {0000001B-0000-0000-C000-000000000046}
oIUIAutomationStructureChangedEventHandler_QueryInterface: IUnknown
oIUIAutomationStructureChangedEventHandler_AddRef
oIUIAutomationStructureChangedEventHandler_AddRef
oIUIAutomationStructureChangedEventHandler_QueryInterface: {00000018-0000-0000-C000-000000000046}
oIUIAutomationStructureChangedEventHandler_QueryInterface: {00000019-0000-0000-C000-000000000046}
oIUIAutomationStructureChangedEventHandler_QueryInterface: {4C1E39E1-E3E3-4296-AA86-EC938D896E92}
oIUIAutomationStructureChangedEventHandler_Release
oIUIAutomationStructureChangedEventHandler_QueryInterface: IUIAutomationStructureChangedEventHandler
oIUIAutomationStructureChangedEventHandler_AddRef
oIUIAutomationStructureChangedEventHandler_AddRef
oIUIAutomationStructureChangedEventHandler_QueryInterface: {1C733A30-2A1C-11CE-ADE5-00AA0044773D}
oIUIAutomationStructureChangedEventHandler_QueryInterface: IUIAutomationStructureChangedEventHandler
oIUIAutomationStructureChangedEventHandler_AddRef

Title     = 
Class     = Frame Notification Bar
Ctrl type = 50033
Ctrl name = pane
Value     = 
Handle    = 00010602

Notification Bar opened

Descendants of the Frame Notification Bar:

Title     = Notification
Class     = DirectUIHWND
Ctrl type = 50021
Ctrl name = tool bar
Value     = 
Handle    = 00010604

    Title     = Notification bar Text
    Class     = 
    Ctrl type = 50020
    Ctrl name = text
    Value     = Do you want to run or save autoit-v3-setup.exe (10,9 MB) from autoitscript.com?
    Handle    = 00000000

    Title     = Run
    Class     = 
    Ctrl type = 50000
    Ctrl name = button
    Value     = 
    Handle    = 00000000

    Title     = Save
    Class     = 
    Ctrl type = 50031
    Ctrl name = split button
    Value     = 
    Handle    = 00000000

        Title     = 
        Class     = 
        Ctrl type = 50031
        Ctrl name = split button
        Value     = 
        Handle    = 00000000

    Title     = Cancel
    Class     = 
    Ctrl type = 50000
    Ctrl name = button
    Value     = 
    Handle    = 00000000

    Title     = Close
    Class     = 
    Ctrl type = 50000
    Ctrl name = button
    Value     = 
    Handle    = 00000000

Save button clicked

Close button clicked


Title     = 
Class     = Frame Notification Bar
Ctrl type = 50033
Ctrl name = pane
Value     = 
Handle    = 00010602

Notification Bar closed


Title     = 
Class     = Frame Notification Bar
Ctrl type = 50033
Ctrl name = pane
Value     = 
Handle    = 00010602

Notification Bar opened

Descendants of the Frame Notification Bar:

Title     = Notification
Class     = DirectUIHWND
Ctrl type = 50021
Ctrl name = tool bar
Value     = 
Handle    = 00010604

    Title     = Notification bar Text
    Class     = 
    Ctrl type = 50020
    Ctrl name = text
    Value     = Running security scan
    Handle    = 00000000

    Title     = View downloads
    Class     = 
    Ctrl type = 50000
    Ctrl name = button
    Value     = 
    Handle    = 00000000

    Title     = Close
    Class     = 
    Ctrl type = 50000
    Ctrl name = button
    Value     = 
    Handle    = 00000000

Close button clicked


Title     = 
Class     = Frame Notification Bar
Ctrl type = 50033
Ctrl name = pane
Value     = 
Handle    = 00010602

Notification Bar closed


Title     = 
Class     = Frame Notification Bar
Ctrl type = 50033
Ctrl name = pane
Value     = 
Handle    = 00010602

Notification Bar opened

Descendants of the Frame Notification Bar:

Title     = Notification
Class     = DirectUIHWND
Ctrl type = 50021
Ctrl name = tool bar
Value     = 
Handle    = 00010604

    Title     = Notification bar Text
    Class     = 
    Ctrl type = 50020
    Ctrl name = text
    Value     = The autoit-v3-setup (9).exe download has completed.
    Handle    = 00000000

    Title     = Run
    Class     = 
    Ctrl type = 50000
    Ctrl name = button
    Value     = 
    Handle    = 00000000

    Title     = Open folder
    Class     = 
    Ctrl type = 50000
    Ctrl name = button
    Value     = 
    Handle    = 00000000

    Title     = View downloads
    Class     = 
    Ctrl type = 50000
    Ctrl name = button
    Value     = 
    Handle    = 00000000

    Title     = Close
    Class     = 
    Ctrl type = 50000
    Ctrl name = button
    Value     = 
    Handle    = 00000000

Close button clicked


Title     = 
Class     = Frame Notification Bar
Ctrl type = 50033
Ctrl name = pane
Value     = 
Handle    = 00010602

Notification Bar closed

oIUIAutomationStructureChangedEventHandler_Release

Tested on Win 7 with IE 11.

Edited by LarsJ

Share this post


Link to post
Share on other sites

If you have downloaded the example above it's very important that you replace this code in MainFunc

 

; Create UI element
Local $pUIElement
$oUIAutomation.GetRootElement( $pUIElement ) ; Desktop
If Not $pUIElement Then Return

with this code

 

; Create UI element
Local $hWindow, $pUIElement
$hWindow = WinGetHandle( "[CLASS:IEFrame]" ) ; Internet Explorer
$oUIAutomation.ElementFromHandle( $hWindow, $pUIElement )
If Not $pUIElement Then Return

If you don't do that you are listening to structure change events from all programs running on the entire PC. And that's all to many events. Even if events are queued up you can risk that there are so many events that some gets lost. It's important that you only listen to events from Internet Explorer.

I have changed the code in post #126.

Remember to open IE before you run the script.

Share this post


Link to post
Share on other sites

Sorry if I missed something

Say, we have some application

 

We dump it and then we get other elements of the application

Can we dump the content of that elements? I was trying to do this way

$oApp=_UIA_getFirstObjectOfElement($odesktop,"classname:=someapplicationclass",$TreeScope_Children)
$oElement=_UIA_getFirstObjectOfElement($oApp,"classname:=someelementclass",$TreeScope_Children)
_UIA_Dumpthemall($oElement, $treescope_subtree)

But it is falling

Variable must be of type "Object".:
$oElementStart.FindAll($TreeScope, $oCondition, $pElements)
$oElementStart^ ERROR

Maybe I used wrong syntax?

Thanx in advance and best regards!

Share this post


Link to post
Share on other sites

You should first check if you have an object most likely you have not

if not isobj($oElement) Then
    consolewrite("Not found")
    Exit
EndIf

In future version of UIA_wrapper I will add more protective checks against "coding" errors

This should work if you have the calculator started

$oApp=_UIA_getFirstObjectOfElement($odesktop,"classname:=CalcFrame",$TreeScope_Children)
$oElement=_UIA_getFirstObjectOfElement($oApp,"classname:=CalcFrame",$TreeScope_Children)
if not isobj($oElement) Then
    consolewrite("Not found")
    Exit
EndIf
_UIA_Dumpthemall($oElement, $treescope_subtree)

Share this post


Link to post
Share on other sites

Here is an example with IUIAutomationEventHandler.

The code clicks the menu items "View | Status bar" and "Organize | Layout | Navigation pane" in Windows Explorer.

Some of these menus are popup menus. When you click a button or menu item to open a popup menu you must wait a short time until the menu shows up. This is normally done with the Sleep command.

In this example an event handler is used to register the event which is fired when the popup menu shows up.

Note that the menu item names are localized. You have to change the names in the code to your own language.

 

#include "CUIAutomation2.au3"

Opt( "MustDeclareVars", 1 )

Global Const $S_OK = 0x00000000
Global Const $E_NOINTERFACE = 0x80004002
Global Const $sIID_IUnknown = "{00000000-0000-0000-C000-000000000046}"

Global $tIUIAutomationEventHandler, $oIUIAutomationEventHandler, $bEvent

Global $oUIAutomation

MainFunc()



Func MainFunc()

  ; Create UI Automation object
  $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation )
  If Not IsObj( $oUIAutomation ) Then Return

  ; Get UI Automation element for Desktop
  ; (Used in event handlers)
  Local $pDesktop
  $oUIAutomation.GetRootElement( $pDesktop )
  If Not $pDesktop Then Return

  ; Get UI Automation element for Windows Explorer
  Local $hExplorer, $pExplorer, $oExplorer
  $hExplorer = WinGetHandle( "[CLASS:CabinetWClass]" ) ; Windows 7, 8
  $oUIAutomation.ElementFromHandle( $hExplorer, $pExplorer )
  $oExplorer = ObjCreateInterface( $pExplorer, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oExplorer ) Then Return
  WinActivate( $hExplorer )

  ; --- Click "View | Status bar" ---

  ConsoleWrite( @CRLF & "--- Click ""View | Status bar"" ---" & @CRLF & @CRLF )

  ; Condition to find menubar
  Local $pCondition
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_MenuBarControlTypeId, $pCondition )
  If Not $pCondition Then Return

  ; Find menubar
  Local $pMenubar, $oMenubar
  $oExplorer.FindFirst( $TreeScope_Descendants, $pCondition, $pMenubar )
  $oMenubar = ObjCreateInterface( $pMenubar, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oMenubar ) Then Return

  ; Condition to find View menu item
  Local $pCondition1, $pCondition2
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_MenuItemControlTypeId, $pCondition1 )
  $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "View", $pCondition2 )
  $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition )
  If Not $pCondition Then Return

  ; Find View menu item
  Local $pMenuItem, $oMenuItem
  $oMenubar.FindFirst( $TreeScope_Descendants, $pCondition, $pMenuItem )
  $oMenuItem = ObjCreateInterface( $pMenuItem, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oMenuItem ) Then Return

  ; Next step is to click the View menu item
  ; Before we do that we'll set up an event handler to report the menu open event
  ; We'll do that instead of just waiting e.g. 150 ms for the menu to open

  ; Create UI Automation event handler to report menu open events
  $oIUIAutomationEventHandler = ObjectFromTag( "oIUIAutomationEventHandler_", $dtagIUIAutomationEventHandler, $tIUIAutomationEventHandler, True )
  If $oUIAutomation.AddAutomationEventHandler( $UIA_MenuOpenedEventId, $pDesktop, $TreeScope_Subtree, 0, $oIUIAutomationEventHandler ) Then Return

  ; Click (DoDefaultAction) View menu item
  Local $pLegacyMenu, $oLegacyMenu
  $oMenuItem.GetCurrentPattern( $UIA_LegacyIAccessiblePatternId, $pLegacyMenu )
  $oLegacyMenu = ObjCreateInterface( $pLegacyMenu, $sIID_IUIAutomationLegacyIAccessiblePattern, $dtagIUIAutomationLegacyIAccessiblePattern )
  If Not IsObj( $oLegacyMenu ) Then Return
  $oLegacyMenu.DoDefaultAction()
  ConsoleWrite( @CRLF & "View menu item clicked" & @CRLF & @CRLF )
  ;Sleep(150)

  ; Wait for menu open event
  $bEvent = 0
  Local $i = 0
  While Not $bEvent And $i < 20
    Sleep(10)
    $i += 1
  WEnd
  ConsoleWrite( "Number of 10 ms wait loops: " & $i & @CRLF & @CRLF )

  ; Remove event handler
  $oUIAutomation.RemoveAutomationEventHandler( $UIA_MenuOpenedEventId, $pDesktop, $oIUIAutomationEventHandler )
  $oIUIAutomationEventHandler = 0
  DeleteObjectFromTag( $tIUIAutomationEventHandler )

  ; Get UI Automation element for Desktop
  Local $pDesktop2, $oDesktop2
  $oUIAutomation.GetRootElement( $pDesktop2 ) ; Desktop
  $oDesktop2 = ObjCreateInterface( $pDesktop2, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oDesktop2 ) Then Return

  ; Find popup (Context) menu
  Local $pContext, $oContext
  $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "#32768", $pCondition )
  $oDesktop2.FindFirst( $TreeScope_Descendants, $pCondition, $pContext )
  $oContext = ObjCreateInterface( $pContext, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oContext ) Then Return
  ConsoleWrite( @CRLF & "Context menu 1:" & @CRLF & @CRLF )
  ListDescendants( $oContext, 0, 0 )

  ; Condition to find "Status bar" menu item
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_MenuItemControlTypeId, $pCondition1 )
  $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Status bar", $pCondition2 )
  $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition )
  If Not $pCondition Then Return

  ; Find "Status bar" menu item
  $oContext.FindFirst( $TreeScope_Descendants, $pCondition, $pMenuItem )
  $oMenuItem = ObjCreateInterface( $pMenuItem, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oMenuItem ) Then Return

  ; Click (Invoke) "Status bar" menu item
  Local $pInvoke, $oInvoke
  $oMenuItem.GetCurrentPattern( $UIA_InvokePatternId, $pInvoke )
  $oInvoke = ObjCreateInterface( $pInvoke, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern )
  If Not IsObj( $oInvoke ) Then Return
  $oInvoke.Invoke()
  ConsoleWrite( """Status bar"" menu item clicked" & @CRLF & @CRLF )

  ; --- Click "Organize | Layout | Navigation pane" ---

  ConsoleWrite( "--- Click ""Organize | Layout | Navigation pane"" ---" & @CRLF & @CRLF )

  ; Condition to find Organize button
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ButtonControlTypeId, $pCondition1 )
  $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Organize", $pCondition2 )
  $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition )
  If Not $pCondition Then Return

  ; Find Organize button
  Local $pButton, $oButton
  $oExplorer.FindFirst( $TreeScope_Descendants, $pCondition, $pButton )
  $oButton = ObjCreateInterface( $pButton, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oButton ) Then Return

  ; Next step is to click the Organize button
  ; Before we do that we'll set up an event handler to report the menu open event
  ; We'll do that instead of just waiting e.g. 150 ms for the menu to open

  ; Create UI Automation event handler to report menu open events
  $oIUIAutomationEventHandler = ObjectFromTag( "oIUIAutomationEventHandler_", $dtagIUIAutomationEventHandler, $tIUIAutomationEventHandler, True )
  If $oUIAutomation.AddAutomationEventHandler( $UIA_MenuOpenedEventId, $pDesktop, $TreeScope_Subtree, 0, $oIUIAutomationEventHandler ) Then Return

  ; Click (Invoke) Organize button
  $oButton.GetCurrentPattern( $UIA_InvokePatternId, $pInvoke )
  $oInvoke = ObjCreateInterface( $pInvoke, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern )
  If Not IsObj( $oInvoke ) Then Return
  $oInvoke.Invoke()
  ConsoleWrite( @CRLF & "Organize button clicked" & @CRLF & @CRLF )
  ;Sleep(150)

  ; Wait for menu open event
  $bEvent = 0
  Local $i = 0
  While Not $bEvent And $i < 20
    Sleep(10)
    $i += 1
  WEnd
  ConsoleWrite( "Number of 10 ms wait loops: " & $i & @CRLF & @CRLF )

  ; Remove event handler
  $oUIAutomation.RemoveAutomationEventHandler( $UIA_MenuOpenedEventId, $pDesktop, $oIUIAutomationEventHandler )
  $oIUIAutomationEventHandler = 0
  DeleteObjectFromTag( $tIUIAutomationEventHandler )

  ; Get UI Automation element for Desktop
  $oUIAutomation.GetRootElement( $pDesktop2 ) ; Desktop
  $oDesktop2 = ObjCreateInterface( $pDesktop2, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oDesktop2 ) Then Return

  ; Find popup (Context) menu
  $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "#32768", $pCondition )
  $oDesktop2.FindFirst( $TreeScope_Descendants, $pCondition, $pContext )
  $oContext = ObjCreateInterface( $pContext, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oContext ) Then Return
  ConsoleWrite( @CRLF & "Context menu 2:" & @CRLF & @CRLF )
  ListDescendants( $oContext, 0, 0 )

  ; Condition to find Layout menu item
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_MenuItemControlTypeId, $pCondition1 )
  $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Layout", $pCondition2 )
  $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition )
  If Not $pCondition Then Return

  ; Find Layout menu item
  $oContext.FindFirst( $TreeScope_Descendants, $pCondition, $pMenuItem )
  $oMenuItem = ObjCreateInterface( $pMenuItem, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oMenuItem ) Then Return

  ; Next step is to expand the Layout menu
  ; Before we do that we'll set up an event handler to report the menu open event
  ; We'll do that instead of just waiting e.g. 150 ms for the menu to open

  ; Create UI Automation event handler to report menu open events
  $oIUIAutomationEventHandler = ObjectFromTag( "oIUIAutomationEventHandler_", $dtagIUIAutomationEventHandler, $tIUIAutomationEventHandler, True )
  If $oUIAutomation.AddAutomationEventHandler( $UIA_MenuOpenedEventId, $pDesktop, $TreeScope_Subtree, 0, $oIUIAutomationEventHandler ) Then Return

  ; Expand Layout menu
  Local $pExpand, $oExpand
  $oMenuItem.GetCurrentPattern( $UIA_ExpandCollapsePatternId, $pExpand )
  $oExpand = ObjCreateInterface( $pExpand, $sIID_IUIAutomationExpandCollapsePattern, $dtagIUIAutomationExpandCollapsePattern )
  If Not IsObj( $oExpand ) Then Return
  $oExpand.Expand()
  ConsoleWrite( @CRLF & "Layout menu expanded" & @CRLF & @CRLF )
  ;Sleep(150)

  ; Wait for menu open event
  $bEvent = 0
  Local $i = 0
  While Not $bEvent And $i < 20
    Sleep(10)
    $i += 1
  WEnd
  ConsoleWrite( "Number of 10 ms wait loops: " & $i & @CRLF & @CRLF )

  ; Remove event handler
  $oUIAutomation.RemoveAutomationEventHandler( $UIA_MenuOpenedEventId, $pDesktop, $oIUIAutomationEventHandler )
  $oIUIAutomationEventHandler = 0
  DeleteObjectFromTag( $tIUIAutomationEventHandler )

  ; Get UI Automation element for Desktop
  $oUIAutomation.GetRootElement( $pDesktop2 ) ; Desktop
  $oDesktop2 = ObjCreateInterface( $pDesktop2, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oDesktop2 ) Then Return

  ; Condition to find Layout menu
  $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "#32768", $pCondition1 )
  $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Layout", $pCondition2 )
  $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition )
  If Not $pCondition Then Return

  ; Find Layout menu
  $oDesktop2.FindFirst( $TreeScope_Descendants, $pCondition, $pContext )
  $oContext = ObjCreateInterface( $pContext, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oContext ) Then Return
  ConsoleWrite( @CRLF & "Context menu 3:" & @CRLF & @CRLF )
  ListDescendants( $oContext, 0, 0 )

  ; Condition to find "Navigation pane" menu item
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_MenuItemControlTypeId, $pCondition1 )
  $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Navigation pane", $pCondition2 )
  $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition )
  If Not $pCondition Then Return

  ; Find "Navigation pane" menu item
  $oContext.FindFirst( $TreeScope_Descendants, $pCondition, $pMenuItem )
  $oMenuItem = ObjCreateInterface( $pMenuItem, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oMenuItem ) Then Return

  ; Click (Invoke) "Navigation pane" menu item
  $oMenuItem.GetCurrentPattern( $UIA_InvokePatternId, $pInvoke )
  $oInvoke = ObjCreateInterface( $pInvoke, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern )
  If Not IsObj( $oInvoke ) Then Return
  $oInvoke.Invoke()
  ConsoleWrite( """Navigation pane"" menu item clicked" & @CRLF & @CRLF )

EndFunc



Func oIUIAutomationEventHandler_HandleAutomationEvent( $pSelf, $pSender, $iEventId ) ; Ret: long  Par: ptr;int
  ConsoleWrite( @CRLF & "oIUIAutomationEventHandler_HandleAutomationEvent: " & $iEventId & @CRLF )
  Local $oSender = ObjCreateInterface( $pSender, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  $oSender.AddRef()
  ConsoleWrite( @CRLF & _
                "Name      = " & _UIA_getPropertyValue( $oSender, $UIA_NamePropertyId ) & @CRLF & _
                "Class     = " & _UIA_getPropertyValue( $oSender, $UIA_ClassNamePropertyId ) & @CRLF & _
                "Ctrl type = " & _UIA_getPropertyValue( $oSender, $UIA_ControlTypePropertyId ) & @CRLF & _
                "Ctrl name = " & _UIA_getPropertyValue( $oSender, $UIA_LocalizedControlTypePropertyId ) & @CRLF & _
                "Value     = " & _UIA_getPropertyValue( $oSender, $UIA_LegacyIAccessibleValuePropertyId ) & @CRLF & _
                "Handle    = " & Hex( _UIA_getPropertyValue( $oSender, $UIA_NativeWindowHandlePropertyId ) ) & @CRLF & @CRLF )
  $bEvent = 1
EndFunc

Func oIUIAutomationEventHandler_QueryInterface( $pSelf, $pRIID, $pObj ) ; Ret: long  Par: ptr;ptr*
  Local $sIID = StringFromGUID( $pRIID )
  If $sIID = $sIID_IUnknown Then
    ConsoleWrite( "oIUIAutomationEventHandler_QueryInterface: IUnknown" & @CRLF )
    DllStructSetData( DllStructCreate( "ptr", $pObj ), 1, $pSelf )
    oIUIAutomationEventHandler_AddRef( $pSelf )
    Return $S_OK
  ElseIf $sIID = $sIID_IUIAutomationEventHandler Then
    ConsoleWrite( "oIUIAutomationEventHandler_QueryInterface: IUIAutomationEventHandler" & @CRLF )
    DllStructSetData( DllStructCreate( "ptr", $pObj ), 1, $pSelf )
    oIUIAutomationEventHandler_AddRef( $pSelf )
    Return $S_OK
  Else
    ConsoleWrite( "oIUIAutomationEventHandler_QueryInterface: " & $sIID & @CRLF )
    Return $E_NOINTERFACE
  EndIf
EndFunc

Func oIUIAutomationEventHandler_AddRef( $pSelf ) ; Ret: ulong
  ConsoleWrite( "oIUIAutomationEventHandler_AddRef" & @CRLF )
  Return 1
EndFunc

Func oIUIAutomationEventHandler_Release( $pSelf ) ; Ret: ulong
  ConsoleWrite( "oIUIAutomationEventHandler_Release" & @CRLF )
  Return 1
EndFunc



Func _UIA_getPropertyValue( $obj, $id )
  Local $tVal
  $obj.GetCurrentPropertyValue( $id, $tVal )
  If Not IsArray( $tVal ) Then Return $tVal
  Local $tStr = $tVal[0]
  For $i = 1 To UBound( $tVal ) - 1
    $tStr &= "; " & $tVal[$i]
  Next
  Return $tStr
EndFunc

; List all descendants of the parent UI element
; in a hierarchical structure like a treeview.
Func ListDescendants( $oParent, $iLevel, $iLevels = 0 )

  If Not IsObj( $oParent ) Then Return
  If $iLevels And $iLevel = $iLevels Then Return

  Local $pRawWalker, $oRawWalker
  $oUIAutomation.RawViewWalker( $pRawWalker )
  $oRawWalker = ObjCreateInterface( $pRawWalker, $sIID_IUIAutomationTreeWalker, $dtagIUIAutomationTreeWalker )

  Local $pUIElement, $oUIElement
  $oRawWalker.GetFirstChildElement( $oParent, $pUIElement )
  $oUIElement = ObjCreateInterface( $pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )

  Local $sIndent = ""
  For $i = 0 To $iLevel - 1
    $sIndent &= "    "
  Next

  While IsObj( $oUIElement )
    ConsoleWrite( $sIndent & "Name      = " & _UIA_getPropertyValue( $oUIElement, $UIA_NamePropertyId ) & @CRLF & _
                  $sIndent & "Class     = " & _UIA_getPropertyValue( $oUIElement, $UIA_ClassNamePropertyId ) & @CRLF & _
                  $sIndent & "Ctrl type = " & _UIA_getPropertyValue( $oUIElement, $UIA_ControlTypePropertyId ) & @CRLF & _
                  $sIndent & "Ctrl name = " & _UIA_getPropertyValue( $oUIElement, $UIA_LocalizedControlTypePropertyId ) & @CRLF & _
                  $sIndent & "Value     = " & _UIA_getPropertyValue( $oUIElement, $UIA_LegacyIAccessibleValuePropertyId ) & @CRLF & _
                  $sIndent & "Handle    = " & Hex( _UIA_getPropertyValue( $oUIElement, $UIA_NativeWindowHandlePropertyId ) ) & @CRLF & @CRLF )

    ListDescendants( $oUIElement, $iLevel + 1, $iLevels )

    $oRawWalker.GetNextSiblingElement( $oUIElement, $pUIElement )
    $oUIElement = ObjCreateInterface( $pUIElement, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  WEnd

EndFunc



Func StringFromGUID( $pGUID )
  Local $aResult = DllCall( "ole32.dll", "int", "StringFromGUID2", "struct*", $pGUID, "wstr", "", "int", 40 )
  If @error Then Return SetError( @error, @extended, "" )
  Return SetExtended( $aResult[0], $aResult[2] )
EndFunc

; Copied and slightly modified (print methods) from this post by trancexx:
; http://www.autoitscript.com/forum/topic/153520-iuiautomation-ms-framework-automate-chrome-ff-ie/page*#entry1143566
Func ObjectFromTag($sFunctionPrefix, $tagInterface, ByRef $tInterface, $fPrint = False, $bIsUnknown = Default, $sIID = "{00000000-0000-0000-C000-000000000046}") ; last param is IID_IUnknown by default
    If $bIsUnknown = Default Then $bIsUnknown = True
    Local $sInterface = $tagInterface ; copy interface description
    Local $tagIUnknown = "QueryInterface hresult(ptr;ptr*);" & _
            "AddRef dword();" & _
            "Release dword();"
    ; Adding IUnknown methods
    If $bIsUnknown Then $tagInterface = $tagIUnknown & $tagInterface
    ; Below line is really simple even though it looks super complex. It's just written weird to fit in one line, not to steal your attention
    Local $aMethods = StringSplit(StringReplace(StringReplace(StringReplace(StringReplace(StringTrimRight(StringReplace(StringRegExpReplace(StringRegExpReplace($tagInterface, "\w+\*", "ptr"), "\h*(\w+)\h*(\w+\*?)\h*(\((.*?)\))\h*(;|;*\z)", "$1\|$2;$4" & @LF), ";" & @LF, @LF), 1), "object", "idispatch"), "hresult", "long"), "bstr", "ptr"), "variant", "ptr"), @LF, 3)
    Local $iUbound = UBound($aMethods)
    Local $sMethod, $aSplit, $sNamePart, $aTagPart, $sTagPart, $sRet, $sParams, $hCallback
    ; Allocation
    $tInterface = DllStructCreate("int RefCount;int Size;ptr Object;ptr Methods[" & $iUbound & "];int_ptr Callbacks[" & $iUbound & "];ulong_ptr Slots[16]") ; 16 pointer sized elements more to create space for possible private props
    If @error Then Return SetError(1, 0, 0)
    For $i = 0 To $iUbound - 1
        $aSplit = StringSplit($aMethods[$i], "|", 2)
        If UBound($aSplit) <> 2 Then ReDim $aSplit[2]
        $sNamePart = $aSplit[0]
        $sTagPart = $aSplit[1]
        $sMethod = $sFunctionPrefix & $sNamePart
        If $fPrint Then
            Local $iPar = StringInStr( $sTagPart, ";", 2 ), $t
            If $iPar Then
                $t = "Ret: " & StringLeft( $sTagPart, $iPar - 1 ) & "  " & _
                     "Par: " & StringRight( $sTagPart, StringLen( $sTagPart ) - $iPar )
            Else
                $t = "Ret: " & $sTagPart
            EndIf
            Local $s = "Func " & $sMethod & _
                "( $pSelf ) ; " & $t & @CRLF & _
                "EndFunc" & @CRLF
            ConsoleWrite( $s )
        EndIf
        $aTagPart = StringSplit($sTagPart, ";", 2)
        $sRet = $aTagPart[0]
        $sParams = StringReplace($sTagPart, $sRet, "", 1)
        $sParams = "ptr" & $sParams
        $hCallback = DllCallbackRegister($sMethod, $sRet, $sParams)
        ConsoleWrite(@error & @CRLF & @CRLF)
        DllStructSetData($tInterface, "Methods", DllCallbackGetPtr($hCallback), $i + 1) ; save callback pointer
        DllStructSetData($tInterface, "Callbacks", $hCallback, $i + 1) ; save callback handle
    Next
    DllStructSetData($tInterface, "RefCount", 1) ; initial ref count is 1
    DllStructSetData($tInterface, "Size", $iUbound) ; number of interface methods
    DllStructSetData($tInterface, "Object", DllStructGetPtr($tInterface, "Methods")) ; Interface method pointers
    Return ObjCreateInterface(DllStructGetPtr($tInterface, "Object"), $sIID, $sInterface, $bIsUnknown) ; pointer that's wrapped into object
EndFunc

Func DeleteObjectFromTag(ByRef $tInterface)
    For $i = 1 To DllStructGetData($tInterface, "Size")
        DllCallbackFree(DllStructGetData($tInterface, "Callbacks", $i))
    Next
    $tInterface = 0
EndFunc

Here is the output in Scite console:

--- Click "View | Status bar" ---

Func oIUIAutomationEventHandler_QueryInterface( $pSelf ) ; Ret: long  Par: ptr;ptr
EndFunc
0

Func oIUIAutomationEventHandler_AddRef( $pSelf ) ; Ret: dword
EndFunc
0

Func oIUIAutomationEventHandler_Release( $pSelf ) ; Ret: dword
EndFunc
0

Func oIUIAutomationEventHandler_HandleAutomationEvent( $pSelf ) ; Ret: long  Par: ptr;int
EndFunc
0

oIUIAutomationEventHandler_QueryInterface: IUnknown
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_QueryInterface: {0000001B-0000-0000-C000-000000000046}
oIUIAutomationEventHandler_QueryInterface: {00000003-0000-0000-C000-000000000046}
oIUIAutomationEventHandler_AddRef

View menu item clicked

oIUIAutomationEventHandler_QueryInterface: {0000001B-0000-0000-C000-000000000046}
oIUIAutomationEventHandler_QueryInterface: IUnknown
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_QueryInterface: {00000018-0000-0000-C000-000000000046}
oIUIAutomationEventHandler_QueryInterface: {00000019-0000-0000-C000-000000000046}
oIUIAutomationEventHandler_QueryInterface: {4C1E39E1-E3E3-4296-AA86-EC938D896E92}
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_QueryInterface: IUIAutomationEventHandler
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_QueryInterface: {1C733A30-2A1C-11CE-ADE5-00AA0044773D}
oIUIAutomationEventHandler_QueryInterface: IUIAutomationEventHandler
oIUIAutomationEventHandler_AddRef

oIUIAutomationEventHandler_HandleAutomationEvent: 20003

Name      = Context
Class     = #32768
Ctrl type = 50009
Ctrl name = menu
Value     = 
Handle    = 002805CC

Number of 10 ms wait loops: 4

oIUIAutomationEventHandler_QueryInterface: IUnknown
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_QueryInterface: IUnknown
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release

Context menu 1:

Name      = Status bar
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = 
Class     = 
Ctrl type = 50038
Ctrl name = separator
Value     = 
Handle    = 00000000

Name      = Extra large icons
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = Large icons
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = Medium icons
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = Small icons
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = List
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = Details
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = Tiles
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = Content
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = 
Class     = 
Ctrl type = 50038
Ctrl name = separator
Value     = 
Handle    = 00000000

Name      = Sort by
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = Group by
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = 
Class     = 
Ctrl type = 50038
Ctrl name = separator
Value     = 
Handle    = 00000000

Name      = Choose details...
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = Customize this folder...
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = 
Class     = 
Ctrl type = 50038
Ctrl name = separator
Value     = 
Handle    = 00000000

Name      = Go To
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = Refresh
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

"Status bar" menu item clicked

--- Click "Organize | Layout | Navigation pane" ---

Func oIUIAutomationEventHandler_QueryInterface( $pSelf ) ; Ret: long  Par: ptr;ptr
EndFunc
0

Func oIUIAutomationEventHandler_AddRef( $pSelf ) ; Ret: dword
EndFunc
0

Func oIUIAutomationEventHandler_Release( $pSelf ) ; Ret: dword
EndFunc
0

Func oIUIAutomationEventHandler_HandleAutomationEvent( $pSelf ) ; Ret: long  Par: ptr;int
EndFunc
0

oIUIAutomationEventHandler_QueryInterface: IUnknown
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_QueryInterface: {0000001B-0000-0000-C000-000000000046}
oIUIAutomationEventHandler_QueryInterface: {00000003-0000-0000-C000-000000000046}
oIUIAutomationEventHandler_AddRef

Organize button clicked

oIUIAutomationEventHandler_QueryInterface: {0000001B-0000-0000-C000-000000000046}
oIUIAutomationEventHandler_QueryInterface: IUnknown
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_QueryInterface: {00000018-0000-0000-C000-000000000046}
oIUIAutomationEventHandler_QueryInterface: {00000019-0000-0000-C000-000000000046}
oIUIAutomationEventHandler_QueryInterface: {4C1E39E1-E3E3-4296-AA86-EC938D896E92}
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_QueryInterface: IUIAutomationEventHandler
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_QueryInterface: {1C733A30-2A1C-11CE-ADE5-00AA0044773D}
oIUIAutomationEventHandler_QueryInterface: IUIAutomationEventHandler
oIUIAutomationEventHandler_AddRef

oIUIAutomationEventHandler_HandleAutomationEvent: 20003

Name      = Context
Class     = #32768
Ctrl type = 50009
Ctrl name = menu
Value     = 
Handle    = 002705B0

Number of 10 ms wait loops: 4

oIUIAutomationEventHandler_QueryInterface: IUnknown
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_QueryInterface: IUnknown
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release

Context menu 2:

Name      = Cut
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = Copy
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = Paste
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = Undo
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = Redo
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = 
Class     = 
Ctrl type = 50038
Ctrl name = separator
Value     = 
Handle    = 00000000

Name      = Select all
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = 
Class     = 
Ctrl type = 50038
Ctrl name = separator
Value     = 
Handle    = 00000000

Name      = Layout
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = Folder and search options
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = 
Class     = 
Ctrl type = 50038
Ctrl name = separator
Value     = 
Handle    = 00000000

Name      = Delete
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = Rename
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = Remove properties
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = Properties
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = 
Class     = 
Ctrl type = 50038
Ctrl name = separator
Value     = 
Handle    = 00000000

Name      = Close
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Func oIUIAutomationEventHandler_QueryInterface( $pSelf ) ; Ret: long  Par: ptr;ptr
EndFunc
0

Func oIUIAutomationEventHandler_AddRef( $pSelf ) ; Ret: dword
EndFunc
0

Func oIUIAutomationEventHandler_Release( $pSelf ) ; Ret: dword
EndFunc
0

Func oIUIAutomationEventHandler_HandleAutomationEvent( $pSelf ) ; Ret: long  Par: ptr;int
EndFunc
0

oIUIAutomationEventHandler_QueryInterface: IUnknown
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_QueryInterface: {0000001B-0000-0000-C000-000000000046}
oIUIAutomationEventHandler_QueryInterface: {00000003-0000-0000-C000-000000000046}
oIUIAutomationEventHandler_AddRef

Layout menu expanded

oIUIAutomationEventHandler_QueryInterface: {0000001B-0000-0000-C000-000000000046}
oIUIAutomationEventHandler_QueryInterface: IUnknown
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_QueryInterface: {00000018-0000-0000-C000-000000000046}
oIUIAutomationEventHandler_QueryInterface: {00000019-0000-0000-C000-000000000046}
oIUIAutomationEventHandler_QueryInterface: {4C1E39E1-E3E3-4296-AA86-EC938D896E92}
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_QueryInterface: IUIAutomationEventHandler
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_QueryInterface: {1C733A30-2A1C-11CE-ADE5-00AA0044773D}
oIUIAutomationEventHandler_QueryInterface: IUIAutomationEventHandler
oIUIAutomationEventHandler_AddRef

oIUIAutomationEventHandler_HandleAutomationEvent: 20003

Name      = Layout
Class     = #32768
Ctrl type = 50009
Ctrl name = menu
Value     = 
Handle    = 00270630

Number of 10 ms wait loops: 3

oIUIAutomationEventHandler_QueryInterface: IUnknown
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_QueryInterface: IUnknown
oIUIAutomationEventHandler_AddRef
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release
oIUIAutomationEventHandler_Release

Context menu 3:

Name      = Menu bar
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = 
Class     = 
Ctrl type = 50038
Ctrl name = separator
Value     = 
Handle    = 00000000

Name      = Details pane
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = Preview pane
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

Name      = Navigation pane
Class     = 
Ctrl type = 50011
Ctrl name = menu item
Value     = 
Handle    = 00000000

"Navigation pane" menu item clicked

Tested on Win 7. Doesn't work on XP or Vista. If you are running a 64 bit windows you must run the script as a 64 bit program.

Share this post


Link to post
Share on other sites

Thank you 

junkew

 

I understood what's the thing, when you showed me the example with calculator. As far as I understood we must follow the hierarchy of the elements

I am trying to use function findThemAll($oElement,$treescope_subtree)

but I get the error

Unknown function name.:
findThemAll($oElement,$treescope_subtree)
^ ERROR

May be I forgot to add some include?

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <constants.au3>
#include <WinAPI.au3>
#include "CUIAutomation2.au3"
#include "UIAWrappers.au3"
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <constants.au3>
#include <WinAPI.au3>
#include <debug.au3>

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Share this post


Link to post
Share on other sites

Thank you 

junkew

 

I understood what's the thing, when you showed me the example with calculator. As far as I understood we must follow the hierarchy of the elements

 

I am trying to use function findThemAll($oElement,$treescope_subtree)

findThemAll is in 

but you should use _UIA_DumpThemAll

Share this post


Link to post
Share on other sites

SafeArrays. Some of the methods take safe arrays as parameters. According to documentation safe arrays are zero-based, one-dimensional arrays (zero-based vectors).

For UI Automation client methods apparently only three data types are used in safe arrays: integers, pointers and strings (BSTR). In case of pointers it seems to be only IUIAutomationCondition interface pointers.

This UDF implements five functions under these conditions: SafeArrayCreateVector, SafeArrayGetElement, SafeArrayPutElement, SafeArrayGetUBound and SafeArrayDestroy.

 

#include-once

#cs
Global Const $tagSAFEARRAY = _
  "ushort cDims;"      & _ ; The number of dimensions.
  "ushort fFeatures;"  & _ ; Flags, see below.
  "ulong  cbElements;" & _ ; The size of an array element.
  "ulong  cLocks;"     & _ ; The number of times the array has been locked without a corresponding unlock.
  "ptr    pvData;"     & _ ; The data.
  "ulong  cElements;"  & _ ; The number of elements in the dimension.
  "long   lLbound"         ; The lower bound of the dimension.

; fFeatures flags
Global Const $FADF_AUTO        = 0x0001 ; An array that is allocated on the stack.
Global Const $FADF_STATIC      = 0x0002 ; An array that is statically allocated.
Global Const $FADF_EMBEDDED    = 0x0004 ; An array that is embedded in a structure.
Global Const $FADF_FIXEDSIZE   = 0x0010 ; An array that may not be resized or reallocated.
Global Const $FADF_RECORD      = 0x0020 ; An array that contains records. When set, there will be a pointer to the IRecordInfo interface at negative offset 4 in the array descriptor.
Global Const $FADF_HAVEIID     = 0x0040 ; An array that has an IID identifying interface. When set, there will be a GUID at negative offset 16 in the safe array descriptor. Flag is set only when FADF_DISPATCH or FADF_UNKNOWN is also set.
Global Const $FADF_HAVEVARTYPE = 0x0080 ; An array that has a variant type. The variant type can be retrieved with SafeArrayGetVartype.
Global Const $FADF_BSTR        = 0x0100 ; An array of BSTRs.
Global Const $FADF_UNKNOWN     = 0x0200 ; An array of IUnknown*.
Global Const $FADF_DISPATCH    = 0x0400 ; An array of IDispatch*.
Global Const $FADF_VARIANT     = 0x0800 ; An array of VARIANTs.
Global Const $FADF_RESERVED    = 0xF008 ; Bits reserved for future use.
#ce



Func SafeArrayCreateVector( $sType, $iRows )
  Local Const $tagSAFEARRAY = "ushort cDims; ushort fFeatures; ulong cbElements; ulong cLocks; ptr pvData; ulong cElements; long lLbound"
  Local Const $FADF_HAVEIID = 0x0040, $FADF_HAVEVARTYPE = 0x0080, $FADF_BSTR = 0x0100, $FADF_UNKNOWN = 0x0200
  Local Const $VT_INT = 22, $VT_INT_PTR = 37

  Local $iVarType, $iFeatures
  Switch $sType
    Case "int"
      $iVarType = $VT_INT
    Case "ptr" ; IUIAutomationCondition interface pointer
      $iVarType = $VT_INT_PTR
      $iFeatures = $FADF_UNKNOWN
      ; $FADF_UNKNOWN must be included in fFeatures in the SafeArray structure.
      ; Otherwise an E_INVALIDARG error will occur when the condition is created.
      If @OSVersion <> "WIN_XP" Then $iFeatures = BitOR( $iFeatures, $FADF_HAVEIID )
      ; On Windows later than XP $FADF_HAVEIID is used instead of $FADF_HAVEVARTYPE.
    Case "str" ; BSTR (binary string)
      $iVarType = $VT_INT_PTR
      $iFeatures = $FADF_BSTR
    Case Else
      Return SetError(1, 0, 0)
  EndSwitch

  Local $aRet = DllCall( "oleaut32.dll", "ptr", "SafeArrayCreateVector", "int", $iVarType, "long", 0, "ulong", $iRows )
  If @error Then Return SetError(2, 0, 0)
  Local $pSafeArray = $aRet[0]

  Switch $sType
    Case "ptr"
      Local $tSAFEARRAY = DllStructCreate( $tagSAFEARRAY, $pSafeArray )
      Local $fFeatures = DllStructGetData( $tSAFEARRAY, "fFeatures" )
      $fFeatures = BitOR( $fFeatures, $iFeatures )
      If @OSVersion <> "WIN_XP" Then $fFeatures = BitXOR( $fFeatures, $FADF_HAVEVARTYPE )
      ; On Windows later than XP $FADF_HAVEIID is used instead of $FADF_HAVEVARTYPE.
      DllStructSetData( $tSAFEARRAY, "fFeatures", $fFeatures )
    Case "str"
      Local $tSAFEARRAY = DllStructCreate( $tagSAFEARRAY, $pSafeArray )
      Local $fFeatures = DllStructGetData( $tSAFEARRAY, "fFeatures" )
      $fFeatures = BitOR( $fFeatures, $iFeatures )
      DllStructSetData( $tSAFEARRAY, "fFeatures", $fFeatures )
  EndSwitch

  Return $pSafeArray
EndFunc

Func SafeArrayGetElement( $pSafeArray, $iIndex, ByRef $vValue )
  Local Const $tagSAFEARRAY = "ushort cDims; ushort fFeatures; ulong cbElements; ulong cLocks; ptr pvData; ulong cElements; long lLbound"
  Local Const $FADF_BSTR = 0x0100, $FADF_UNKNOWN = 0x0200

  Local $fFeatures = DllStructGetData( DllStructCreate( $tagSAFEARRAY, $pSafeArray ), "fFeatures" )

  Local $sType
  Select
    Case BitAND( $fFeatures, $FADF_BSTR ) OR BitAND( $fFeatures, $FADF_UNKNOWN )
      $sType = "ptr*"
    Case Else
      $sType = "int*"
  EndSelect

  Local $aRet = DllCall( "oleaut32.dll", "int", "SafeArrayGetElement", "ptr", $pSafeArray, "long*", $iIndex, $sType, 0 )
  If @error Then Return SetError(1, 0, 1)
  $vValue = $aRet[3]

  If BitAND( $fFeatures, $FADF_BSTR ) Then
    $vValue = SysReadString( $vValue )
    If @error Then Return SetError(2, 0, 1)
  EndIf

  Return $aRet[0]
EndFunc

Func SafeArrayPutElement( $pSafeArray, $iIndex, $vValue )
  Local Const $tagSAFEARRAY = "ushort cDims; ushort fFeatures; ulong cbElements; ulong cLocks; ptr pvData; ulong cElements; long lLbound"
  Local Const $FADF_BSTR = 0x0100, $FADF_UNKNOWN = 0x0200

  Local $tSAFEARRAY = DllStructCreate( $tagSAFEARRAY, $pSafeArray )
  Local $fFeatures = DllStructGetData( $tSAFEARRAY, "fFeatures" )

  Local $sType
  Select
    Case BitAND( $fFeatures, $FADF_BSTR )
      $sType = "ptr*"
      DllStructSetData( $tSAFEARRAY, "fFeatures", $fFeatures - $FADF_BSTR )
      ; This is a workaround. String is not inserted if $fFeatures includes $FADF_BSTR.
      $vValue = SysAllocString( $vValue )
      If @error Then Return SetError(1, 0, 1)
    Case BitAND( $fFeatures, $FADF_UNKNOWN )
      $sType = "ptr*"
      DllStructSetData( $tSAFEARRAY, "fFeatures", $fFeatures - $FADF_UNKNOWN )
      ; This is a workaround. The DllCall crashes if $fFeatures includes $FADF_UNKNOWN.
    Case Else
      $sType = "int*"
  EndSelect

  Local $aRet = DllCall( "oleaut32.dll", "int", "SafeArrayPutElement", "ptr", $pSafeArray, "long*", $iIndex, $sType, $vValue )
  If @error Then Return SetError(2, 0, 1)

  Select
    Case BitAND( $fFeatures, $FADF_BSTR ) OR BitAND( $fFeatures, $FADF_UNKNOWN )
      DllStructSetData( $tSAFEARRAY, "fFeatures", $fFeatures )
      ; This will undo the workaround.
  EndSelect

  Return $aRet[0]
EndFunc

Func SafeArrayGetUBound( $pSafeArray, ByRef $iUBound )
  Local $aRet = DllCall( "oleaut32.dll", "int", "SafeArrayGetUBound", "ptr", $pSafeArray, "uint", 1, "long*", 0 )
  If @error Then Return SetError(1, 0, 1)
  $iUBound = $aRet[3]
  Return $aRet[0]
EndFunc

Func SafeArrayDestroy( $pSafeArray )
  Local $aRet = DllCall( "oleaut32.dll", "int", "SafeArrayDestroy", "ptr", $pSafeArray )
  If @error Then Return SetError(1, 0, 1)
  Return $aRet[0]
EndFunc



; BSTR functions
; Copied and slightly modified from AutoItObject.au3 by the AutoItObject-Team

Func SysAllocString( $str )
  Local $aRet = DllCall( "oleaut32.dll", "ptr", "SysAllocString", "wstr", $str )
  If @error Then Return SetError(1, 0, 0)
  Return $aRet[0]
EndFunc

Func SysFreeString( $pBSTR )
  If Not $pBSTR Then Return SetError(1, 0, 0)
  DllCall( "oleaut32.dll", "none", "SysFreeString", "ptr", $pBSTR )
  If @error Then Return SetError(2, 0, 0)
EndFunc

Func SysReadString( $pBSTR, $iLen = -1 )
  If Not $pBSTR Then Return SetError(1, 0, "")
  If $iLen < 1 Then $iLen = SysStringLen( $pBSTR )
  If $iLen < 1 Then Return SetError(2, 0, "")
  Return DllStructGetData( DllStructCreate( "wchar[" & $iLen & "]", $pBSTR ), 1 )
EndFunc

Func SysStringLen( $pBSTR )
  If Not $pBSTR Then Return SetError(1, 0, 0)
  Local $aRet = DllCall( "oleaut32.dll", "uint", "SysStringLen", "ptr", $pBSTR )
  If @error Then Return SetError(2, 0, 0)
  Return $aRet[0]
EndFunc
SafeArray.au3

This Windows Explorer example demonstrates reading of integer and BSTR safe arrays with PollForPotentialSupportedPatterns and PollForPotentialSupportedProperties methods of the IUIAutomation interface:

#include "CUIAutomation2.au3"
#include "SafeArray.au3"

Opt( "MustDeclareVars", 1 )

MainFunc()


Func MainFunc()

  ; Get window handle for Windows Explorer
  Local $hExplorer = WinGetHandle( "[CLASS:CabinetWClass]", "" )  ; Vista, 7, 8
  ;Local $hExplorer = WinGetHandle( "[CLASS:ExploreWClass]", "" ) ; Windows XP
  If Not $hExplorer Then Return

  ; Create UI Automation object
  Local $oUIAutomation
  $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation )
  If Not IsObj( $oUIAutomation ) Then Return

  ; Get UI Automation element from window handle
  Local $pExplorer, $oExplorer
  $oUIAutomation.ElementFromHandle( $hExplorer, $pExplorer )
  $oExplorer = ObjCreateInterface( $pExplorer, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oExplorer ) Then Return

  ; Potential supported patterns for Windows Explorer top window
  Local $pPatternIds, $pPatternNames, $iUBound, $id, $name
  $oUIAutomation.PollForPotentialSupportedPatterns( $oExplorer, $pPatternIds, $pPatternNames )
  SafeArrayGetUBound( $pPatternIds, $iUBound )
  ConsoleWrite( @CRLF & "Potential supported patterns for Windows Explorer top window" & @CRLF )
  For $i = 0 To $iUBound
    SafeArrayGetElement( $pPatternIds, $i, $id )
    SafeArrayGetElement( $pPatternNames, $i, $name )
    ConsoleWrite( "  $i, $id, $name = " & $i & ", " & $id & ", " & $name & @CRLF )
  Next

  SafeArrayDestroy( $pPatternIds )
  SafeArrayDestroy( $pPatternNames )

  ; Potential supported properties for Windows Explorer top window
  Local $pPropertyIds, $pPropertyNames, $iUBound, $id, $name
  $oUIAutomation.PollForPotentialSupportedProperties( $oExplorer, $pPropertyIds, $pPropertyNames )
  SafeArrayGetUBound( $pPropertyIds, $iUBound )
  ConsoleWrite( @CRLF & "Potential supported properties for Windows Explorer top window" & @CRLF )
  For $i = 0 To $iUBound
    SafeArrayGetElement( $pPropertyIds, $i, $id )
    SafeArrayGetElement( $pPropertyNames, $i, $name )
    ConsoleWrite( "  $i, $id, $name = " & $i & ", " & $id & ", " & $name & @CRLF )
  Next

  SafeArrayDestroy( $pPropertyIds )
  SafeArrayDestroy( $pPropertyNames )

EndFunc
Tested on XP 32 bit and Win 7 64 bit. Should work on Vista and Win 8 too.

This Windows Explorer example demonstrates creation of a safe array with pointers. The code creates a CreateAndConditionFromArray condition to search for a file named Test.txt in the current folder (virtual items on Win 7, 8 are not taken into account: Test.txt must be visible in the listview). Note that the search is case sensitive.

#include "CUIAutomation2.au3"
#include "SafeArray.au3"

Opt( "MustDeclareVars", 1 )

MainFunc()


Func MainFunc()

  ; Get window handle for Windows Explorer
  Local $hExplorer = WinGetHandle( "[CLASS:CabinetWClass]", "" )  ; Vista, 7, 8
  ;Local $hExplorer = WinGetHandle( "[CLASS:ExploreWClass]", "" ) ; Windows XP
  If Not $hExplorer Then Return

  ; Create UI Automation object
  Local $oUIAutomation
  $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation )
  If Not IsObj( $oUIAutomation ) Then Return

  ; Get UI Automation element from window handle
  Local $pExplorer, $oExplorer
  $oUIAutomation.ElementFromHandle( $hExplorer, $pExplorer )
  $oExplorer = ObjCreateInterface( $pExplorer, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oExplorer ) Then Return

  ; Conditions to find "Test.txt" item in listview
  Local $pCondition1, $pCondition2
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ListItemControlTypeId, $pCondition1 )
  $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Test.txt", $pCondition2 )
  If Not $pCondition1 Or Not $pCondition2 Then Return
  ConsoleWrite( @CRLF & "Conditions to find ""Test.txt"" item in listview" & @CRLF )
  ConsoleWrite( "$pCondition1 (item) = " & Ptr( $pCondition1 ) & @CRLF )
  ConsoleWrite( "$pCondition2 (name) = " & Ptr( $pCondition2 ) & @CRLF )

  ; Create pointer SafeArray with 2 rows
  Local $ptrSafeArray = SafeArrayCreateVector( "ptr", 2 )
  ConsoleWrite( @CRLF & "Create pointer SafeArray with 2 rows" & @CRLF )
  ConsoleWrite( "$ptrSafeArray = " & $ptrSafeArray & @CRLF )

  ; Write SafeArray structure
  Local Const $tagSAFEARRAY = "ushort cDims; ushort fFeatures; ulong cbElements; ulong cLocks; ptr pvData; ulong cElements; long lLbound"
  Local $tSAFEARRAY = DllStructCreate( $tagSAFEARRAY, $ptrSafeArray )
  ConsoleWrite( @CRLF & "SafeArray structure" & @CRLF )
  ConsoleWrite( "$tSAFEARRAY size       = " & DllStructGetSize( $tSAFEARRAY ) & @CRLF )
  ConsoleWrite( "$tSAFEARRAY cDims      = " & DllStructGetData( $tSAFEARRAY, "cDims" ) & @CRLF )
  ConsoleWrite( "$tSAFEARRAY fFeatures  = " & "0x" & Hex( DllStructGetData( $tSAFEARRAY, "fFeatures" ) ) & @CRLF )
  ConsoleWrite( "$tSAFEARRAY cbElements = " & DllStructGetData( $tSAFEARRAY, "cbElements" ) & @CRLF )
  ConsoleWrite( "$tSAFEARRAY cLocks     = " & DllStructGetData( $tSAFEARRAY, "cLocks" ) & @CRLF )
  ConsoleWrite( "$tSAFEARRAY pvData     = " & DllStructGetData( $tSAFEARRAY, "pvData" ) & @CRLF )
  ConsoleWrite( "$tSAFEARRAY cElements  = " & DllStructGetData( $tSAFEARRAY, "cElements" ) & @CRLF )
  ConsoleWrite( "$tSAFEARRAY lLbound    = " & DllStructGetData( $tSAFEARRAY, "lLbound" ) & @CRLF )

  ; Put the two conditions into SafeArray
  SafeArrayPutElement( $ptrSafeArray, 0, $pCondition1 )
  SafeArrayPutElement( $ptrSafeArray, 1, $pCondition2 )
  ConsoleWrite( @CRLF & "The two conditions put into SafeArray" & @CRLF )

  ; Get and write the two conditions
  Local $pValue
  ConsoleWrite( @CRLF & "Get the two conditions" & @CRLF )
  SafeArrayGetElement( $ptrSafeArray, 0, $pValue )
  ConsoleWrite( "$pCondition1 (item) = " & Ptr( $pValue ) & @CRLF )
  SafeArrayGetElement( $ptrSafeArray, 1, $pValue )
  ConsoleWrite( "$pCondition2 (name) = " & Ptr( $pValue ) & @CRLF )

  Local $pAndCondition
  $oUIAutomation.CreateAndConditionFromArray( $ptrSafeArray, $pAndCondition )
  ConsoleWrite( @CRLF & "Create condition from SafeArray" & @CRLF )
  ConsoleWrite( "$pAndCondition = " & Ptr( $pAndCondition ) & @CRLF )

  ; Find item
  Local $pItem
  $oExplorer.FindFirst( $TreeScope_Descendants, $pAndCondition, $pItem )
  If $pItem Then
    ConsoleWrite( @CRLF & """Test.txt"" found" & @CRLF )
  Else
    ConsoleWrite( @CRLF & """Test.txt"" not found" & @CRLF )
  EndIf

  SafeArrayDestroy( $ptrSafeArray )
  ConsoleWrite( @CRLF & "Destroy SafeArray" & @CRLF & @CRLF )

EndFunc
Tested on XP 32 bit and Win 7 64 bit. Should work on Vista and Win 8 too.

Share this post


Link to post
Share on other sites

Microsoft Active Accessibility (MSAA). The IAccessible interface. Documentation.

To run this example you must replace the entire $dtagIAccessible description string in CUIAutomation2.au3 with this description:

Global $dtagIAccessible = "GetTypeInfoCount hresult(uint*);" & _ ; IDispatch
"GetTypeInfo hresult(uint;int;ptr*);" & _
"GetIDsOfNames hresult(struct*;wstr;uint;int;int);" & _
"Invoke hresult(int;struct*;int;word;ptr*;ptr*;ptr*;uint*);" & _
"get_accParent hresult(ptr*);" & _                               ; IAccessible
"get_accChildCount hresult(long*);" & _
"get_accChild hresult(variant;idispatch*);" & _
"get_accName hresult(variant;bstr*);" & _
"get_accValue hresult(variant;bstr*);" & _
"get_accDescription hresult(variant;bstr*);" & _
"get_accRole hresult(variant;variant*);" & _
"get_accState hresult(variant;variant*);" & _
"get_accHelp hresult(variant;bstr*);" & _
"get_accHelpTopic hresult(bstr*;variant;long*);" & _
"get_accKeyboardShortcut hresult(variant;bstr*);" & _
"get_accFocus hresult(struct*);" & _
"get_accSelection hresult(variant*);" & _
"get_accDefaultAction hresult(variant;bstr*);" & _
"accSelect hresult(long;variant);" & _
"accLocation hresult(long*;long*;long*;long*;variant);" & _
"accNavigate hresult(long;variant;variant*);" & _
"accHitTest hresult(long;long;variant*);" & _
"accDoDefaultAction hresult(variant);" & _
"put_accName hresult(variant;bstr);" & _
"put_accValue hresult(variant;bstr);"

Some constants and functions are defined in this UDF:

#include-once

Global Const $tagGUID = "ulong Data1;ushort Data2;ushort Data3;byte Data4[8]"

Global Const $tIID_IAccessible = DllStructCreate( $tagGUID )
DllStructSetData( $tIID_IAccessible, "Data1", 0x618736E0 )
DllStructSetData( $tIID_IAccessible, "Data2", 0x3C3D )
DllStructSetData( $tIID_IAccessible, "Data3", 0x11CF )
DllStructSetData( $tIID_IAccessible, "Data4", "0x810C00AA00389B71" )

;Global Const $tagVARIANT = "word vt;word r1;word r2;word r3;ptr data; ptr;"
If @AutoItX64 Then
  Global $tagVARIANT = "dword[6];" ; Use this form to be able to build an
Else                               ; array in function AccessibleChildren.
  Global $tagVARIANT = "dword[4];"
EndIf

Global Const $VT_EMPTY    = 0
Global Const $VT_I4       = 3
Global Const $VT_DISPATCH = 9

Global Const $S_OK                  = 0x00000000
Global Const $S_FALSE               = 0x00000001
Global Const $E_NOTIMPL             = 0x80004001
Global Const $E_NOINTERFACE         = 0x80004002
Global Const $E_FAIL                = 0x80004005
Global Const $DISP_E_MEMBERNOTFOUND = 0x80020003
Global Const $E_OUTOFMEMORY         = 0x8007000E
Global Const $E_INVALIDARG          = 0x80070057


; ========= MS Active Accessibility constants =========

; Child ID for the object itself
; (in contrast to simple child elements of the object)
Global Const $CHILDID_SELF = 0

; Navigation constants
Global Const $NAVDIR_MIN        = 0
Global Const $NAVDIR_UP         = 0x1
Global Const $NAVDIR_DOWN       = 0x2
Global Const $NAVDIR_LEFT       = 0x3
Global Const $NAVDIR_RIGHT      = 0x4
Global Const $NAVDIR_NEXT       = 0x5
Global Const $NAVDIR_PREVIOUS   = 0x6
Global Const $NAVDIR_FIRSTCHILD = 0x7
Global Const $NAVDIR_LASTCHILD  = 0x8
Global Const $NAVDIR_MAX        = 0x9

; Selection flags
Global Const $SELFLAG_NONE            = 0
Global Const $SELFLAG_TAKEFOCUS       = 0x1
Global Const $SELFLAG_TAKESELECTION   = 0x2
Global Const $SELFLAG_EXTENDSELECTION = 0x4
Global Const $SELFLAG_ADDSELECTION    = 0x8
Global Const $SELFLAG_REMOVESELECTION = 0x10
Global Const $SELFLAG_VALID           = 0x1f

; Object identifiers
Global Const $OBJID_WINDOW            = 0x00000000
Global Const $OBJID_SYSMENU           = 0xFFFFFFFF
Global Const $OBJID_TITLEBAR          = 0xFFFFFFFE
Global Const $OBJID_MENU              = 0xFFFFFFFD
Global Const $OBJID_CLIENT            = 0xFFFFFFFC
Global Const $OBJID_VSCROLL           = 0xFFFFFFFB
Global Const $OBJID_HSCROLL           = 0xFFFFFFFA
Global Const $OBJID_SIZEGRIP          = 0xFFFFFFF9
Global Const $OBJID_CARET             = 0xFFFFFFF8
Global Const $OBJID_CURSOR            = 0xFFFFFFF7
Global Const $OBJID_ALERT             = 0xFFFFFFF6
Global Const $OBJID_SOUND             = 0xFFFFFFF5
Global Const $OBJID_QUERYCLASSNAMEIDX = 0xFFFFFFF4
Global Const $OBJID_NATIVEOM          = 0xFFFFFFF0

; Object roles
Global Const $ROLE_SYSTEM_TITLEBAR           = 0x1
Global Const $ROLE_SYSTEM_MENUBAR            = 0x2
Global Const $ROLE_SYSTEM_SCROLLBAR          = 0x3
Global Const $ROLE_SYSTEM_GRIP               = 0x4
Global Const $ROLE_SYSTEM_SOUND              = 0x5
Global Const $ROLE_SYSTEM_CURSOR             = 0x6
Global Const $ROLE_SYSTEM_CARET              = 0x7
Global Const $ROLE_SYSTEM_ALERT              = 0x8
Global Const $ROLE_SYSTEM_WINDOW             = 0x9
Global Const $ROLE_SYSTEM_CLIENT             = 0xa
Global Const $ROLE_SYSTEM_MENUPOPUP          = 0xb
Global Const $ROLE_SYSTEM_MENUITEM           = 0xc
Global Const $ROLE_SYSTEM_TOOLTIP            = 0xd
Global Const $ROLE_SYSTEM_APPLICATION        = 0xe
Global Const $ROLE_SYSTEM_DOCUMENT           = 0xf
Global Const $ROLE_SYSTEM_PANE               = 0x10
Global Const $ROLE_SYSTEM_CHART              = 0x11
Global Const $ROLE_SYSTEM_DIALOG             = 0x12
Global Const $ROLE_SYSTEM_BORDER             = 0x13
Global Const $ROLE_SYSTEM_GROUPING           = 0x14
Global Const $ROLE_SYSTEM_SEPARATOR          = 0x15
Global Const $ROLE_SYSTEM_TOOLBAR            = 0x16
Global Const $ROLE_SYSTEM_STATUSBAR          = 0x17
Global Const $ROLE_SYSTEM_TABLE              = 0x18
Global Const $ROLE_SYSTEM_COLUMNHEADER       = 0x19
Global Const $ROLE_SYSTEM_ROWHEADER          = 0x1a
Global Const $ROLE_SYSTEM_COLUMN             = 0x1b
Global Const $ROLE_SYSTEM_ROW                = 0x1c
Global Const $ROLE_SYSTEM_CELL               = 0x1d
Global Const $ROLE_SYSTEM_LINK               = 0x1e
Global Const $ROLE_SYSTEM_HELPBALLOON        = 0x1f
Global Const $ROLE_SYSTEM_CHARACTER          = 0x20
Global Const $ROLE_SYSTEM_LIST               = 0x21
Global Const $ROLE_SYSTEM_LISTITEM           = 0x22
Global Const $ROLE_SYSTEM_OUTLINE            = 0x23
Global Const $ROLE_SYSTEM_OUTLINEITEM        = 0x24
Global Const $ROLE_SYSTEM_PAGETAB            = 0x25
Global Const $ROLE_SYSTEM_PROPERTYPAGE       = 0x26
Global Const $ROLE_SYSTEM_INDICATOR          = 0x27
Global Const $ROLE_SYSTEM_GRAPHIC            = 0x28
Global Const $ROLE_SYSTEM_STATICTEXT         = 0x29
Global Const $ROLE_SYSTEM_TEXT               = 0x2a
Global Const $ROLE_SYSTEM_PUSHBUTTON         = 0x2b
Global Const $ROLE_SYSTEM_CHECKBUTTON        = 0x2c
Global Const $ROLE_SYSTEM_RADIOBUTTON        = 0x2d
Global Const $ROLE_SYSTEM_COMBOBOX           = 0x2e
Global Const $ROLE_SYSTEM_DROPLIST           = 0x2f
Global Const $ROLE_SYSTEM_PROGRESSBAR        = 0x30
Global Const $ROLE_SYSTEM_DIAL               = 0x31
Global Const $ROLE_SYSTEM_HOTKEYFIELD        = 0x32
Global Const $ROLE_SYSTEM_SLIDER             = 0x33
Global Const $ROLE_SYSTEM_SPINBUTTON         = 0x34
Global Const $ROLE_SYSTEM_DIAGRAM            = 0x35
Global Const $ROLE_SYSTEM_ANIMATION          = 0x36
Global Const $ROLE_SYSTEM_EQUATION           = 0x37
Global Const $ROLE_SYSTEM_BUTTONDROPDOWN     = 0x38
Global Const $ROLE_SYSTEM_BUTTONMENU         = 0x39
Global Const $ROLE_SYSTEM_BUTTONDROPDOWNGRID = 0x3a
Global Const $ROLE_SYSTEM_WHITESPACE         = 0x3b
Global Const $ROLE_SYSTEM_PAGETABLIST        = 0x3c
Global Const $ROLE_SYSTEM_CLOCK              = 0x3d
Global Const $ROLE_SYSTEM_SPLITBUTTON        = 0x3e
Global Const $ROLE_SYSTEM_IPADDRESS          = 0x3f
Global Const $ROLE_SYSTEM_OUTLINEBUTTON      = 0x40

; Object state constants
Global Const $STATE_SYSTEM_NORMAL          = 0
Global Const $STATE_SYSTEM_UNAVAILABLE     = 0x1
Global Const $STATE_SYSTEM_SELECTED        = 0x2
Global Const $STATE_SYSTEM_FOCUSED         = 0x4
Global Const $STATE_SYSTEM_PRESSED         = 0x8
Global Const $STATE_SYSTEM_CHECKED         = 0x10
Global Const $STATE_SYSTEM_MIXED           = 0x20
Global Const $STATE_SYSTEM_INDETERMINATE   = $STATE_SYSTEM_MIXED
Global Const $STATE_SYSTEM_READONLY        = 0x40
Global Const $STATE_SYSTEM_HOTTRACKED      = 0x80
Global Const $STATE_SYSTEM_DEFAULT         = 0x100
Global Const $STATE_SYSTEM_EXPANDED        = 0x200
Global Const $STATE_SYSTEM_COLLAPSED       = 0x400
Global Const $STATE_SYSTEM_BUSY            = 0x800
Global Const $STATE_SYSTEM_FLOATING        = 0x1000
Global Const $STATE_SYSTEM_MARQUEED        = 0x2000
Global Const $STATE_SYSTEM_ANIMATED        = 0x4000
Global Const $STATE_SYSTEM_INVISIBLE       = 0x8000
Global Const $STATE_SYSTEM_OFFSCREEN       = 0x10000
Global Const $STATE_SYSTEM_SIZEABLE        = 0x20000
Global Const $STATE_SYSTEM_MOVEABLE        = 0x40000
Global Const $STATE_SYSTEM_SELFVOICING     = 0x80000
Global Const $STATE_SYSTEM_FOCUSABLE       = 0x100000
Global Const $STATE_SYSTEM_SELECTABLE      = 0x200000
Global Const $STATE_SYSTEM_LINKED          = 0x400000
Global Const $STATE_SYSTEM_TRAVERSED       = 0x800000
Global Const $STATE_SYSTEM_MULTISELECTABLE = 0x1000000
Global Const $STATE_SYSTEM_EXTSELECTABLE   = 0x2000000
Global Const $STATE_SYSTEM_ALERT_LOW       = 0x4000000
Global Const $STATE_SYSTEM_ALERT_MEDIUM    = 0x8000000
Global Const $STATE_SYSTEM_ALERT_HIGH      = 0x10000000
Global Const $STATE_SYSTEM_PROTECTED       = 0x20000000
Global Const $STATE_SYSTEM_VALID           = 0x7fffffff
Global Const $STATE_SYSTEM_HASPOPUP        = 0x40000000

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


Global Const $hdllMSAA = DllOpen( "oleacc.dll" )

OnAutoItExitRegister( "ExitMSAA" )

Func ExitMSAA()
  DllClose( $hdllMSAA )
EndFunc


Func AccessibleChildren( $paccContainer, $iChildStart, $iChildren, ByRef $tVarChildren, ByRef $iObtained )
  Local $sVarArray = ""
  For $i = 1 To $iChildren
    $sVarArray &= $tagVARIANT
  Next
  $tVarChildren = DllStructCreate( $sVarArray )
  Local $aRet = DllCall( $hdllMSAA, "int", "AccessibleChildren", "ptr", $paccContainer, "int", $iChildStart, "int", $iChildren, "struct*", $tVarChildren, "int*", 0 )
  If @error Then Return SetError(1, 0, $S_FALSE)
  If $aRet[0] Then Return SetError(2, 0, $aRet[0])
  $iObtained = $aRet[5]
  Return $S_OK
EndFunc

Func AccessibleObjectFromWindow( $hWnd, $iObjectID, $tRIID, ByRef $pObject )
  Local $aRet = DllCall( $hdllMSAA, "int", "AccessibleObjectFromWindow", "hwnd", $hWnd, "uint", $iObjectID, "struct*", $tRIID, "int*", 0 )
  If @error Then Return SetError(1, 0, $S_FALSE)
  If $aRet[0] Then Return SetError(2, 0, $aRet[0])
  $pObject = $aRet[4]
  Return $S_OK
EndFunc

Func GetRoleText( $iRole, $sRole, $iRoleMax )
  Local $aRet = DllCall( $hdllMSAA, "uint", "GetRoleText", "dword", $iRole, "ptr", $sRole, "uint", $iRoleMax )
  If @error Then Return SetError(1, 0, 0)
  If Not $aRet[0] Then Return SetError(2, 0, 0)
  Return $aRet[0]
EndFunc

Func GetStateText( $iStateBit, $sStateBit, $iStateBitMax )
  Local $aRet = DllCall( $hdllMSAA, "uint", "GetStateText", "dword", $iStateBit, "ptr", $sStateBit, "uint", $iStateBitMax )
  If @error Then Return SetError(1, 0, 0)
  If Not $aRet[0] Then Return SetError(2, 0, 0)
  Return $aRet[0]
EndFunc
MSActiveAccessibility.au3

The example displays a view of the element tree below a window or a given element. The element tree is shown in an hierarchical structure like a treeview. The example is based on a recursive procedure with the AccessibleChildren function.

#include "CUIAutomation2.au3"
#include "MSActiveAccessibility.au3"

Opt( "MustDeclareVars", 1 )

MainFunc()


Func MainFunc()

  ; Get window handle
  ;Local $hWindow = WinGetHandle( "[CLASS:Chrome_WidgetWin_1]", "" ) ; Chrome            ; http://tweepi.com/auth/login
  ;Local $hWindow = WinGetHandle( "[CLASS:IEFrame]" )                ; Internet Explorer ; http://tweepi.com/auth/login
  ;Local $hWindow = WinGetHandle( "[CLASS:CabinetWClass]" )          ; Windows Explorer, Vista, 7, 8
  ;Local $hWindow = WinGetHandle( "[CLASS:ExploreWClass]" )          ; Windows Explorer, Windows XP
  Local $hWindow = WinGetHandle( "Calculator" )                      ; Calculator
  ;Local $hWindow = ControlGetHandle("[CLASS:Notepad]", "", "Edit1") ; Notepad
  If Not $hWindow Then Return

  ; Get Window object
  Local $pWindow, $oWindow
  AccessibleObjectFromWindow( $hWindow, $OBJID_CLIENT, $tIID_IAccessible, $pWindow )
  $oWindow = ObjCreateInterface( $pWindow, $sIID_IAccessible, $dtagIAccessible )
  If Not IsObj( $oWindow ) Then Return

  ;#cs
  ; Window name
  Local $sName
  ConsoleWrite( @CRLF & "Window:" )
  ConsoleWrite( @CRLF & "-------" & @CRLF )
  PrintObjectInfo( $oWindow, $CHILDID_SELF, "" )

  ; Get children
  ConsoleWrite( "Children:" & @CRLF )
  ConsoleWrite( "---------" & @CRLF )
  WalkTreeWithAccessibleChildren( $pWindow, 0, 5 )
  ;#ce

  #cs
  ; Get parent object
  Local $pParent, $oParent
  $oWindow.get_accParent( $pParent )
  $oParent = ObjCreateInterface( $pParent, $sIID_IAccessible, $dtagIAccessible )
  If Not IsObj( $oParent ) Then Return

  ; Parent name
  Local $sName
  ConsoleWrite( @CRLF & "Parent:" )
  ConsoleWrite( @CRLF & "-------" & @CRLF )
  PrintObjectInfo( $oParent, $CHILDID_SELF, "" )

  ; Get children
  ConsoleWrite( "Children:" & @CRLF )
  ConsoleWrite( "---------" & @CRLF )
  WalkTreeWithAccessibleChildren( $pParent, 0, 5 )
  #ce

EndFunc


Func WalkTreeWithAccessibleChildren( $pAcc, $iLevel, $iLevels = 0 )

  If $iLevels And $iLevel = $iLevels Then Return

  ; Create object
  Local $oAcc = ObjCreateInterface( $pAcc, $sIID_IAccessible, $dtagIAccessible )
  If Not IsObj( $oAcc ) Then Return
  $oAcc.AddRef()

  Local $iChildCount, $iReturnCount, $tVarChildren

  ; Get children
  If $oAcc.get_accChildCount( $iChildCount ) Or Not $iChildCount Then Return
  If AccessibleChildren( $pAcc, 0, $iChildCount, $tVarChildren, $iReturnCount ) Then Return

  ; Indentation
  Local $sIndent = ""
  For $i = 0 To $iLevel - 1
    $sIndent &= "    "
  Next

  Local $vt, $pChildObj, $oChildObj, $iChildElem

  ; For each child
  For $i = 1 To $iReturnCount

    ; $tVarChildren is an array of VARIANTs with information about the children
    $vt = BitAND( DllStructGetData( $tVarChildren, $i, 1 ), 0xFFFF )

    If $vt = $VT_DISPATCH Then

      ; Child object
      $pChildObj = DllStructGetData( $tVarChildren, $i, 3 )
      $oChildObj = ObjCreateInterface( $pChildObj, $sIID_IAccessible, $dtagIAccessible )
      If IsObj( $oChildObj ) Then
        PrintObjectInfo( $oChildObj, $CHILDID_SELF, $sIndent )
        WalkTreeWithAccessibleChildren( $pChildObj, $iLevel + 1, $iLevels )
      EndIf

    Else ; $vt = $VT_I4

      ; Child element
      $iChildElem = DllStructGetData( $tVarChildren, $i, 3 )
      PrintObjectInfo( $oAcc, $iChildElem, $sIndent )

    EndIf

  Next

EndFunc


Func PrintObjectInfo( $oAcc, $iChild, $sIndent )
  Local $sName, $iRole, $sRole, $iRoleLen
  Local $iState, $sState, $iStateLen
  Local $sValue, $x, $y, $w, $h
  If $iChild <> $CHILDID_SELF Then _
    ConsoleWrite( $sIndent & "$iChildElem = " & $iChild & @CRLF )
  $oAcc.get_accName( $iChild, $sName )
  ConsoleWrite( $sIndent & "$sName  = " & $sName & @CRLF )
  If $oAcc.get_accRole( $iChild, $iRole ) = $S_OK Then
    ConsoleWrite( $sIndent & "$iRole  = 0x" & Hex( $iRole ) & @CRLF )
    $iRoleLen = GetRoleText( $iRole, 0, 0 ) + 1
    $sRole = DllStructCreate( "char[" & $iRoleLen & "]" )
    GetRoleText( $iRole, DllStructGetPtr( $sRole ), $iRoleLen )
    ConsoleWrite( $sIndent & "$sRole  = " & DllStructGetData( $sRole, 1 ) & @CRLF )
  EndIf
  If $oAcc.get_accState( $iChild, $iState ) = $S_OK Then
    ConsoleWrite( $sIndent & "$iState = 0x" & Hex( $iState ) & @CRLF )
    $iStateLen = GetStateText( $iState, 0, 0 ) + 1
    $sState = DllStructCreate( "char[" & $iStateLen & "]" )
    GetStateText( $iState, DllStructGetPtr( $sState ), $iStateLen )
    ConsoleWrite( $sIndent & "$sState = " & DllStructGetData( $sState, 1 ) & @CRLF )
  EndIf
  If $oAcc.get_accValue( $iChild, $sValue ) = $S_OK Then _
    ConsoleWrite( $sIndent & "$sValue = " & $sValue & @CRLF )
  IF $oAcc.accLocation( $x, $y, $w, $h, $iChild ) = $S_OK Then _
    ConsoleWrite( $sIndent & "$x, $y, $w, $h = " & $x & ", " & $y & ", " & $w & ", " & $h & @CRLF )
  ConsoleWrite( @CRLF )
EndFunc
Testet on XP 32 bit and Win 7 64 bit. Should work on Vista and Win 8 too.

This is output in Scite console from Calculator:

Window:
-------
$sName  = Calculator
$iRole  = 0x0000000A
$sRole  = client
$iState = 0x00100000
$sState = focusable
$x, $y, $w, $h = 918, 309, 407, 264

Children:
---------
$sName  = 0
$iRole  = 0x00000009
$sRole  = window
$iState = 0x00100000
$sState = focusable
$x, $y, $w, $h = 918, 309, 407, 264

    $sName  = System
    $iRole  = 0x00000002
    $sRole  = menu bar
    $iState = 0x00008000
    $sState = invisible

    $sName  = 0
    $iRole  = 0x00000001
    $sRole  = title bar
    $iState = 0x00008000
    $sState = invisible

        $iChildElem = 1
        $sName  = 0

        $iChildElem = 2
        $sName  = 0

        $iChildElem = 3
        $sName  = 0

        $iChildElem = 4
        $sName  = 0

        $iChildElem = 5
        $sName  = 0

    $sName  = Application
    $iRole  = 0x00000002
    $sRole  = menu bar
    $iState = 0x00008000
    $sState = invisible

    $sName  = 0
    $iRole  = 0x0000000A
    $sRole  = client
    $iState = 0x00100000
    $sState = focusable
    $x, $y, $w, $h = 918, 309, 407, 264

        $sName  = 0
        $iRole  = 0x00000009
        $sRole  = window
        $iState = 0x00100000
        $sState = focusable
        $x, $y, $w, $h = 929, 319, 385, 50

            $sName  = System
            $iRole  = 0x00000002
            $sRole  = menu bar
            $iState = 0x00008000
            $sState = invisible

            $sName  = 0
            $iRole  = 0x00000001
            $sRole  = title bar
            $iState = 0x00008000
            $sState = invisible

                $iChildElem = 1
                $sName  = 0

                $iChildElem = 2
                $sName  = 0

                $iChildElem = 3
                $sName  = 0

                $iChildElem = 4
                $sName  = 0

                $iChildElem = 5
                $sName  = 0

            $sName  = Application
            $iRole  = 0x00000002
            $sRole  = menu bar
            $iState = 0x00008000
            $sState = invisible

            $sName  = 0
            $iRole  = 0x00000028
            $sRole  = graphic
            $iState = 0x00000040
            $sState = read only
            $x, $y, $w, $h = 929, 319, 385, 50

            $sName  = Vertical
            $iRole  = 0x00000003
            $sRole  = scroll bar
            $iState = 0x00008000
            $sState = invisible
            $sValue = 0

                $iChildElem = 1
                $sName  = 0

                $iChildElem = 2
                $sName  = 0

                $iChildElem = 3
                $sName  = 0

                $iChildElem = 4
                $sName  = 0

                $iChildElem = 5
                $sName  = 0

            $sName  = Horizontal
            $iRole  = 0x00000003
            $sRole  = scroll bar
            $iState = 0x00008000
            $sState = invisible
            $sValue = 0

                $iChildElem = 1
                $sName  = 0

                $iChildElem = 2
                $sName  = 0

                $iChildElem = 3
                $sName  = 0

                $iChildElem = 4
                $sName  = 0

                $iChildElem = 5
                $sName  = 0

            $sName  = 0
            $iRole  = 0x00000004
            $sRole  = grip
            $iState = 0x00008001
            $sState = invisible

        $sName  = 0
        $iRole  = 0x00000009
        $sRole  = window
        $iState = 0x00100000
        $sState = focusable
        $x, $y, $w, $h = 929, 319, 385, 50

            $sName  = System
            $iRole  = 0x00000002
            $sRole  = menu bar
            $iState = 0x00008000
            $sState = invisible

            $sName  = 0
            $iRole  = 0x00000001
            $sRole  = title bar
            $iState = 0x00008000
            $sState = invisible

                $iChildElem = 1
                $sName  = 0

                $iChildElem = 2
                $sName  = 0

                $iChildElem = 3
                $sName  = 0

                $iChildElem = 4
                $sName  = 0

                $iChildElem = 5
                $sName  = 0

            $sName  = Application
            $iRole  = 0x00000002
            $sRole  = menu bar
            $iState = 0x00008000
            $sState = invisible

            $sName  = 0
            $iRole  = 0x00000012
            $sRole  = dialog
            $iState = 0x00100000
            $sState = focusable
            $x, $y, $w, $h = 929, 319, 385, 50

                $sName  = Running History
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 933, 322, 377, 13

                $sName  = Memory
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 929, 344, 14, 18

                $sName  = Result
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 947, 334, 362, 28

                $sName  = 0
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 947, 337, 167, 30

            $sName  = Vertical
            $iRole  = 0x00000003
            $sRole  = scroll bar
            $iState = 0x00008000
            $sState = invisible
            $sValue = 0

                $iChildElem = 1
                $sName  = 0

                $iChildElem = 2
                $sName  = 0

                $iChildElem = 3
                $sName  = 0

                $iChildElem = 4
                $sName  = 0

                $iChildElem = 5
                $sName  = 0

            $sName  = Horizontal
            $iRole  = 0x00000003
            $sRole  = scroll bar
            $iState = 0x00008000
            $sState = invisible
            $sValue = 0

                $iChildElem = 1
                $sName  = 0

                $iChildElem = 2
                $sName  = 0

                $iChildElem = 3
                $sName  = 0

                $iChildElem = 4
                $sName  = 0

                $iChildElem = 5
                $sName  = 0

            $sName  = 0
            $iRole  = 0x00000004
            $sRole  = grip
            $iState = 0x00008001
            $sState = invisible

        $sName  = 0
        $iRole  = 0x00000009
        $sRole  = window
        $iState = 0x00100000
        $sState = focusable
        $x, $y, $w, $h = 929, 374, 385, 191

            $sName  = System
            $iRole  = 0x00000002
            $sRole  = menu bar
            $iState = 0x00008000
            $sState = invisible

            $sName  = 0
            $iRole  = 0x00000001
            $sRole  = title bar
            $iState = 0x00008000
            $sState = invisible

                $iChildElem = 1
                $sName  = 0

                $iChildElem = 2
                $sName  = 0

                $iChildElem = 3
                $sName  = 0

                $iChildElem = 4
                $sName  = 0

                $iChildElem = 5
                $sName  = 0

            $sName  = Application
            $iRole  = 0x00000002
            $sRole  = menu bar
            $iState = 0x00008000
            $sState = invisible

            $sName  = 0
            $iRole  = 0x00000012
            $sRole  = dialog
            $iState = 0x00100000
            $sState = focusable
            $x, $y, $w, $h = 929, 374, 385, 191

                $sName  = Memory clear
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1124, 374, 34, 27

                $sName  = Backspace
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1124, 406, 34, 27

                $sName  = 7
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1124, 438, 34, 27

                $sName  = 4
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1124, 470, 34, 27

                $sName  = 1
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1124, 502, 34, 27

                $sName  = 0
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1124, 534, 73, 27

                $sName  = Memory recall
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1163, 374, 34, 27

                $sName  = Clear entry
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1163, 406, 34, 27

                $sName  = 8
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1163, 438, 34, 27

                $sName  = 5
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1163, 470, 34, 27

                $sName  = 2
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1163, 502, 34, 27

                $sName  = Memory store
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1202, 374, 34, 27

                $sName  = Clear
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1202, 406, 34, 27

                $sName  = 9
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1202, 438, 34, 27

                $sName  = 6
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1202, 470, 34, 27

                $sName  = 3
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1202, 502, 34, 27

                $sName  = Decimal separator
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1202, 534, 34, 27

                $sName  = Memory add
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1241, 374, 34, 27

                $sName  = Negate
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1241, 406, 34, 27

                $sName  = Divide
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1241, 438, 34, 27

                $sName  = Multiply
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1241, 470, 34, 27

                $sName  = Subtract
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1241, 502, 34, 27

                $sName  = Add
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1241, 534, 34, 27

                $sName  = Memory subtract
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1280, 374, 34, 27

                $sName  = Square root
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1280, 406, 34, 27

                $sName  = Percentage
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100001
                $sState = focusable
                $x, $y, $w, $h = 1280, 438, 34, 27

                $sName  = Reciprocal
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1280, 470, 34, 27

                $sName  = Equals
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1280, 502, 34, 59

                $sName  = 0
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 929, 374, 190, 27

                $sName  = Degrees
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 937, 379, 64, 16

                $sName  = Radians
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1001, 379, 66, 16

                $sName  = Grads
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1068, 379, 50, 16

                $sName  = 
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 929, 406, 34, 27

                $sName  = Integer part
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 929, 438, 34, 27

                $sName  = Degree minute second
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 929, 470, 34, 27

                $sName  = Pi
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 929, 502, 34, 27

                $sName  = Exponential notation
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 929, 534, 34, 27

                $sName  = Inverse functions
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 968, 406, 34, 27

                $sName  = Hyperbolic sine
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 968, 438, 34, 27

                $sName  = Hyperbolic cosine
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 968, 470, 34, 27

                $sName  = Hyperbolic tangent
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 968, 502, 34, 27

                $sName  = Exponential
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 968, 534, 34, 27

                $sName  = Natural log
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1007, 406, 34, 27

                $sName  = Sine
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1007, 438, 34, 27

                $sName  = Cosine
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1007, 470, 34, 27

                $sName  = Tangent
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1007, 502, 34, 27

                $sName  = Modulo
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1007, 534, 34, 27

                $sName  = Open parenthesis
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1046, 406, 34, 27

                $sName  = Square
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1046, 438, 34, 27

                $sName  = Raise to y power
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1046, 470, 34, 27

                $sName  = Cube
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1046, 502, 34, 27

                $sName  = Log
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1046, 534, 34, 27

                $sName  = Close parenthesis
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1085, 406, 34, 27

                $sName  = Factorial
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1085, 438, 34, 27

                $sName  = Order of y root
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1085, 470, 34, 27

                $sName  = Cube root
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1085, 502, 34, 27

                $sName  = Anti log
                $iRole  = 0x00000009
                $sRole  = window
                $iState = 0x00100000
                $sState = focusable
                $x, $y, $w, $h = 1085, 534, 34, 27

            $sName  = Vertical
            $iRole  = 0x00000003
            $sRole  = scroll bar
            $iState = 0x00008000
            $sState = invisible
            $sValue = 0

                $iChildElem = 1
                $sName  = 0

                $iChildElem = 2
                $sName  = 0

                $iChildElem = 3
                $sName  = 0

                $iChildElem = 4
                $sName  = 0

                $iChildElem = 5
                $sName  = 0

            $sName  = Horizontal
            $iRole  = 0x00000003
            $sRole  = scroll bar
            $iState = 0x00008000
            $sState = invisible
            $sValue = 0

                $iChildElem = 1
                $sName  = 0

                $iChildElem = 2
                $sName  = 0

                $iChildElem = 3
                $sName  = 0

                $iChildElem = 4
                $sName  = 0

                $iChildElem = 5
                $sName  = 0

            $sName  = 0
            $iRole  = 0x00000004
            $sRole  = grip
            $iState = 0x00008001
            $sState = invisible

        $sName  = 0
        $iRole  = 0x00000009
        $sRole  = window
        $iState = 0x00108000
        $sState = focusable
        $x, $y, $w, $h = 918, 309, 500, 500

            $sName  = System
            $iRole  = 0x00000002
            $sRole  = menu bar
            $iState = 0x00008000
            $sState = invisible

            $sName  = 0
            $iRole  = 0x00000001
            $sRole  = title bar
            $iState = 0x00008000
            $sState = invisible

                $iChildElem = 1
                $sName  = 0

                $iChildElem = 2
                $sName  = 0

                $iChildElem = 3
                $sName  = 0

                $iChildElem = 4
                $sName  = 0

                $iChildElem = 5
                $sName  = 0

            $sName  = Application
            $iRole  = 0x00000002
            $sRole  = menu bar
            $iState = 0x00008000
            $sState = invisible

            $sName  = 0
            $iRole  = 0x00000012
            $sRole  = dialog
            $iState = 0x00108000
            $sState = focusable
            $x, $y, $w, $h = 918, 309, 500, 500

            $sName  = Vertical
            $iRole  = 0x00000003
            $sRole  = scroll bar
            $iState = 0x00008000
            $sState = invisible
            $sValue = 0

                $iChildElem = 1
                $sName  = 0

                $iChildElem = 2
                $sName  = 0

                $iChildElem = 3
                $sName  = 0

                $iChildElem = 4
                $sName  = 0

                $iChildElem = 5
                $sName  = 0

            $sName  = Horizontal
            $iRole  = 0x00000003
            $sRole  = scroll bar
            $iState = 0x00008000
            $sState = invisible
            $sValue = 0

                $iChildElem = 1
                $sName  = 0

                $iChildElem = 2
                $sName  = 0

                $iChildElem = 3
                $sName  = 0

                $iChildElem = 4
                $sName  = 0

                $iChildElem = 5
                $sName  = 0

            $sName  = 0
            $iRole  = 0x00000004
            $sRole  = grip
            $iState = 0x00008001
            $sState = invisible

    $sName  = Vertical
    $iRole  = 0x00000003
    $sRole  = scroll bar
    $iState = 0x00008000
    $sState = invisible
    $sValue = 0

        $iChildElem = 1
        $sName  = 0

        $iChildElem = 2
        $sName  = 0

        $iChildElem = 3
        $sName  = 0

        $iChildElem = 4
        $sName  = 0

        $iChildElem = 5
        $sName  = 0

    $sName  = Horizontal
    $iRole  = 0x00000003
    $sRole  = scroll bar
    $iState = 0x00008000
    $sState = invisible
    $sValue = 0

        $iChildElem = 1
        $sName  = 0

        $iChildElem = 2
        $sName  = 0

        $iChildElem = 3
        $sName  = 0

        $iChildElem = 4
        $sName  = 0

        $iChildElem = 5
        $sName  = 0

    $sName  = 0
    $iRole  = 0x00000004
    $sRole  = grip
    $iState = 0x00008001
    $sState = invisible
Edited by LarsJ

Share this post


Link to post
Share on other sites

I have a question...can I use this code:

func _UIA_getPropertyValue($obj, $id)
    local $tval
    local $tStr

    if not isobj($obj) Then
        seterror(1,0,0)
        return "** NO PROPERTYVALUE DUE TO NONEXISTING OBJECT"
    EndIf
    
    $obj.GetCurrentPropertyValue($Id,$tVal)
    $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
        return $tStr
    endIf
    return $tVal
EndFunc

Running: +>16:49:54 Starting AutoIt3Wrapper v.2.1.0.33    Environment(Language:0409  Keyboard:00000409  OS:WIN_XP/Service Pack 3  CPU:X64 OS:X86)

to circumvent the error, after changing the code to fit this error?

P:AutoitAutomationUIAWrappers.au3 (657) : ==> Variable must be of type "Object".:
$obj.FindAll($treescope, $oCondition, $pElements)
$obj^ ERROR

Edit: the function that the error points to is _UIA_getObjectByFindAll

Edited by nitekram

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Share this post


Link to post
Share on other sites

junkew, If you are in the business of Windows automation you simply should implement IAccessible.

Most tasks which can be handled with IAccessible can probably also be handled with UI Automation. But may be for a given task all you need is IAccessible. Why power up the huge UI Automation if all you need is IAccessible?

I also think that IAccessible has a justification together with IAccessible2. Have you been looking into IAccessible2?

With IUIAutomationLegacyIAccessiblePattern.GetIAccessible you can get a pointer for IAccessible. I have tested this. It works. The description for GetIAccessible should be this string:

"GetIAccessible hresult(ptr*);"

May I ask if you are preparing or working on a new version of the UDFs and the Spy script?

Regards Lars.

Share this post


Link to post
Share on other sites