Popular Post LarsJ Posted January 31, 2019 Author Popular Post Share Posted January 31, 2019 (edited) How to topics, 1 - 7 How to topics is a guide to use UIASpy to identify windows and controls and to create sample code to obtain information and perform actions. Topics 1 - 7: Introductory topicsTop of next post (bottom of this post) Topics 8 - 15: Sample code creation Topics 16 - 17: Other How to topics How to perform UI Automation tasks How to use UIASpy to detect elements How to use UIASpy to create sample code How to create sample code through Detail info page How to create sample code through Sample code menu How to create sample code by copying listview rows How to create objects with ObjCreateInterface How to create UI Automation main objects How to identify and find application top window How to identify and find UI elements (controls) How to get UI element property values How to create element action objects How to get pattern property values How to perform element actions How to create executable code How to perform a mouse click in middle of bounding rectangle How to perform a control click via PostMessage and $UIA_AutomationIdPropertyId 1. How to perform UI Automation tasks UI Automation tasks are almost always performed in a top-down and step-by-step procedure. The task is divided into smaller sub-tasks that cannot be further divided. Each sub-task is performed in 2-4 steps. Clicking a button in a window is divided into 2 sub-tasks: Identify the window Identify and click the button The window that's identified in the first sub-task is used to identify the button in the second sub-task. Identifying the window is done in 2 steps: Create condition to identify the window Find the window based on the condition Identifying and clicking the button is done in 4 steps: Create condition to identify the button Find the button based on the condition Create an action to click the button Perform the action and click the button Here, the procedure is illustrated schematically: UIASpy can provide information to identify windows and controls and can generate sample code to implement the 2-4 steps. 2. How to use UIASpy to detect elementsOpen UIASpy. Click Left pane | Delete top windows to delete all treeview top windows. To detect a window, place the mouse cursor over the window title bar and press F2. To detect a control, place the mouse cursor over the control and press F1. Switch back to UIASpy window. 3. How to use UIASpy to create Sample code Through Sample code creation, you can more or less create all code in a simple automation task: Create UI Automation initial code Create condition and find application window Create condition and find control in window Get information about windows and controls Create pattern objects to perform actions Get information related to pattern objects Perform actions with pattern object methods Add a Sleep() statement if necessary In short, there are 3 ways to create sample code with UIASpy: Use the UIASpy Sample code main menu Right click a selected row in the Detail info listview page and Click Create sample code to create code based on selected row(s) Right click a selected row in the Detail info listview page or in a Sample code listview page and Click Copy to sample code to copy variable names and values to sample code (preferred) or Click Copy selected items to copy variable names and values to clipboard Then paste the code into an editor. 4. How to create sample code through Detail info page The Detail info listview page is also the default listview page. This makes sample code creation easy and fast. You can find a brief description with pictures and code snippets in the UIASpy thread. But not all code can be created this way. In many cases, there is a need to use the Sample code main menu. 5. How to create sample code through Sample code menu Much more code can be created through the Sample code menu than through the Detail info page. In addition, the menu can be used to set Sample code options and for Sample code maintenance. You can find a brief description with a picture in the UIASpy thread. 6. How to create sample code by copying listview rows To copy information from the Detail info listview page or a Sample code listview page into the editor right-click a selected row and click Copy to sample code: Paste the code into the editor: ; --- Copy element info --- ; $UIA_NativeWindowHandlePropertyId 0x00090244 7. How to create objects with ObjCreateInterface All objects needed in most automation tasks can be created using UIASpy sample code features. This is by far the easiest way to create the objects. There is really no need to create the objects in other ways. Top of post Edited April 3, 2019 by LarsJ Header mLipok, argumentum, LukeLe and 3 others 3 3 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
LarsJ Posted January 31, 2019 Author Share Posted January 31, 2019 junkew, In the current version of simplespy.au3 you can easily add a ComboBox that list the elements from Desktop to detected element. If the detected element is a pane control (or a custom control) the user can simply select the proper element in the ComboBox. This also allows the user to get information about application top window. Earthshine 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
LarsJ Posted February 3, 2019 Author Share Posted February 3, 2019 Automating Notepad - Classic This is a repetition of the Notepad example above. But this time with classic automation code: #include <WindowsConstants.au3> #include <WinAPI.au3> Example() Func Example() ; Open Notepad Run( "Notepad" ) Sleep( 1000 ) ; Notepad window handle Local $hNotepad = WinGetHandle( "[Class:Notepad]" ) ; Fill up "Edit1" with "HelloWorld" ControlSend( $hNotepad, "", "Edit1", "HelloWorld" ) ; Open "Save As..." dialog _WinAPI_PostMessage( $hNotepad, $WM_COMMAND, 4, 0 ) ; 4 = $UIA_AutomationIdPropertyId in UIASpy Sleep( 1000 ) ; Save As window handle Local $hSaveAs = WinGetHandle( "[Class:#32770]" ) ; Fill up "Edit1" (File name) with "HelloWorld.txt" ControlSend( $hSaveAs, "", "Edit1", "HelloWorld.txt" ) ; Click Save button _WinAPI_PostMessage( $hSaveAs, $WM_COMMAND, 1, 0 ) ; 1 = $UIA_AutomationIdPropertyId in UIASpy EndFunc Earthshine, argumentum and junkew 3 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
AtomicSeek Posted February 3, 2019 Share Posted February 3, 2019 Dear LarsJ, Your UIASpy tool and related examples are simply amazing. I was struggling for months to automate WindowsForms10 and other types of applications that resist to classic AutoIt and this helps me a lot. UI Automation is like the "missing chapter" of AutoIt, and I am very excited to see that it starts to take a functional form. I think this example can be considered even more classic because it does not contain any other UDFs: ; open Notepad Run ( "Notepad.exe" ) ; wait for Notepad window to exist Local $hNotepad = WinWait ( "[CLASS:Notepad; TITLE:Untitled - Notepad;]" ) ; write "HelloWorld" ControlSetText ( $hNotepad, "", "[CLASS:Edit; INSTANCE:1]", "HelloWorld" ) ; open the SaveAs window (by pressing ALT+f and a) ControlSend ( $hNotepad, "", "", "{ALT}fa" ) ; wait for Save As window to exist Local $hSaveAs = WinWait ( "[CLASS:#32770; TITLE:Save As;]" ) ; complete the File Name field with "HelloWorld.txt" ControlSetText ( $hSaveAs, "", "[CLASS:Edit; INSTANCE:1]", "HelloWorld.txt" ) ; press the Save button ControlClick ( $hSaveAs, "", "[CLASS:Button; INSTANCE:2]" ) ; wait for Save As window to close WinWaitClose ( $hSaveAs, "" ) ; close the Notepad window WinClose ( $hNotepad, "" ) ; wait for Notepad window to close WinWaitClose ( $hNotepad, "" ) Thank you! Best regards, AtomicSeek LarsJ 1 Link to comment Share on other sites More sharing options...
LarsJ Posted February 4, 2019 Author Share Posted February 4, 2019 AtomicSeek, You're welcome. I've planned more updates of these examples, so stay tuned. Regards Lars. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
arnoldfields Posted February 7, 2019 Share Posted February 7, 2019 This incredible! I will start to examine those materials right away. Many thanks! Link to comment Share on other sites More sharing options...
LarsJ Posted February 8, 2019 Author Share Posted February 8, 2019 arnoldfields, You're welcome. A new update is ready in a week or two. Stay tuned. Regards Lars. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
LarsJ Posted February 24, 2019 Author Share Posted February 24, 2019 (edited) How to topics, 8 - 15 How to topics is a guide to use UIASpy to identify windows and controls and to create sample code to obtain information and perform actions. Topics 1 - 7: Introductory topics Topics 8 - 15: Sample code creationTop of next post (bottom of this post) Topics 16 - 17: Other How to topics How to perform UI Automation tasks How to use UIASpy to detect elements How to use UIASpy to create sample code How to create sample code through Detail info page How to create sample code through Sample code menu How to create sample code by copying listview rows How to create objects with ObjCreateInterface How to create UI Automation main objects ($oUIAutomation.GetRootElement()) How to identify and find application top window ($UIA_ClassNamePropertyId, $oUIAutomation.CreatePropertyCondition()) How to identify and find UI elements (controls) (Edit control, $UIA_AutomationIdPropertyId, $oUIElement.FindFirst()) How to get UI element property values ($UIA_NativeWindowHandlePropertyId, $UIA_BoundingRectanglePropertyId) How to create element action objects (Create $oValuePattern action object) How to get pattern property values ($UIA_ValueValuePropertyId, $oUIElement.GetCurrentPropertyValue()) How to perform element actions ($oValuePattern.SetValue()) How to create executable code How to perform a mouse click in middle of bounding rectangle How to perform a control click via PostMessage and $UIA_AutomationIdPropertyId Notepad is used as a general example: The Notepad window is identified, the Edit control is identified, some properties are extracted, the ValuePattern action object is created, the existing text in the Edit control is extracted and a new text is set. It looks like this in pseudo code: ; 8. Create UI Automation main objects Create $oUIAutomation and $oDesktop objects ; 9. Identify and find application top window Create condition to identify window through $UIA_ClassNamePropertyId Find window through $oDesktop.FindFirst() with the condition as input ; 10. Identify and find Edit control from top window Create condition to identify Edit control with $UIA_AutomationIdPropertyId Find Edit control through $oWindow.FindFirst() with the condition as input ; 11. Extract some properties from the Edit control Get $UIA_NativeWindowHandlePropertyId with $oEdit.GetCurrentPropertyValue() Get $UIA_BoundingRectanglePropertyId with $oEdit.GetCurrentPropertyValue() ; 12. Create element action object for the Edit control to set a text value Create $oValuePattern with $oEdit.GetCurrentPattern() and $UIA_ValuePatternId as input ; 13. Extract the existing text in the Edit control as a pattern property Get $UIA_ValueValuePropertyId with $oEdit.GetCurrentPropertyValue() ; 14. Perform an action on the Edit control to set a new text Set new text with $oValuePattern.SetValue() and the new text as input ; 15. Create executable code from the code generated by UIASpy Modify the somewhat generic code to be executable Open an empty Notepad and type/paste Hello into the Edit control. Open UIASpy. Click Left pane | Delete top windows to delete all treeview top windows. Place mouse cursor over Notepad title bar and press F2. Notepad and UIASpy should look like shown in the picture in topic 9. The Edit control should contain the word Hello (not shown in the picture). Let UIASpy be open throughout the entire example. In topic 15 all code will be copied from the listview Code page into SciTE editor. 8. How to create UI Automation main objects Click Sample code | Initial code | Complete code to create complete startup code. The code should look like this in the listview Code page: #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "CUIAutomation2.au3" ; Get proper version in UIASpy Includes folder ;#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) EndFunc 9. How to identify and find application top window Click Notepad window in the treeview to return to the Detail info listview page. Select the row as shown, right-click and click Create sample code. The new code that's added to the bottom of the existing code should look like this in the listview Code page: ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Notepad", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Descendants, $pCondition0, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) If you accidentally selected a wrong row in the Detail info listview page, then click Sample code | Undo code, click treeview, select the right row in the listview, right-click and click Create sample code. 10. How to identify and find UI elements (controls) Click the Edit control in the treeview. Select the row as shown, right-click and click Create sample code. New code: ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, "15", $pCondition1 ) If Not $pCondition1 Then Return ConsoleWrite( "$pCondition1 ERR" & @CRLF ) ConsoleWrite( "$pCondition1 OK" & @CRLF ) Local $pEdit1, $oEdit1 $oWindow1.FindFirst( $TreeScope_Descendants, $pCondition1, $pEdit1 ) $oEdit1 = ObjCreateInterface( $pEdit1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oEdit1 ) Then Return ConsoleWrite( "$oEdit1 ERR" & @CRLF ) ConsoleWrite( "$oEdit1 OK" & @CRLF ) 11. How to get UI element property values Extract window handle and bounding rectangle for the Edit control. The far easiest way to extract properties is through Sample code | Properties... Select the row as shown, right-click and click Create sample code. New code: ; --- Element Properties --- ConsoleWrite( "--- Element Properties ---" & @CRLF ) Local $hNativeWindowHandle1 $oEdit1.GetCurrentPropertyValue( $UIA_NativeWindowHandlePropertyId, $hNativeWindowHandle1 ) ConsoleWrite( "$hNativeWindowHandle1 = " & $hNativeWindowHandle1 & @CRLF ) Local $asBoundingRectangle1 $oEdit1.GetCurrentPropertyValue( $UIA_BoundingRectanglePropertyId, $asBoundingRectangle1 ) UIA_GetArrayPropertyValue( $asBoundingRectangle1 ) ConsoleWrite( "$asBoundingRectangle1 = " & $asBoundingRectangle1 & @CRLF ) UIA_GetArrayPropertyValue() in UIA_Functions.au3 converts a property returned as an array to a comma separated string. 12. How to create element action objects Create the ValuePattern action object. It'll be used in topic 14 to set a new text in the Edit control. Click the Edit control in the treeview. Select the row as shown (scroll down), right-click and click Create sample code. New code: ; --- Value Pattern (action) Object --- ConsoleWrite( "--- Value Pattern (action) Object ---" & @CRLF ) Local $pValuePattern1, $oValuePattern1 $oEdit1.GetCurrentPattern( $UIA_ValuePatternId, $pValuePattern1 ) $oValuePattern1 = ObjCreateInterface( $pValuePattern1, $sIID_IUIAutomationValuePattern, $dtagIUIAutomationValuePattern ) If Not IsObj( $oValuePattern1 ) Then Return ConsoleWrite( "$oValuePattern1 ERR" & @CRLF ) ConsoleWrite( "$oValuePattern1 OK" & @CRLF ) 13. How to get pattern property values Extract the existing text in the Edit control. That's the $UIA_ValueValuePropertyId. Click the Edit control in the treeview. Select the row as shown (scroll down), right-click and click Create sample code. New code: ; --- Control Pattern Properties --- ConsoleWrite( "--- Control Pattern Properties ---" & @CRLF ) Local $sValueValue1 $oEdit1.GetCurrentPropertyValue( $UIA_ValueValuePropertyId, $sValueValue1 ) ConsoleWrite( "$sValueValue1 = " & $sValueValue1 & @CRLF ) 14. How to perform element actions Set a new text, HelloWorld, in the Edit control with the SetValue() method of the ValuePattern action object. Click the Edit control in the treeview. Select the row as shown (scroll down), right-click and click Create sample code. New code: ; --- Value Pattern (action) Methods --- ConsoleWrite( "--- Value Pattern (action) Methods ---" & @CRLF ) $oValuePattern1.SetValue(bstr) ConsoleWrite( "$oValuePattern1.SetValue()" & @CRLF ) bstr must be replaced with "HelloWorld". We'll do that in topic 15. 15. How to create executable code The code in the listview Code page isn't immediately executable. A few necessary corrections must be made before the code is executable. Click Sample code | Corrections to add a list of necessary and nice corrections. New code: ; Code corrections: ; CUIAutomation2.au3 path ; UIA_Functions.au3 path ; Code to open target appl ; Create undeclared variables ; Delete double declared variables ; Window, Pane, Parent and Control names ; Fill out Pattern (action) Method parameters All code directly from the listview Code page (Examples\2) How to topics\Notepad\ListViewCodePage.au3): expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "CUIAutomation2.au3" ; Get proper version in UIASpy Includes folder ;#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) EndFunc ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Notepad", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Descendants, $pCondition0, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, "15", $pCondition1 ) If Not $pCondition1 Then Return ConsoleWrite( "$pCondition1 ERR" & @CRLF ) ConsoleWrite( "$pCondition1 OK" & @CRLF ) Local $pEdit1, $oEdit1 $oWindow1.FindFirst( $TreeScope_Descendants, $pCondition1, $pEdit1 ) $oEdit1 = ObjCreateInterface( $pEdit1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oEdit1 ) Then Return ConsoleWrite( "$oEdit1 ERR" & @CRLF ) ConsoleWrite( "$oEdit1 OK" & @CRLF ) ; --- Element Properties --- ConsoleWrite( "--- Element Properties ---" & @CRLF ) Local $hNativeWindowHandle1 $oEdit1.GetCurrentPropertyValue( $UIA_NativeWindowHandlePropertyId, $hNativeWindowHandle1 ) ConsoleWrite( "$hNativeWindowHandle1 = " & $hNativeWindowHandle1 & @CRLF ) Local $asBoundingRectangle1 $oEdit1.GetCurrentPropertyValue( $UIA_BoundingRectanglePropertyId, $asBoundingRectangle1 ) UIA_GetArrayPropertyValue( $asBoundingRectangle1 ) ConsoleWrite( "$asBoundingRectangle1 = " & $asBoundingRectangle1 & @CRLF ) ; --- Value Pattern (action) Object --- ConsoleWrite( "--- Value Pattern (action) Object ---" & @CRLF ) Local $pValuePattern1, $oValuePattern1 $oEdit1.GetCurrentPattern( $UIA_ValuePatternId, $pValuePattern1 ) $oValuePattern1 = ObjCreateInterface( $pValuePattern1, $sIID_IUIAutomationValuePattern, $dtagIUIAutomationValuePattern ) If Not IsObj( $oValuePattern1 ) Then Return ConsoleWrite( "$oValuePattern1 ERR" & @CRLF ) ConsoleWrite( "$oValuePattern1 OK" & @CRLF ) ; --- Control Pattern Properties --- ConsoleWrite( "--- Control Pattern Properties ---" & @CRLF ) Local $sValueValue1 $oEdit1.GetCurrentPropertyValue( $UIA_ValueValuePropertyId, $sValueValue1 ) ConsoleWrite( "$sValueValue1 = " & $sValueValue1 & @CRLF ) ; --- Value Pattern (action) Methods --- ConsoleWrite( "--- Value Pattern (action) Methods ---" & @CRLF ) $oValuePattern1.SetValue(bstr) ConsoleWrite( "$oValuePattern1.SetValue()" & @CRLF ) ; Code corrections: ; CUIAutomation2.au3 path ; UIA_Functions.au3 path ; Code to open target appl ; Create undeclared variables ; Delete double declared variables ; Window, Pane, Parent and Control names ; Fill out Pattern (action) Method parameters Necessary corrections: ; CUIAutomation2.au3 path ; UIA_Functions.au3 path ; Fill out Pattern (action) Method parameters And the code from line 26 must be moved into the function. All code after necessary corrections (Examples\2) How to topics\Notepad\NecessaryCorrections.au3): expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "..\..\..\Includes\CUIAutomation2.au3" ; Get proper version in UIASpy Includes folder #include "..\..\..\Includes\UIA_Functions.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Notepad", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Descendants, $pCondition0, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, "15", $pCondition1 ) If Not $pCondition1 Then Return ConsoleWrite( "$pCondition1 ERR" & @CRLF ) ConsoleWrite( "$pCondition1 OK" & @CRLF ) Local $pEdit1, $oEdit1 $oWindow1.FindFirst( $TreeScope_Descendants, $pCondition1, $pEdit1 ) $oEdit1 = ObjCreateInterface( $pEdit1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oEdit1 ) Then Return ConsoleWrite( "$oEdit1 ERR" & @CRLF ) ConsoleWrite( "$oEdit1 OK" & @CRLF ) ; --- Element Properties --- ConsoleWrite( "--- Element Properties ---" & @CRLF ) Local $hNativeWindowHandle1 $oEdit1.GetCurrentPropertyValue( $UIA_NativeWindowHandlePropertyId, $hNativeWindowHandle1 ) ConsoleWrite( "$hNativeWindowHandle1 = " & $hNativeWindowHandle1 & @CRLF ) Local $asBoundingRectangle1 $oEdit1.GetCurrentPropertyValue( $UIA_BoundingRectanglePropertyId, $asBoundingRectangle1 ) UIA_GetArrayPropertyValue( $asBoundingRectangle1 ) ConsoleWrite( "$asBoundingRectangle1 = " & $asBoundingRectangle1 & @CRLF ) ; --- Value Pattern (action) Object --- ConsoleWrite( "--- Value Pattern (action) Object ---" & @CRLF ) Local $pValuePattern1, $oValuePattern1 $oEdit1.GetCurrentPattern( $UIA_ValuePatternId, $pValuePattern1 ) $oValuePattern1 = ObjCreateInterface( $pValuePattern1, $sIID_IUIAutomationValuePattern, $dtagIUIAutomationValuePattern ) If Not IsObj( $oValuePattern1 ) Then Return ConsoleWrite( "$oValuePattern1 ERR" & @CRLF ) ConsoleWrite( "$oValuePattern1 OK" & @CRLF ) ; --- Control Pattern Properties --- ConsoleWrite( "--- Control Pattern Properties ---" & @CRLF ) Local $sValueValue1 $oEdit1.GetCurrentPropertyValue( $UIA_ValueValuePropertyId, $sValueValue1 ) ConsoleWrite( "$sValueValue1 = " & $sValueValue1 & @CRLF ) ; --- Value Pattern (action) Methods --- ConsoleWrite( "--- Value Pattern (action) Methods ---" & @CRLF ) $oValuePattern1.SetValue( "HelloWorld" ) ConsoleWrite( "$oValuePattern1.SetValue()" & @CRLF ) ; Code corrections: ; CUIAutomation2.au3 path ; UIA_Functions.au3 path ; Fill out Pattern (action) Method parameters EndFunc Run the code. SciTE output: $oUIAutomation OK $oDesktop OK --- Find window/control --- $pCondition0 OK $oWindow1 OK --- Find window/control --- $pCondition1 OK $oEdit1 OK --- Element Properties --- $hNativeWindowHandle1 = 197258 $asBoundingRectangle1 = 258,100,984,842 --- Value Pattern (action) Object --- $oValuePattern1 OK --- Control Pattern Properties --- $sValueValue1 = Hello --- Value Pattern (action) Methods --- $oValuePattern1.SetValue() Nice corrections: Update comments. All code after nice corrections (Examples\2) How to topics\Notepad\NiceCorrections.au3): expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "..\..\..\Includes\CUIAutomation2.au3" ; Get proper version in UIASpy Includes folder #include "..\..\..\Includes\UIA_Functions.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find Notepad --- ConsoleWrite( "--- Find Notepad ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Notepad", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Descendants, $pCondition0, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Find Edit control --- ConsoleWrite( "--- Find Edit control ---" & @CRLF ) Local $pCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, "15", $pCondition1 ) If Not $pCondition1 Then Return ConsoleWrite( "$pCondition1 ERR" & @CRLF ) ConsoleWrite( "$pCondition1 OK" & @CRLF ) Local $pEdit1, $oEdit1 $oWindow1.FindFirst( $TreeScope_Descendants, $pCondition1, $pEdit1 ) $oEdit1 = ObjCreateInterface( $pEdit1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oEdit1 ) Then Return ConsoleWrite( "$oEdit1 ERR" & @CRLF ) ConsoleWrite( "$oEdit1 OK" & @CRLF ) ; --- Element Properties --- ConsoleWrite( "--- Element Properties ---" & @CRLF ) Local $hNativeWindowHandle1 $oEdit1.GetCurrentPropertyValue( $UIA_NativeWindowHandlePropertyId, $hNativeWindowHandle1 ) ConsoleWrite( "$hNativeWindowHandle1 = " & $hNativeWindowHandle1 & @CRLF ) Local $asBoundingRectangle1 $oEdit1.GetCurrentPropertyValue( $UIA_BoundingRectanglePropertyId, $asBoundingRectangle1 ) UIA_GetArrayPropertyValue( $asBoundingRectangle1 ) ConsoleWrite( "$asBoundingRectangle1 = " & $asBoundingRectangle1 & @CRLF ) ; --- Value Pattern (action) Object --- ConsoleWrite( "--- Value Pattern (action) Object ---" & @CRLF ) Local $pValuePattern1, $oValuePattern1 $oEdit1.GetCurrentPattern( $UIA_ValuePatternId, $pValuePattern1 ) $oValuePattern1 = ObjCreateInterface( $pValuePattern1, $sIID_IUIAutomationValuePattern, $dtagIUIAutomationValuePattern ) If Not IsObj( $oValuePattern1 ) Then Return ConsoleWrite( "$oValuePattern1 ERR" & @CRLF ) ConsoleWrite( "$oValuePattern1 OK" & @CRLF ) ; --- Control Pattern Properties --- ConsoleWrite( "--- Control Pattern Properties ---" & @CRLF ) Local $sValueValue1 $oEdit1.GetCurrentPropertyValue( $UIA_ValueValuePropertyId, $sValueValue1 ) ConsoleWrite( "$sValueValue1 = " & $sValueValue1 & @CRLF ) ; --- Value Pattern (action) Methods --- ConsoleWrite( "--- Value Pattern (action) Methods ---" & @CRLF ) $oValuePattern1.SetValue( "HelloWorld" ) ConsoleWrite( "$oValuePattern1.SetValue()" & @CRLF ) ; Code corrections: ; CUIAutomation2.au3 path ; UIA_Functions.au3 path ; Fill out Pattern (action) Method parameters ; Nice corrections: Update comments EndFunc Run the code. SciTE output: $oUIAutomation OK $oDesktop OK --- Find Notepad --- $pCondition0 OK $oWindow1 OK --- Find Edit control --- $pCondition1 OK $oEdit1 OK --- Element Properties --- $hNativeWindowHandle1 = 197258 $asBoundingRectangle1 = 258,100,984,842 --- Value Pattern (action) Object --- $oValuePattern1 OK --- Control Pattern Properties --- $sValueValue1 = Hello --- Value Pattern (action) Methods --- $oValuePattern1.SetValue() Top of post Edited March 22, 2019 by LarsJ Header Gianni and yutijang 2 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
odaylton Posted March 3, 2019 Share Posted March 3, 2019 Just wonderful. incredible as Autoit is powerful .... LarsJ you put Autoit to a new level ... I do not know if I'm not finding but there is something showing the coordinates of the mouse and mouse type when pressing [F2] I think it would be interesting to have this information as well as pixel color at the mouse position .... I await for news Link to comment Share on other sites More sharing options...
odaylton Posted March 3, 2019 Share Posted March 3, 2019 4 hours ago, odaylton said: Just wonderful. incredible as Autoit is powerful .... LarsJ you put Autoit to a new level ... I do not know if I'm not finding but there is something showing the coordinates of the mouse and mouse type when pressing [F2] I think it would be interesting to have this information as well as pixel color at the mouse position .... I await for news I was doing a test on a machine with win7 and Autoit v3.3.14.5 and it ran normally But I have another machine where I develop that contains win XP and Autoit v3.3.14.2 and au to run the SciTE of the second error message: >"C:\Arquivos de programas\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Arquivos de programas\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "E:\0MeusDocs\0Projetos\AutoIt\UIASpy\UIASpy.au3" /UserParams +>09:48:05 Starting AutoIt3Wrapper v.17.224.935.0 SciTE v.3.7.3.0 Keyboard:00010416 OS:WIN_XP/Service Pack 3 CPU:X86 OS:X86 Environment(Language:0416) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Arquivos de programas\AutoIt3\SciTE UserDir => C:\Documents and Settings\VM-1\Configurações locais\Dados de aplicativos\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Documents and Settings\VM-1\Configurações locais\Dados de aplicativos\AutoIt v3\SciTE >Running AU3Check (3.3.14.2) from:C:\Arquivos de programas\AutoIt3 input:E:\0MeusDocs\0Projetos\AutoIt\UIASpy\UIASpy.au3 +>09:48:07 AU3Check ended.rc:0 >Running:(3.3.14.2):C:\Arquivos de programas\AutoIt3\autoit3.exe "E:\0MeusDocs\0Projetos\AutoIt\UIASpy\UIASpy.au3" --> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop "E:\0MeusDocs\0Projetos\AutoIt\UIASpy\Includes\UIASpy_Elements.au3" (33) : ==> Variable must be of type "Object".: $oUIAutomation.GetRootElement( $pDesktop ) $oUIAutomation^ ERROR ->09:48:09 AutoIt3.exe ended.rc:1 +>09:48:09 AutoIt3Wrapper Finished. >Exit code: 1 Time: 5.784 I believe the error lies in the incompatibility with win XP and I rely on your expertise and knowledge to solve this problem PS: on another machine with Autoit v3.3.14.5 with XP also gave the same error Link to comment Share on other sites More sharing options...
LarsJ Posted March 3, 2019 Author Share Posted March 3, 2019 The error is due to the fact that UI Automation software is not installed on your Windows XPs. You must install Platform Update for Windows Vista. At the bottom of this page you'll find a link to a Knowledge Base article which (again at the bottom of the page) describes how to install the update through Windows Update. I've tested UIASpy under Windows XP through Windows XP Mode in Windows Virtual PC for Windows 7. Mouse coordinates and pixel colors are not used in UI Automation code so I'm going to disappoint you here. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
odaylton Posted March 5, 2019 Share Posted March 5, 2019 (edited) On 3/3/2019 at 2:32 PM, LarsJ said: The error is due to the fact that UI Automation software is not installed on your Windows XPs. You must install Platform Update for Windows Vista. At the bottom of this page you'll find a link to a Knowledge Base article which (again at the bottom of the page) describes how to install the update through Windows Update. I've tested UIASpy under Windows XP through Windows XP Mode in Windows Virtual PC for Windows 7. Thanks for the prompt clarification, I will try to install Update. As the machines with XP are in virtual machines, I have the habit of installing the minimum nescessario to leave them as soon as possible, but in this case I will have to break this rule because it is worth the test. I suggest putting this comment as an addendum to your well-crafted "HowTo" On 3/3/2019 at 2:32 PM, LarsJ said: Mouse coordinates and pixel colors are not used in UI Automation code so I'm going to disappoint you here. I understand that this data is not part of the Automation project but it is here the exploration of the structure of your program to generate a code generator more comprehensive to all the possibilities that Autoit can elaborate for the less experienced programmers. I think it would not be a bad idea to have other codes for other features that autoit explores. After a quick look at their "Includes" I believe this would be an ideal place for these inclusions: In the "UIASpy_Detect" include this section where I imagine the information is collected. Func UIASpy_DetectElement( $iFkey ) ; $iFkey = 1 ; Update direct childs of element ; $iFkey = 2 ; Update direct childs of parent ; $iFkey = 3 ; Update all childs of element ; $iFkey = 4 ; Update all childs of parent $bFkeyDetect = True ; Get element under mouse Local $pUIElement, $oUIElement Local $x = MouseGetPos(0), $y = MouseGetPos(1) Local Static $tPoint = DllStructCreate( $tagPOINT ) DllStructSetData( $tPoint, "X", $x ) DllStructSetData( $tPoint, "Y", $y ) $oUIAutomation.ElementFromPoint( $tPoint, $pUIElement ) As far as I can understand, the whole program is written in OO (Object Orientation), which I unfortunately do not master much (Old Guard programmer), but I understand its comprehensiveness and ease. Who knows, you can suggest how to make something different out of the scope of your project, but that other programmers can easily generate other facilities for this wonderful project. Sorry for the insistence but as you thoroughly know all the structure of the objects used could give me a light to be able to humiliently uncertain this complement Edited March 5, 2019 by odaylton Link to comment Share on other sites More sharing options...
LarsJ Posted March 9, 2019 Author Share Posted March 9, 2019 Mouse coordinates and pixel colors are still not relevant to UI Automation. I can add new features, but they must be relevant to UI Automation. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
LarsJ Posted March 9, 2019 Author Share Posted March 9, 2019 (edited) How to topics, 16 - 17 How to topics is a guide to use UIASpy to identify windows and controls and to create sample code to obtain information and perform actions. Topics 1 - 7: Introductory topics Topics 8 - 15: Sample code creation Topics 16 - 17: Other How to topics How to perform UI Automation tasks How to use UIASpy to detect elements How to use UIASpy to create sample code How to create sample code through Detail info page How to create sample code through Sample code menu How to create sample code by copying listview rows How to create objects with ObjCreateInterface How to create UI Automation main objects How to identify and find application top window How to identify and find UI elements (controls) How to get UI element property values How to create element action objects How to get pattern property values How to perform element actions How to create executable code How to perform a mouse click in middle of bounding rectangle (MenuItem, UIA_WinActivate()) How to perform a control click via PostMessage and $UIA_AutomationIdPropertyId (MenuItem) Notepad is used as a general example. 16. How to perform a mouse click in middle of bounding rectangle Open an empty Notepad Open UIASpy tool Create Sample code to Add complete initial code Identify and find Notepad top window Activate Notepad through Code snippets... Identify and find the File menu item Click File menu through Code snippets... Modify the Sample code to be executable Executable code (Examples\3) Other How to topics\Notepad\16) Mouse click in bounding rectangle.au3): expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "..\..\..\Includes\CUIAutomation2.au3" ; Get proper version in UIASpy Includes folder #include "..\..\..\Includes\UIA_Functions.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Notepad", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Descendants, $pCondition0, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Code Snippets --- ConsoleWrite( "--- Code Snippets ---" & @CRLF ) UIA_WinActivate( $oWindow1 ) ConsoleWrite( "UIA_WinActivate( $oWindow1 )" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition1, $pCondition2, $pAndCondition2 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_MenuItemControlTypeId, $pCondition1 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "File", $pCondition2 ) $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pAndCondition2 ) If Not $pAndCondition2 Then Return ConsoleWrite( "$pAndCondition2 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition2 OK" & @CRLF ) Local $pMenuItem1, $oMenuItem1 $oWindow1.FindFirst( $TreeScope_Descendants, $pAndCondition2, $pMenuItem1 ) $oMenuItem1 = ObjCreateInterface( $pMenuItem1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oMenuItem1 ) Then Return ConsoleWrite( "$oMenuItem1 ERR" & @CRLF ) ConsoleWrite( "$oMenuItem1 OK" & @CRLF ) ; --- Code Snippets --- ConsoleWrite( "--- Code Snippets ---" & @CRLF ) UIA_MouseClick( $oMenuItem1 ) ConsoleWrite( "UIA_MouseClick( $oMenuItem1 )" & @CRLF ) EndFunc SciTE output: $oUIAutomation OK $oDesktop OK --- Find window/control --- $pCondition0 OK $oWindow1 OK --- Code Snippets --- UIA_WinActivate( $oWindow1 ) --- Find window/control --- $pAndCondition2 OK $oMenuItem1 OK --- Code Snippets --- UIA_MouseClick( $oMenuItem1 ) 17. How to perform a control click via PostMessage and $UIA_AutomationIdPropertyId Open an empty Notepad Open UIASpy tool Create Sample code to Add complete initial code Identify and find Notepad top window Detect Save As... menu item in Notepad File menu Copy $UIA_AutomationIdPropertyId for Save As... menu item to Sample code Click Save As... menu item through Code snippets... Modify the Sample code to be executable Copy $UIA_AutomationIdPropertyId for Save As... menu item to Sample code: Executable code (Examples\3) Other How to topics\Notepad\17) Control click via PostMessage.au3): expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "..\..\..\Includes\CUIAutomation2.au3" ; Get proper version in UIASpy Includes folder #include "..\..\..\Includes\UIA_Functions.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Notepad", $pCondition0 ) If Not $pCondition0 Then Return ConsoleWrite( "$pCondition0 ERR" & @CRLF ) ConsoleWrite( "$pCondition0 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Descendants, $pCondition0, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Copy element info --- ; $UIA_AutomationIdPropertyId 4 ; --- Code Snippets --- ConsoleWrite( "--- Code Snippets ---" & @CRLF ) UIA_PostMessage( $oWindow1, 4 ) ; 4 = $UIA_AutomationIdPropertyId ConsoleWrite( "UIA_PostMessage( $oWindow1, $sAutomationId )" & @CRLF ) EndFunc SciTE output: $oUIAutomation OK $oDesktop OK --- Find window/control --- $pCondition0 OK $oWindow1 OK --- Code Snippets --- UIA_PostMessage( $oWindow1, $sAutomationId ) Edited March 23, 2019 by LarsJ Yellow cues Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
LarsJ Posted March 9, 2019 Author Share Posted March 9, 2019 (edited) Patterns (actions), 1 - 12 Control patterns are objects that can be used to perform actions on an UI element (window/control). The actual actions are performed by executing the methods of the pattern objects. Control types that are supported by specific control patterns are listed in Control Types and Their Supported Control Patterns. How to create pattern objects and execute pattern methods through UIASpy is described in How to topics 12 and 14. The examples shows how to use control patterns. The examples are tested on Windows 10 and Windows 7. In many examples you need to update eg. control names to your own names. There may also be other values to be updated. Lines to be updated are marked with ; <<<<<<<<<<<<<<<<<<<< Use UIASpy to check and copy the values. All code is stored in Examples\4) Patterns (actions)\<Pattern>\ folders. Patterns (actions): Section 1 - 12: Examples based on File ExplorerTop of next post (bottom of this post) Section 13 - 15: Virtual listview item patterns Section 16 - 17: Other control pattern objects File Explorer pictureWindow patterns (Window) Window Control Pattern (SetWindowVisualState()) Transform Control Pattern (Move())Treeview patterns (Tree, TreeItem) ExpandCollapse Control Pattern (Expand(), Collapse()) ScrollItem Control Pattern (ScrollIntoView()) Scroll Control Pattern (Scroll()) Does not work on Windows 7 ($oScrollPattern1 ERR)Listview patterns (List, ListItem) Grid Control Pattern (GetItem()) Table Control Pattern (GetCurrentColumnHeaders()) Invoke Control Pattern (Invoke()) MultipleView Control Pattern (GetCurrentSupportedViews()) SelectionItem Control Pattern (Select(), AddToSelection()) Selection Control Pattern (GetCurrentSelection())Virtual listview item patterns File Explorer picture ItemContainer Control Pattern VirtualizedItem Control Pattern Other control pattern objects Value Control Pattern RangeValue Control Pattern 1. File Explorer picture 2. Window Control Pattern From Microsoft documentation: The Window control pattern supports controls that provide fundamental window-based functionality within a traditional GUI. This includes top-level application windows, multiple-document interface (MDI) child windows, resizable split pane controls, modal dialogs and balloon help windows. Preparation File Explorer should look as shown in the picture. Open UIASpy, place the mouse over window title bar, press F2. Code The code created with UIASpy shows how to alternately switch the window visual state between normal and minimized (Window.au3, Window-a.au3 contains code directly from UIASpy): expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "..\..\..\Includes\CUIAutomation2.au3" ; Get proper version in UIASpy Includes folder ;#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0, $pCondition1, $pAndCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "CabinetWClass", $pCondition0 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "System (C:)", $pCondition1 ) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $oUIAutomation.CreateAndCondition( $pCondition0, $pCondition1, $pAndCondition1 ) If Not $pAndCondition1 Then Return ConsoleWrite( "$pAndCondition1 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition1 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Descendants, $pAndCondition1, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Window Pattern (action) Object --- ConsoleWrite( "--- Window Pattern (action) Object ---" & @CRLF ) Local $pWindowPattern1, $oWindowPattern1 $oWindow1.GetCurrentPattern( $UIA_WindowPatternId, $pWindowPattern1 ) $oWindowPattern1 = ObjCreateInterface( $pWindowPattern1, $sIID_IUIAutomationWindowPattern, $dtagIUIAutomationWindowPattern ) If Not IsObj( $oWindowPattern1 ) Then Return ConsoleWrite( "$oWindowPattern1 ERR" & @CRLF ) ConsoleWrite( "$oWindowPattern1 OK" & @CRLF ) ; --- Control Pattern Properties --- ConsoleWrite( "--- Control Pattern Properties ---" & @CRLF ) Local $iWindowWindowVisualState1 $oWindow1.GetCurrentPropertyValue( $UIA_WindowWindowVisualStatePropertyId, $iWindowWindowVisualState1 ) ConsoleWrite( "$iWindowWindowVisualState1 = " & $iWindowWindowVisualState1 & @CRLF ) ; --- Copy element info --- ; $UIA_WindowWindowVisualStatePropertyId $WindowVisualState_Normal ; --- Window Pattern (action) Methods --- ConsoleWrite( "--- Window Pattern (action) Methods ---" & @CRLF ) If $iWindowWindowVisualState1 = $WindowVisualState_Normal Then $oWindowPattern1.SetWindowVisualState( $WindowVisualState_Minimized ) ConsoleWrite( "$oWindowPattern1.SetWindowVisualState( $WindowVisualState_Minimized )" & @CRLF ) Else $oWindowPattern1.SetWindowVisualState( $WindowVisualState_Normal ) ConsoleWrite( "$oWindowPattern1.SetWindowVisualState( $WindowVisualState_Normal )" & @CRLF ) EndIf EndFunc SciTE output: $oUIAutomation OK $oDesktop OK --- Find window/control --- $pAndCondition1 OK $oWindow1 OK --- Window Pattern (action) Object --- $oWindowPattern1 OK --- Control Pattern Properties --- $iWindowWindowVisualState1 = 0 --- Window Pattern (action) Methods --- $oWindowPattern1.SetWindowVisualState( $WindowVisualState_Minimized ) Remarks WindowVisualState values are found in CUIAutomation2.au3 and Microsoft documentation. 3. Transform Control Pattern From Microsoft documentation: The Transform control pattern is used to support controls that can be moved, resized, or rotated within a two-dimensional space. Preparation File Explorer should look as shown in the picture. Open UIASpy, place the mouse over window title bar, press F2. Code The code created with UIASpy shows how to move the window horizontally 100 pixels forth and back (Transform.au3, Transform-a.au3 contains code directly from UIASpy): expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "..\..\..\Includes\CUIAutomation2.au3" ; Get proper version in UIASpy Includes folder #include "..\..\..\Includes\UIA_Functions.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0, $pCondition1, $pAndCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "CabinetWClass", $pCondition0 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "System (C:)", $pCondition1 ) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $oUIAutomation.CreateAndCondition( $pCondition0, $pCondition1, $pAndCondition1 ) If Not $pAndCondition1 Then Return ConsoleWrite( "$pAndCondition1 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition1 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Descendants, $pAndCondition1, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Transform Pattern (action) Object --- ConsoleWrite( "--- Transform Pattern (action) Object ---" & @CRLF ) Local $pTransformPattern1, $oTransformPattern1 $oWindow1.GetCurrentPattern( $UIA_TransformPatternId, $pTransformPattern1 ) $oTransformPattern1 = ObjCreateInterface( $pTransformPattern1, $sIID_IUIAutomationTransformPattern, $dtagIUIAutomationTransformPattern ) If Not IsObj( $oTransformPattern1 ) Then Return ConsoleWrite( "$oTransformPattern1 ERR" & @CRLF ) ConsoleWrite( "$oTransformPattern1 OK" & @CRLF ) ; --- Element Properties (information) --- ConsoleWrite( "--- Element Properties (information) ---" & @CRLF ) Local $asBoundingRectangle1 $oWindow1.GetCurrentPropertyValue( $UIA_BoundingRectanglePropertyId, $asBoundingRectangle1 ) UIA_GetArrayPropertyValueAsString( $asBoundingRectangle1 ) ConsoleWrite( "$asBoundingRectangle1 = " & $asBoundingRectangle1 & @CRLF ) ; --- Copy element info --- ; $UIA_BoundingRectanglePropertyId l=250,t=50,w=1000,h=900 ; --- Transform Pattern (action) Methods --- ConsoleWrite( "--- Transform Pattern (action) Methods ---" & @CRLF ) If StringSplit( $asBoundingRectangle1, ",", 2 )[0] = 250 Then ; 2 = $STR_NOCOUNT ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $oTransformPattern1.Move( StringSplit( $asBoundingRectangle1, ",", 2 )[0] + 100, 50 ) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ConsoleWrite( "$oTransformPattern1.Move( +100 )" & @CRLF ) Else $oTransformPattern1.Move( StringSplit( $asBoundingRectangle1, ",", 2 )[0] - 100, 50 ) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ConsoleWrite( "$oTransformPattern1.Move( -100 )" & @CRLF ) EndIf EndFunc SciTE output: $oUIAutomation OK $oDesktop OK --- Find window/control --- $pAndCondition1 OK $oWindow1 OK --- Transform Pattern (action) Object --- $oTransformPattern1 OK --- Element Properties (information) --- $asBoundingRectangle1 = 250,50,1000,900 --- Transform Pattern (action) Methods --- $oTransformPattern1.Move( +100 ) Remarks Note the use of UIA_GetArrayPropertyValueAsString() function and the inclusion of UIA_Functions.au3 UDF. 4. ExpandCollapse Control Pattern From Microsoft documentation: The ExpandCollapse control pattern is used to support controls that visually expand to display more content and collapse to hide content. Eg. a treeview element with child elements. Preparation File Explorer should look as shown in the picture. The C-drive in the treeview should be collapsed. Open UIASpy, place the mouse over the C-drive, press F1. Code The code generated with UIASpy shows how to alternately expand and collapse the C-drive (ExpandCollapse.au3, ExpandCollapse-a.au3 contains code directly from UIASpy): expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "..\..\..\Includes\CUIAutomation2.au3" ; Get proper version in UIASpy Includes folder ;#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0, $pCondition1, $pAndCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "CabinetWClass", $pCondition0 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "System (C:)", $pCondition1 ) ; <<<<<<<<<<<<<<<<< $oUIAutomation.CreateAndCondition( $pCondition0, $pCondition1, $pAndCondition1 ) If Not $pAndCondition1 Then Return ConsoleWrite( "$pAndCondition1 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition1 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Descendants, $pAndCondition1, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition2, $pCondition3, $pAndCondition3 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TreeItemControlTypeId, $pCondition2 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "System (C:)", $pCondition3 ) ; <<<<<<<<<<<<<<<<< $oUIAutomation.CreateAndCondition( $pCondition2, $pCondition3, $pAndCondition3 ) If Not $pAndCondition3 Then Return ConsoleWrite( "$pAndCondition3 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition3 OK" & @CRLF ) Local $pTreeItem1, $oTreeItem1 $oWindow1.FindFirst( $TreeScope_Descendants, $pAndCondition3, $pTreeItem1 ) $oTreeItem1 = ObjCreateInterface( $pTreeItem1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oTreeItem1 ) Then Return ConsoleWrite( "$oTreeItem1 ERR" & @CRLF ) ConsoleWrite( "$oTreeItem1 OK" & @CRLF ) ; --- ExpandCollapse Pattern (action) Object --- ConsoleWrite( "--- ExpandCollapse Pattern (action) Object ---" & @CRLF ) Local $pExpandCollapsePattern1, $oExpandCollapsePattern1 $oTreeItem1.GetCurrentPattern( $UIA_ExpandCollapsePatternId, $pExpandCollapsePattern1 ) $oExpandCollapsePattern1 = ObjCreateInterface( $pExpandCollapsePattern1, $sIID_IUIAutomationExpandCollapsePattern, $dtagIUIAutomationExpandCollapsePattern ) If Not IsObj( $oExpandCollapsePattern1 ) Then Return ConsoleWrite( "$oExpandCollapsePattern1 ERR" & @CRLF ) ConsoleWrite( "$oExpandCollapsePattern1 OK" & @CRLF ) ; --- Control Pattern Properties --- ConsoleWrite( "--- Control Pattern Properties ---" & @CRLF ) Local $iExpandCollapseExpandCollapseState1 $oTreeItem1.GetCurrentPropertyValue( $UIA_ExpandCollapseExpandCollapseStatePropertyId, $iExpandCollapseExpandCollapseState1 ) ConsoleWrite( "$iExpandCollapseExpandCollapseState1 = " & $iExpandCollapseExpandCollapseState1 & @CRLF ) ; --- Copy element info --- ; $UIA_ExpandCollapseExpandCollapseStatePropertyId $ExpandCollapseState_Collapsed ; --- ExpandCollapse Pattern (action) Methods --- ConsoleWrite( "--- ExpandCollapse Pattern (action) Methods ---" & @CRLF ) If $iExpandCollapseExpandCollapseState1 = $ExpandCollapseState_Collapsed Then $oExpandCollapsePattern1.Expand() ConsoleWrite( "$oExpandCollapsePattern1.Expand()" & @CRLF ) Else $oExpandCollapsePattern1.Collapse() ConsoleWrite( "$oExpandCollapsePattern1.Collapse()" & @CRLF ) EndIf EndFunc SciTE output: $oUIAutomation OK $oDesktop OK --- Find window/control --- $pAndCondition1 OK $oWindow1 OK --- Find window/control --- $pAndCondition3 OK $oTreeItem1 OK --- ExpandCollapse Pattern (action) Object --- $oExpandCollapsePattern1 OK --- Control Pattern Properties --- $iExpandCollapseExpandCollapseState1 = 0 --- ExpandCollapse Pattern (action) Methods --- $oExpandCollapsePattern1.Expand() Remarks ExpandCollapseState values are found in CUIAutomation2.au3 and Microsoft documentation. 5. ScrollItem Control Pattern From Microsoft documentation: The ScrollItem control pattern acts as a communication channel between a child control and its container to ensure that the container can change the currently visible content (or region) within its viewport to display the child control. The ScrollItem pattern object implements one method only: ScrollIntoView(). It can be used to make a child control visible in its parent container control. Eg. to make a treeview item visible in the treeview. Preparation File Explorer should look as shown in the picture. The C-drive in the treeview should be collapsed. Open UIASpy, place the mouse over the C-drive, press F1. Expand the C-drive in the treeview. Expand Windows folder in the treeview. Windows folder should be visible in top of the treeview. The C-drive should be scrolled out of sight. Code The code created with UIASpy shows how to scroll the C-drive into sight (ScrollItem.au3, ScrollItem-a.au3 contains code directly from UIASpy): expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "..\..\..\Includes\CUIAutomation2.au3" ; Get proper version in UIASpy Includes folder ;#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0, $pCondition1, $pAndCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "CabinetWClass", $pCondition0 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "System (C:)", $pCondition1 ) $oUIAutomation.CreateAndCondition( $pCondition0, $pCondition1, $pAndCondition1 ) If Not $pAndCondition1 Then Return ConsoleWrite( "$pAndCondition1 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition1 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Descendants, $pAndCondition1, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition2, $pCondition3, $pAndCondition3 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TreeItemControlTypeId, $pCondition2 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "System (C:)", $pCondition3 ) $oUIAutomation.CreateAndCondition( $pCondition2, $pCondition3, $pAndCondition3 ) If Not $pAndCondition3 Then Return ConsoleWrite( "$pAndCondition3 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition3 OK" & @CRLF ) Local $pTreeItem1, $oTreeItem1 $oWindow1.FindFirst( $TreeScope_Descendants, $pAndCondition3, $pTreeItem1 ) $oTreeItem1 = ObjCreateInterface( $pTreeItem1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oTreeItem1 ) Then Return ConsoleWrite( "$oTreeItem1 ERR" & @CRLF ) ConsoleWrite( "$oTreeItem1 OK" & @CRLF ) ; --- ScrollItem Pattern (action) Object --- ConsoleWrite( "--- ScrollItem Pattern (action) Object ---" & @CRLF ) Local $pScrollItemPattern1, $oScrollItemPattern1 $oTreeItem1.GetCurrentPattern( $UIA_ScrollItemPatternId, $pScrollItemPattern1 ) $oScrollItemPattern1 = ObjCreateInterface( $pScrollItemPattern1, $sIID_IUIAutomationScrollItemPattern, $dtagIUIAutomationScrollItemPattern ) If Not IsObj( $oScrollItemPattern1 ) Then Return ConsoleWrite( "$oScrollItemPattern1 ERR" & @CRLF ) ConsoleWrite( "$oScrollItemPattern1 OK" & @CRLF ) ; --- ScrollItem Pattern (action) Methods --- ConsoleWrite( "--- ScrollItem Pattern (action) Methods ---" & @CRLF ) $oScrollItemPattern1.ScrollIntoView() ConsoleWrite( "$oScrollItemPattern1.ScrollIntoView()" & @CRLF ) EndFunc SciTE output: $oUIAutomation OK $oDesktop OK --- Find window/control --- $pAndCondition1 OK $oWindow1 OK --- Find window/control --- $pAndCondition3 OK $oTreeItem1 OK --- ScrollItem Pattern (action) Object --- $oScrollItemPattern1 OK --- ScrollItem Pattern (action) Methods --- $oScrollItemPattern1.ScrollIntoView() 6. Scroll Control Pattern From Microsoft documentation: The Scroll control pattern is used to support a control that acts as a scrollable container for a collection of child objects. Preparation Run the ScrollItem example in the section above. The C-drive should be visible near the top of the treeview. The treeview scrollbar thumb should also be visible near the top of the treeview. Open UIASpy, place the mouse over the C-drive, press F2. The treeview should be detected. Code The UIASpy generated code shows how to scroll the treeview one page down (Scroll.au3, Scroll-a.au3 contains code directly from UIASpy): expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "..\..\..\Includes\CUIAutomation2.au3" ; Get proper version in UIASpy Includes folder ;#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0, $pCondition1, $pAndCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "CabinetWClass", $pCondition0 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "System (C:)", $pCondition1 ) ; <<<<<<<<<<<<< $oUIAutomation.CreateAndCondition( $pCondition0, $pCondition1, $pAndCondition1 ) If Not $pAndCondition1 Then Return ConsoleWrite( "$pAndCondition1 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition1 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Descendants, $pAndCondition1, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition2 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TreeControlTypeId, $pCondition2 ) If Not $pCondition2 Then Return ConsoleWrite( "$pCondition2 ERR" & @CRLF ) ConsoleWrite( "$pCondition2 OK" & @CRLF ) Local $pTree1, $oTree1 $oWindow1.FindFirst( $TreeScope_Descendants, $pCondition2, $pTree1 ) $oTree1 = ObjCreateInterface( $pTree1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oTree1 ) Then Return ConsoleWrite( "$oTree1 ERR" & @CRLF ) ConsoleWrite( "$oTree1 OK" & @CRLF ) ; --- Scroll Pattern (action) Object --- ConsoleWrite( "--- Scroll Pattern (action) Object ---" & @CRLF ) Local $pScrollPattern1, $oScrollPattern1 $oTree1.GetCurrentPattern( $UIA_ScrollPatternId, $pScrollPattern1 ) $oScrollPattern1 = ObjCreateInterface( $pScrollPattern1, $sIID_IUIAutomationScrollPattern, $dtagIUIAutomationScrollPattern ) If Not IsObj( $oScrollPattern1 ) Then Return ConsoleWrite( "$oScrollPattern1 ERR" & @CRLF ) ConsoleWrite( "$oScrollPattern1 OK" & @CRLF ) ; --- Scroll Pattern (action) Methods --- ConsoleWrite( "--- Scroll Pattern (action) Methods ---" & @CRLF ) $oScrollPattern1.Scroll( $ScrollAmount_NoAmount, $ScrollAmount_LargeIncrement ) ; Horizontally, vertically ConsoleWrite( "$oScrollPattern1.Scroll()" & @CRLF ) EndFunc SciTE output: $oUIAutomation OK $oDesktop OK --- Find window/control --- $pAndCondition1 OK $oWindow1 OK --- Find window/control --- $pCondition2 OK $oTree1 OK --- Scroll Pattern (action) Object --- $oScrollPattern1 OK --- Scroll Pattern (action) Methods --- $oScrollPattern1.Scroll() Remarks ScrollAmount values are found in CUIAutomation2.au3 and Microsoft documentation. 7. Grid Control Pattern From Microsoft documentation: The Grid control pattern supports controls that acts as a container for a collection of child controls that are organized in a two-dimensional logical coordinate system that can be traversed by row and column. These child controls can eg. be the individual cells in a listview. Preparation File Explorer should look as shown in the picture. Open UIASpy, place the mouse over the first visible item in the listview, press F2, press F7. F2 detects the listview item that's parent for the individual item cells (image and edit controls). F7 navigates to the parent control of the item which is the listview. Code Code as created with UIASpy to get the text in a listview cell given by row and column number (Grid.au3, Grid-a.au3 contains code directly from UIASpy): expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "..\..\..\Includes\CUIAutomation2.au3" ; Get proper version in UIASpy Includes folder ;#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0, $pCondition1, $pAndCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "CabinetWClass", $pCondition0 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "System (C:)", $pCondition1 ) ; <<<<<<<<<<<<<<<<<<<<<<< $oUIAutomation.CreateAndCondition( $pCondition0, $pCondition1, $pAndCondition1 ) If Not $pAndCondition1 Then Return ConsoleWrite( "$pAndCondition1 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition1 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Descendants, $pAndCondition1, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition2 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ListControlTypeId, $pCondition2 ) If Not $pCondition2 Then Return ConsoleWrite( "$pCondition2 ERR" & @CRLF ) ConsoleWrite( "$pCondition2 OK" & @CRLF ) Local $pList1, $oList1 $oWindow1.FindFirst( $TreeScope_Descendants, $pCondition2, $pList1 ) $oList1 = ObjCreateInterface( $pList1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oList1 ) Then Return ConsoleWrite( "$oList1 ERR" & @CRLF ) ConsoleWrite( "$oList1 OK" & @CRLF ) ; --- Grid Pattern (action) Object --- ConsoleWrite( "--- Grid Pattern (action) Object ---" & @CRLF ) Local $pGridPattern1, $oGridPattern1 $oList1.GetCurrentPattern( $UIA_GridPatternId, $pGridPattern1 ) $oGridPattern1 = ObjCreateInterface( $pGridPattern1, $sIID_IUIAutomationGridPattern, $dtagIUIAutomationGridPattern ) If Not IsObj( $oGridPattern1 ) Then Return ConsoleWrite( "$oGridPattern1 ERR" & @CRLF ) ConsoleWrite( "$oGridPattern1 OK" & @CRLF ) ; --- Control Pattern Properties --- ConsoleWrite( "--- Control Pattern Properties ---" & @CRLF ) Local $iGridColumnCount1 $oList1.GetCurrentPropertyValue( $UIA_GridColumnCountPropertyId, $iGridColumnCount1 ) ConsoleWrite( "$iGridColumnCount1 = " & $iGridColumnCount1 & @CRLF ) Local $iGridRowCount1 $oList1.GetCurrentPropertyValue( $UIA_GridRowCountPropertyId, $iGridRowCount1 ) ConsoleWrite( "$iGridRowCount1 = " & $iGridRowCount1 & @CRLF ) ; --- Grid Pattern (action) Methods --- ConsoleWrite( "--- Grid Pattern (action) Methods ---" & @CRLF ) Local $pEdit1, $oEdit1 $oGridPattern1.GetItem( 4, 0, $pEdit1 ) ; Row, col ConsoleWrite( "$oGridPattern1.GetItem()" & @CRLF ) $oEdit1 = ObjCreateInterface( $pEdit1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) ; --- Control Pattern Properties --- ConsoleWrite( "--- Control Pattern Properties ---" & @CRLF ) Local $sValueValue1 $oEdit1.GetCurrentPropertyValue( $UIA_ValueValuePropertyId, $sValueValue1 ) ConsoleWrite( "$sValueValue1 = " & $sValueValue1 & @CRLF ) EndFunc SciTE output: $oUIAutomation OK $oDesktop OK --- Find window/control --- $pAndCondition1 OK $oWindow1 OK --- Find window/control --- $pCondition2 OK $oList1 OK --- Grid Pattern (action) Object --- $oGridPattern1 OK --- Control Pattern Properties --- $iGridColumnCount1 = 4 $iGridRowCount1 = 21 --- Grid Pattern (action) Methods --- $oGridPattern1.GetItem() --- Control Pattern Properties --- $sValueValue1 = Intel Remarks Read about $oGridPattern.GetItem() in the Microsoft documentation. 8. Table Control Pattern From Microsoft documentation: The Table control pattern is used to support controls that act as containers for a collection of child elements. The children of the container element must be organized in a two-dimensional logical coordinate system that can be traversed by row and column. This control pattern is analogous to the Grid control pattern with the distinction that the Table control pattern must also expose a column and/or row header relationship for each child element. The Table control pattern can be used to get information about the header control in a listview. Preparation File Explorer should look as shown in the picture. Open UIASpy, place the mouse over the header control in the listview, press F2, press F7. F2 detects the header control that's parent for the individual header items. F7 navigates to the parent control of the header which is the listview. Code The code generated with UIASpy shows how to get information about the header control (Table.au3, Table-a.au3 contains code directly from UIASpy): expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "..\..\..\Includes\CUIAutomation2.au3" ; Get proper version in UIASpy Includes folder ;#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0, $pCondition1, $pAndCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "CabinetWClass", $pCondition0 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "System (C:)", $pCondition1 ) ; <<<<<<<<<<<<< $oUIAutomation.CreateAndCondition( $pCondition0, $pCondition1, $pAndCondition1 ) If Not $pAndCondition1 Then Return ConsoleWrite( "$pAndCondition1 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition1 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Descendants, $pAndCondition1, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition2 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ListControlTypeId, $pCondition2 ) If Not $pCondition2 Then Return ConsoleWrite( "$pCondition2 ERR" & @CRLF ) ConsoleWrite( "$pCondition2 OK" & @CRLF ) Local $pList1, $oList1 $oWindow1.FindFirst( $TreeScope_Descendants, $pCondition2, $pList1 ) $oList1 = ObjCreateInterface( $pList1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oList1 ) Then Return ConsoleWrite( "$oList1 ERR" & @CRLF ) ConsoleWrite( "$oList1 OK" & @CRLF ) ; --- Table Pattern (action) Object --- ConsoleWrite( "--- Table Pattern (action) Object ---" & @CRLF ) Local $pTablePattern1, $oTablePattern1 $oList1.GetCurrentPattern( $UIA_TablePatternId, $pTablePattern1 ) $oTablePattern1 = ObjCreateInterface( $pTablePattern1, $sIID_IUIAutomationTablePattern, $dtagIUIAutomationTablePattern ) If Not IsObj( $oTablePattern1 ) Then Return ConsoleWrite( "$oTablePattern1 ERR" & @CRLF ) ConsoleWrite( "$oTablePattern1 OK" & @CRLF ) ; --- Table Pattern (action) Methods --- ConsoleWrite( "--- Table Pattern (action) Methods ---" & @CRLF ) Local $pElements $oTablePattern1.GetCurrentColumnHeaders( $pElements ) ConsoleWrite( "$oTablePattern1.GetCurrentColumnHeaders()" & @CRLF ) ; --- Code Snippets --- ConsoleWrite( "--- Code Snippets ---" & @CRLF ) Local $oAutomationElementArray1, $iLength1 ; $pElements is a pointer to an UI Automation element array $oAutomationElementArray1 = ObjCreateInterFace( $pElements, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray ) $oAutomationElementArray1.Length( $iLength1 ) If Not $iLength1 Then Return ConsoleWrite( "$iLength1 = 0 ERR" & @CRLF ) ConsoleWrite( "$iLength1 = " & $iLength1 & @CRLF ) ; --- Code Snippets --- ConsoleWrite( "--- Code Snippets ---" & @CRLF ) Local $pElement1, $oElement1, $sValue1 For $i = 0 To $iLength1 - 1 $oAutomationElementArray1.GetElement( $i, $pElement1 ) $oElement1 = ObjCreateInterface( $pElement1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) $oElement1.GetCurrentPropertyValue( $UIA_ClassNamePropertyId, $sValue1 ) ; $UIA_ClassNamePropertyId is used as example ConsoleWrite( "$sValue1 = " & $sValue1 & @CRLF ) $oElement1.GetCurrentPropertyValue( $UIA_NamePropertyId, $sValue1 ) ConsoleWrite( "$sValue1 = " & $sValue1 & @CRLF ) Next ; --- Copy element info --- ; $UIA_NamePropertyId Name EndFunc SciTE output: $oUIAutomation OK $oDesktop OK --- Find window/control --- $pAndCondition1 OK $oWindow1 OK --- Find window/control --- $pCondition2 OK $oList1 OK --- Table Pattern (action) Object --- $oTablePattern1 OK --- Table Pattern (action) Methods --- $oTablePattern1.GetCurrentColumnHeaders() --- Code Snippets --- $iLength1 = 4 --- Code Snippets --- $sValue1 = UIColumnHeader $sValue1 = Name $sValue1 = UIColumnHeader $sValue1 = Date modified $sValue1 = UIColumnHeader $sValue1 = Type $sValue1 = UIColumnHeader $sValue1 = Size Remarks Note the loop in bottom of the code that's used to traverse the UI Automation element array to get information about the individual header elements. The $UIA_NamePropertyId is copied in UIASpy from the Name header item. 9. Invoke Control Pattern From Microsoft documentation: The Invoke control pattern is used to support controls that do not maintain state when activated but rather initiate or perform a single, unambiguous action. Controls that do maintain state, such as check boxes and radio buttons, must instead implement Toggle and Selection patterns respectively. In short, the Invoke pattern is used to implement the click action. Preparation File Explorer should look as shown in the picture. Select Windows folder in the listview. Open UIASpy, place the mouse over Windows folder, press F2. F2 detects the listview item that's parent for the individual listview fields (image and edit controls). Code Code to click the Windows folder as generated with UIASpy (Invoke.au3, Invoke-a.au3 contains code directly from UIASpy): expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "..\..\..\Includes\CUIAutomation2.au3" ; Get proper version in UIASpy Includes folder ;#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0, $pCondition1, $pAndCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "CabinetWClass", $pCondition0 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "System (C:)", $pCondition1 ) ; <<<<<<<<<<<<<<<<< $oUIAutomation.CreateAndCondition( $pCondition0, $pCondition1, $pAndCondition1 ) If Not $pAndCondition1 Then Return ConsoleWrite( "$pAndCondition1 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition1 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Descendants, $pAndCondition1, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition2, $pCondition3, $pAndCondition3 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ListItemControlTypeId, $pCondition2 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "Windows", $pCondition3 ) ; <<<<<<<<<<<<<<<<<<<<< $oUIAutomation.CreateAndCondition( $pCondition2, $pCondition3, $pAndCondition3 ) If Not $pAndCondition3 Then Return ConsoleWrite( "$pAndCondition3 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition3 OK" & @CRLF ) Local $pListItem1, $oListItem1 $oWindow1.FindFirst( $TreeScope_Descendants, $pAndCondition3, $pListItem1 ) $oListItem1 = ObjCreateInterface( $pListItem1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oListItem1 ) Then Return ConsoleWrite( "$oListItem1 ERR" & @CRLF ) ConsoleWrite( "$oListItem1 OK" & @CRLF ) ; --- Invoke Pattern (action) Object --- ConsoleWrite( "--- Invoke Pattern (action) Object ---" & @CRLF ) Local $pInvokePattern1, $oInvokePattern1 $oListItem1.GetCurrentPattern( $UIA_InvokePatternId, $pInvokePattern1 ) $oInvokePattern1 = ObjCreateInterface( $pInvokePattern1, $sIID_IUIAutomationInvokePattern, $dtagIUIAutomationInvokePattern ) If Not IsObj( $oInvokePattern1 ) Then Return ConsoleWrite( "$oInvokePattern1 ERR" & @CRLF ) ConsoleWrite( "$oInvokePattern1 OK" & @CRLF ) ; --- Invoke Pattern (action) Methods --- ConsoleWrite( "--- Invoke Pattern (action) Methods ---" & @CRLF ) $oInvokePattern1.Invoke() ConsoleWrite( "$oInvokePattern1.Invoke()" & @CRLF ) EndFunc SciTE output: $oUIAutomation OK $oDesktop OK --- Find window/control --- $pAndCondition1 OK $oWindow1 OK --- Find window/control --- $pAndCondition3 OK $oListItem1 OK --- Invoke Pattern (action) Object --- $oInvokePattern1 OK --- Invoke Pattern (action) Methods --- $oInvokePattern1.Invoke() Remarks Sometimes the Invoke() method does not work for a control. Mainly because the method isn't implemented by the provider. The most common workaround is to perform a MouseClick in the middle of the control (calculated from bounding rectangel). See How to topic number 16. Another workaround is to use classic automation code if possible. See How to topic number 17. Examples Other examples: MouseClick in middle of the control: How to topic number 16. Click with classic automation code: How to topic number 17. 10. MultipleView Control Pattern From Microsoft documentation: The MultipleView control pattern is used to support controls that provide, and are able to switch between, multiple representations of the same information or the same set of child controls. Examples of controls that can present multiple views include the listview (which can show its contents as thumbnails, tiles, icons, or details), Microsoft Excel charts (pie, line, bar, cell value with a formula), Microsoft Word documents (normal, web layout, print layout, reading layout, outline), Microsoft Outlook calendar (year, month, week, day), and Microsoft Windows Media Player skins. Preparation File Explorer should look as shown in the picture. Open UIASpy, place the mouse over the first visible item in the listview, press F2, press F7. F2 detects the listview item that's parent for the individual item cells (image and edit controls). F7 navigates to the parent control of the item which is the listview. Code The code generated with UIASpy shows how to get an array of view identifiers (integers). The returned array is a safearray of integers. The code also shows how to extract the integers from the safearray (MultipleView.au3, MultipleView-a.au3 contains code directly from UIASpy): expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "..\..\..\Includes\CUIAutomation2.au3" ; Get proper version in UIASpy Includes folder #include "..\..\..\Includes\UIA_SafeArray.au3" ; Can be copied from UIASpy Includes folder #include "..\..\..\Includes\UIA_Variant.au3" ; Can be copied from UIASpy Includes folder ;#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0, $pCondition1, $pAndCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "CabinetWClass", $pCondition0 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "System (C:)", $pCondition1 ) ; <<<<<<<<<<<<< $oUIAutomation.CreateAndCondition( $pCondition0, $pCondition1, $pAndCondition1 ) If Not $pAndCondition1 Then Return ConsoleWrite( "$pAndCondition1 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition1 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Descendants, $pAndCondition1, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition2 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ListControlTypeId, $pCondition2 ) If Not $pCondition2 Then Return ConsoleWrite( "$pCondition2 ERR" & @CRLF ) ConsoleWrite( "$pCondition2 OK" & @CRLF ) Local $pList1, $oList1 $oWindow1.FindFirst( $TreeScope_Descendants, $pCondition2, $pList1 ) $oList1 = ObjCreateInterface( $pList1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oList1 ) Then Return ConsoleWrite( "$oList1 ERR" & @CRLF ) ConsoleWrite( "$oList1 OK" & @CRLF ) ; --- MultipleView Pattern (action) Object --- ConsoleWrite( "--- MultipleView Pattern (action) Object ---" & @CRLF ) Local $pMultipleViewPattern1, $oMultipleViewPattern1 $oList1.GetCurrentPattern( $UIA_MultipleViewPatternId, $pMultipleViewPattern1 ) $oMultipleViewPattern1 = ObjCreateInterface( $pMultipleViewPattern1, $sIID_IUIAutomationMultipleViewPattern, $dtagIUIAutomationMultipleViewPattern ) If Not IsObj( $oMultipleViewPattern1 ) Then Return ConsoleWrite( "$oMultipleViewPattern1 ERR" & @CRLF ) ConsoleWrite( "$oMultipleViewPattern1 OK" & @CRLF ) ; --- MultipleView Pattern (action) Methods --- ConsoleWrite( "--- MultipleView Pattern (action) Methods ---" & @CRLF ) Local $pSafeArray $oMultipleViewPattern1.GetCurrentSupportedViews( $pSafeArray ) ConsoleWrite( "$oMultipleViewPattern1.GetCurrentSupportedViews()" & @CRLF ) If Not $pSafeArray Then Return ConsoleWrite( "$pSafeArray ERR" & @CRLF ) ConsoleWrite( "$pSafeArray OK" & @CRLF ) Local $iElements, $iViewId SafeArrayGetUBound( $pSafeArray, 1, $iElements ) ConsoleWrite( "$iElements = " & $iElements & @CRLF ) For $i = 0 To $iElements - 1 SafeArrayGetElement( $pSafeArray, $i, $iViewId ) ConsoleWrite( "$iViewId = " & $iViewId & @CRLF ) Next EndFunc SciTE output: $oUIAutomation OK $oDesktop OK --- Find window/control --- $pAndCondition1 OK $oWindow1 OK --- Find window/control --- $pCondition2 OK $oList1 OK --- MultipleView Pattern (action) Object --- $oMultipleViewPattern1 OK --- MultipleView Pattern (action) Methods --- $oMultipleViewPattern1.GetCurrentSupportedViews() $pSafeArray OK $iElements = 7 $iViewId = 0 $iViewId = 1 $iViewId = 2 $iViewId = 3 $iViewId = 4 $iViewId = 5 $iViewId = 6 Remarks Note that UIA_SafeArray.au3 and UIA_Variant.au3 are included in top of the code to be able to handle safearrays. Note also how the view identifiers are extracted from the safearray returned by $oMultipleViewPattern.GetCurrentSupportedViews() in bottom of the code. Read about $oMultipleViewPattern.GetCurrentSupportedViews() in the Microsoft documentation. 11. SelectionItem Control Pattern From Microsoft documentation: The SelectionItem control pattern is used to support controls that act as individual, selectable child items of container controls. Eg. listbox and listview items. Preparation File Explorer should look as shown in the picture. Open UIASpy, place the mouse over the first visible item in the listview, press F2. F2 detects the listview item that's parent for the individual listview fields (image and edit controls). Code The code created with UIASpy shows how to select the first item in the listview and then select additional four items: (SelectionItem.au3, SelectionItem-a.au3 contains code directly from UIASpy): expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "..\..\..\Includes\CUIAutomation2.au3" ; Get proper version in UIASpy Includes folder ;#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0, $pCondition1, $pAndCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "CabinetWClass", $pCondition0 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "System (C:)", $pCondition1 ) ; <<<<<<<<<<<<<<<<< $oUIAutomation.CreateAndCondition( $pCondition0, $pCondition1, $pAndCondition1 ) If Not $pAndCondition1 Then Return ConsoleWrite( "$pAndCondition1 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition1 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Descendants, $pAndCondition1, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition2, $pCondition3, $pAndCondition3 $oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, "0", $pCondition2 ) $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ListItemControlTypeId, $pCondition3 ) $oUIAutomation.CreateAndCondition( $pCondition2, $pCondition3, $pAndCondition3 ) If Not $pAndCondition3 Then Return ConsoleWrite( "$pAndCondition3 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition3 OK" & @CRLF ) Local $pListItem1, $oListItem1 $oWindow1.FindFirst( $TreeScope_Descendants, $pAndCondition3, $pListItem1 ) $oListItem1 = ObjCreateInterface( $pListItem1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oListItem1 ) Then Return ConsoleWrite( "$oListItem1 ERR" & @CRLF ) ConsoleWrite( "$oListItem1 OK" & @CRLF ) ; --- SelectionItem Pattern (action) Object --- ConsoleWrite( "--- SelectionItem Pattern (action) Object ---" & @CRLF ) Local $pSelectionItemPattern1, $oSelectionItemPattern1 $oListItem1.GetCurrentPattern( $UIA_SelectionItemPatternId, $pSelectionItemPattern1 ) $oSelectionItemPattern1 = ObjCreateInterface( $pSelectionItemPattern1, $sIID_IUIAutomationSelectionItemPattern, $dtagIUIAutomationSelectionItemPattern ) If Not IsObj( $oSelectionItemPattern1 ) Then Return ConsoleWrite( "$oSelectionItemPattern1 ERR" & @CRLF ) ConsoleWrite( "$oSelectionItemPattern1 OK" & @CRLF ) ; --- SelectionItem Pattern (action) Methods --- ConsoleWrite( "--- SelectionItem Pattern (action) Methods ---" & @CRLF ) $oSelectionItemPattern1.Select() ConsoleWrite( "$oSelectionItemPattern1.Select()" & @CRLF ) ; --- Add 4 items to selection --- ConsoleWrite( "--- Add 4 items to selection ---" & @CRLF ) For $i = 1 To 4 ; 3 lines copied from code above $oUIAutomation.CreatePropertyCondition( $UIA_AutomationIdPropertyId, String( $i ), $pCondition2 ) ; Modified: "0" --> String( $i ) $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ListItemControlTypeId, $pCondition3 ) $oUIAutomation.CreateAndCondition( $pCondition2, $pCondition3, $pAndCondition3 ) ; 2 lines copied from code above $oWindow1.FindFirst( $TreeScope_Descendants, $pAndCondition3, $pListItem1 ) $oListItem1 = ObjCreateInterface( $pListItem1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) ; 2 lines copied from code above $oListItem1.GetCurrentPattern( $UIA_SelectionItemPatternId, $pSelectionItemPattern1 ) $oSelectionItemPattern1 = ObjCreateInterface( $pSelectionItemPattern1, $sIID_IUIAutomationSelectionItemPattern, $dtagIUIAutomationSelectionItemPattern ) ; 2 lines copied from SelectionItem-a.au3 $oSelectionItemPattern1.AddToSelection() ConsoleWrite( "$oSelectionItemPattern1.AddToSelection()" & @CRLF ) Next EndFunc SciTE output: $oUIAutomation OK $oDesktop OK --- Find window/control --- $pAndCondition1 OK $oWindow1 OK --- Find window/control --- $pAndCondition3 OK $oListItem1 OK --- SelectionItem Pattern (action) Object --- $oSelectionItemPattern1 OK --- SelectionItem Pattern (action) Methods --- $oSelectionItemPattern1.Select() --- Add 4 items to selection --- $oSelectionItemPattern1.AddToSelection() $oSelectionItemPattern1.AddToSelection() $oSelectionItemPattern1.AddToSelection() $oSelectionItemPattern1.AddToSelection() Remarks Note the For-loop to add 4 items to selection. 12. Selection Control Pattern From Microsoft documentation: The Selection control pattern is used to support controls that act as containers for a collection of selectable child items. Eg. a listview with selectable items. Preparation Run the SelectionItem example in the section above. Five items should be selected in top of the listview. Open UIASpy, place the mouse over the first selected item, press F2, press F7. The listview should be detected. F2 detects the listview item that's parent for the individual item cells (image and edit controls). F7 navigates to the parent control of the item which is the listview. Code The UIASpy generated code shows how to get the selected listview items as an UI Automation element array and how to get access to the individual elements in the array: (Selection.au3, Selection-a.au3 contains code directly from UIASpy): expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ;#AutoIt3Wrapper_UseX64=n ; If target application is running as 32 bit code ;#AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "..\..\..\Includes\CUIAutomation2.au3" ; Get proper version in UIASpy Includes folder ;#include "UIA_Functions.au3" ; Can be copied from UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; Get Desktop element Local $pDesktop, $oDesktop $oUIAutomation.GetRootElement( $pDesktop ) $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition0, $pCondition1, $pAndCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "CabinetWClass", $pCondition0 ) $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, "System (C:)", $pCondition1 ) ; <<<<<<<<<<<<< $oUIAutomation.CreateAndCondition( $pCondition0, $pCondition1, $pAndCondition1 ) If Not $pAndCondition1 Then Return ConsoleWrite( "$pAndCondition1 ERR" & @CRLF ) ConsoleWrite( "$pAndCondition1 OK" & @CRLF ) Local $pWindow1, $oWindow1 $oDesktop.FindFirst( $TreeScope_Descendants, $pAndCondition1, $pWindow1 ) $oWindow1 = ObjCreateInterface( $pWindow1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow1 ) Then Return ConsoleWrite( "$oWindow1 ERR" & @CRLF ) ConsoleWrite( "$oWindow1 OK" & @CRLF ) ; --- Find window/control --- ConsoleWrite( "--- Find window/control ---" & @CRLF ) Local $pCondition2 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_ListControlTypeId, $pCondition2 ) If Not $pCondition2 Then Return ConsoleWrite( "$pCondition2 ERR" & @CRLF ) ConsoleWrite( "$pCondition2 OK" & @CRLF ) Local $pList1, $oList1 $oWindow1.FindFirst( $TreeScope_Descendants, $pCondition2, $pList1 ) $oList1 = ObjCreateInterface( $pList1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oList1 ) Then Return ConsoleWrite( "$oList1 ERR" & @CRLF ) ConsoleWrite( "$oList1 OK" & @CRLF ) ; --- Selection Pattern (action) Object --- ConsoleWrite( "--- Selection Pattern (action) Object ---" & @CRLF ) Local $pSelectionPattern1, $oSelectionPattern1 $oList1.GetCurrentPattern( $UIA_SelectionPatternId, $pSelectionPattern1 ) $oSelectionPattern1 = ObjCreateInterface( $pSelectionPattern1, $sIID_IUIAutomationSelectionPattern, $dtagIUIAutomationSelectionPattern ) If Not IsObj( $oSelectionPattern1 ) Then Return ConsoleWrite( "$oSelectionPattern1 ERR" & @CRLF ) ConsoleWrite( "$oSelectionPattern1 OK" & @CRLF ) ; --- Selection Pattern (action) Methods --- ConsoleWrite( "--- Selection Pattern (action) Methods ---" & @CRLF ) Local $pElements $oSelectionPattern1.GetCurrentSelection( $pElements ) ConsoleWrite( "$oSelectionPattern1.GetCurrentSelection()" & @CRLF ) ; --- Code Snippets --- ConsoleWrite( "--- Code Snippets ---" & @CRLF ) Local $oAutomationElementArray1, $iLength1 ; $pElements is a pointer to an UI Automation element array $oAutomationElementArray1 = ObjCreateInterFace( $pElements, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray ) $oAutomationElementArray1.Length( $iLength1 ) If Not $iLength1 Then Return ConsoleWrite( "$iLength1 = 0 ERR" & @CRLF ) ConsoleWrite( "$iLength1 = " & $iLength1 & @CRLF ) ; --- Code Snippets --- ConsoleWrite( "--- Code Snippets ---" & @CRLF ) Local $pElement1, $oElement1, $sValue1 For $i = 0 To $iLength1 - 1 $oAutomationElementArray1.GetElement( $i, $pElement1 ) $oElement1 = ObjCreateInterface( $pElement1, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) $oElement1.GetCurrentPropertyValue( $UIA_ClassNamePropertyId, $sValue1 ) ; $UIA_ClassNamePropertyId is used as example ConsoleWrite( "$sValue1 = " & $sValue1 & @CRLF ) $oElement1.GetCurrentPropertyValue( $UIA_ValueValuePropertyId, $sValue1 ) ConsoleWrite( "$sValue1 = " & $sValue1 & @CRLF ) Next ; --- Copy element info --- ; $UIA_ValueValuePropertyId $Recycle.Bin EndFunc SciTE output: $oUIAutomation OK $oDesktop OK --- Find window/control --- $pAndCondition1 OK $oWindow1 OK --- Find window/control --- $pCondition2 OK $oList1 OK --- Selection Pattern (action) Object --- $oSelectionPattern1 OK --- Selection Pattern (action) Methods --- $oSelectionPattern1.GetCurrentSelection() --- Code Snippets --- $iLength1 = 5 --- Code Snippets --- $sValue1 = UIItem $sValue1 = $Recycle.Bin $sValue1 = UIItem $sValue1 = Config.Msi $sValue1 = UIItem $sValue1 = Documents and Settings $sValue1 = UIItem $sValue1 = Intel $sValue1 = UIItem $sValue1 = MSOCache Remarks Note the loop in bottom of the code that's used to traverse the UI Automation element array to get information about the individual elements. The $UIA_ValueValuePropertyId is copied in UIASpy from the edit element of the first selected listview item. Top of post Edited February 9, 2020 by LarsJ Text updates Decibel and jugador 2 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
AtomicSeek Posted March 13, 2019 Share Posted March 13, 2019 (edited) Dear LarsJ, I have one small suggestion: Ternary Operator can be used in order to shorten the error checking codes: #include "Includes\CUIAutomation2.au3" ; Get proper version in UIASpy Includes folder Opt( "MustDeclareVars", 1 ) Example() ; Ternary Operator ; Conditionally chooses one of two responses based on the result of an expression. ; (expression) ? (expression1 if expression is True) : (expression2 if expression is False) Func Example() ; Create UI Automation object Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation ) ; by using the Ternary Operator, the following 2 lines If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF ) ConsoleWrite( "$oUIAutomation OK" & @CRLF ) ; can be replaced by this line ConsoleWrite ( (IsObj($oUIAutomation)) ? ("$oUIAutomation OK" & @CRLF) : ("$oUIAutomation ERR" & @CRLF) ) ; or even shorter by this line ConsoleWrite ( "$oUIAutomation " & ( IsObj($oUIAutomation) ? "OK" : "ERR" ) & @CRLF ) EndFunc .. but it's true that this way the Return part dissapears .. Thak you for your amazing help! Best regards, AtomicSeek Edited March 13, 2019 by AtomicSeek Link to comment Share on other sites More sharing options...
BrewManNH Posted March 13, 2019 Share Posted March 13, 2019 35 minutes ago, AtomicSeek said: but it's true that this way the Return part dissapears .. The Return part is the all important part of that line. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
AtomicSeek Posted March 13, 2019 Share Posted March 13, 2019 6 minutes ago, BrewManNH said: The Return part is the all important part of that line. Being focused on ways to shorten the code, I missed the most important part there: the return functionality in case of error .. Link to comment Share on other sites More sharing options...
BrewManNH Posted March 13, 2019 Share Posted March 13, 2019 There's no reason that you'd need to shorten code unless what you wrote isn't working or is unclear. Shortening just for the sake of getting less lines of code is usually unnecessary.Most of the time, when someone shortens code they end up making that code extremely hard to follow for anyone else looking at it, not to mention looking at it for yourself months down the road. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
AtomicSeek Posted March 13, 2019 Share Posted March 13, 2019 44 minutes ago, BrewManNH said: There's no reason that you'd need to shorten code unless what you wrote isn't working or is unclear. Shortening just for the sake of getting less lines of code is usually unnecessary.Most of the time, when someone shortens code they end up making that code extremely hard to follow for anyone else looking at it, not to mention looking at it for yourself months down the road. I am a fan of clean code, and comparing the native AutoIt code, with this way of using the UI Automation code in AutoIt, for the same simple task (for example, checking if a window exists and activating it), the result is very different in size and approach. Of course I am more than happy and thankful to LarsJ for his work, giving us a way to automate what we could not automate with native AutoIt code. In the same time, I am also looking for ways to shorten the UI Automation approach up to a level similar with the native AutoIt code. I'm sorry for my intervention, I did not want to deviate in any way this great topic.. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now