rcmaehl Posted March 31, 2017 Share Posted March 31, 2017 (edited) I'm having a bit of an issue getting data from an ATL:SysListView32 class on a Window. AutoIt Window Info does not seem to be able to detect the text in it. I've searched the forums and the only alternatives I can find have had their links broken from forum conversions or are from 2012 or earlier. Is there a specific way I can do this or an alternative tool I can try? Thanks, -RC Edited March 31, 2017 by rcmaehl My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.My Projects WhyNotWin11Cisco Finesse, Github, IRC UDF, WindowEx UDF Link to comment Share on other sites More sharing options...
LarsJ Posted April 3, 2017 Share Posted April 3, 2017 (edited) If the AutoIt Window Info tool isn't able to detect a control the standard way to proceed is to try with the UI Automation framework, which has been the Microsoft automation platform for the last 10 years. You should start by checking if the UI Automation framework is able to detect your control. The easiest way to do that is to use Inspect.exe which is a Microsoft tool. You can find Inspect.exe in the bin-folder of the Windows 10 SDK (can also be installed on windows 7/8). The Windows 10 SDK takes up about 2.5 GB of diskspace. If you only need Inspect.exe you can copy the 32 and 64 bit versions of the program and then uninstall the SDK again (installing the SDK is the only legal way to get a copy of Inspect.exe). You can also find a copy of Inspect.exe here (the RAR-file can be extracted with 7-Zip). Double click Inspect.exe to start it and hover the mouse pointer over the control. You'll probably see a lot of information. In a Combo box in upper left corner of Inspect.exe you can switch between UI Automation mode (default) and MSAA mode (Microsoft Active Accessibility). MSAA mode can be useful if your program is very old (more than 10 years old). If Inspect.exe can identify your control you can use the AutoIt implementation of the UI Automation framework to automate the control. Here is an example with the TreeView in Windows/File Explorer left pane window. The Intel folder on the C-drive is selected: Inspect.exe can identify the TreeView item and extract a lot of information. The Action menu is opened and the Expand action is highlighted: When the Expand menu item is clicked the TreeView is expanded: With Inspect.exe you can test if the TreeView can be automated with UI Automation code. And you can perform the test without writing a single line of code. In the next two pictures the Intel folder is collapsed again. With Inspect.exe you can relatively easily get an impression of whether you're able to automate the window or control. And you can figure it out before you start writing code. The code box shows how to automate the manual procedure above with UI Automation code. Windows/File Explorer must be open and the C-drive must be expanded as shown in the last picture. The code expands and collapses the Windows folder: expandcollapse popup#include "CUIAutomation2.au3" Opt( "MustDeclareVars", 1 ) Example() Func Example() ; Flag to handle Windows XP Local $fXP = ( @OSVersion = "WIN_XP" ) ; Get window handle for Windows/File Explorer on XP, Vista, 7, 8, 10 Local $hWindow = WinGetHandle( "[REGEXPCLASS:^(Cabinet|Explore)WClass$]" ) If Not $hWindow Then Return ConsoleWrite( "$hWindow ERR" & @CRLF ) ConsoleWrite( "$hWindow OK" & @CRLF ) ; Activate the window WinActivate( $hWindow ) ; 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 UI Automation element from window handle Local $pWindow, $oWindow $oUIAutomation.ElementFromHandle( $hWindow, $pWindow ) $oWindow = ObjCreateInterface( $pWindow, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oWindow ) Then Return ConsoleWrite( "$oWindow ERR" & @CRLF ) ConsoleWrite( "$oWindow OK" & @CRLF ) ; Condition to find the Windows folder in the TreeView ; We use two conditions to find the Windows folder ; A condition to find the folder as a TreeView item ; A condition to find the folder by name (Windows) ; TreeView item Local $pCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TreeItemControlTypeId, $pCondition1 ) If Not $pCondition1 Then Return ConsoleWrite( "$pCondition1 ERR" & @CRLF ) ConsoleWrite( "$pCondition1 OK" & @CRLF ) ; Folder name Local $pCondition2 ; Note that $UIA_NamePropertyId ia a CASE SENSITIVE condition $oUIAutomation.CreatePropertyCondition( $UIA_NamePropertyId, ( $fXP ? "WINDOWS" : "Windows" ), $pCondition2 ) If Not $pCondition2 Then Return ConsoleWrite( "$pCondition2 ERR" & @CRLF ) ConsoleWrite( "$pCondition2 OK" & @CRLF ) ; And condition Local $pCondition $oUIAutomation.CreateAndCondition( $pCondition1, $pCondition2, $pCondition ) If Not $pCondition Then Return ConsoleWrite( "$pCondition ERR" & @CRLF ) ConsoleWrite( "$pCondition OK" & @CRLF ) ; Find folder Local $pFolder, $oFolder $oWindow.FindFirst( $TreeScope_Descendants, $pCondition, $pFolder ) $oFolder = ObjCreateInterface( $pFolder, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oFolder ) Then Return ConsoleWrite( "$oFolder ERR" & @CRLF ) ConsoleWrite( "$oFolder OK" & @CRLF ) If Not $fXP Then ; For visual verification ; XP: SetFocus expands the folder $oFolder.SetFocus() ; Not necessary ConsoleWrite( "SetFocus OK" & @CRLF ) EndIf ; ExpandCollapse pattern object ; Pattern objects are used for ACTIONS Local $pExpandCollapse, $oExpandCollapse $oFolder.GetCurrentPattern( $UIA_ExpandCollapsePatternId, $pExpandCollapse ) $oExpandCollapse = ObjCreateInterface( $pExpandCollapse, $sIID_IUIAutomationExpandCollapsePattern, $dtagIUIAutomationExpandCollapsePattern ) If Not IsObj( $oExpandCollapse ) Then Return ConsoleWrite( "$oExpandCollapse ERR" & @CRLF ) ConsoleWrite( "$oExpandCollapse OK" & @CRLF ) ; Wait 5 seconds Sleep( 5000 ) ; Expand folder $oExpandCollapse.Expand() ConsoleWrite( @CRLF & "Expand OK" & @CRLF ) ; Wait 5 seconds Sleep( 5000 ) ; Collapse folder $oExpandCollapse.Collapse() ConsoleWrite( @CRLF & "Collapse OK" & @CRLF ) EndFunc Output in SciTE console: $hWindow OK $oUIAutomation OK $oWindow OK $pCondition1 OK $pCondition2 OK $pCondition OK $oFolder OK SetFocus OK $oExpandCollapse OK Expand OK Collapse OK The code is tested on Windows 10, 7 and XP. The zip file contains the example code and CUIAutomation2.au3. Run the code in SciTE. Explorer.7z An alternative to Inspect.exe is the simplespy.au3 script which is included in UIA_V0_63.zip in bottom of first post in the UI Automation thread. Another alternative to both Inspect.exe and simplespy.au3 is UIASpy - UI Automation Spy Tool. Examples of UIASpy use are found in Using UI Automation Code in AutoIt. With the code in post 71 of the UI Automation thread you can print information in SciTE console about the controls in a window. The information is printed in a hierarchical structure like a treeview. Edited January 26, 2019 by LarsJ New image links rcmaehl and lee321987 1 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...
rcmaehl Posted April 4, 2017 Author Share Posted April 4, 2017 Thanks @LarsJ, I'll try that! My UDFs are generally for me. If they aren't updated for a while, it means I'm not using them myself. As soon as I start using them again, they'll get updated.My Projects WhyNotWin11Cisco Finesse, Github, IRC UDF, WindowEx UDF Link to comment Share on other sites More sharing options...
NassauSky Posted April 9, 2020 Share Posted April 9, 2020 (edited) Thanks @LarsJ but i'm actually having a problem running the script on my Win10 (64). I receive the following output in SciiTE: $hWindow OK $oUIAutomation OK $oWindow OK $pCondition1 OK $pCondition2 OK $pCondition OK$oFolder ERR >Exit code: 0 Time: 0.719 It's failing here: ; Find folder Local $pFolder, $oFolder $oWindow.FindFirst( $TreeScope_Descendants, $pCondition2, $pFolder ) $oFolder = ObjCreateInterface( $pFolder, $sIID_IUIAutomationElement, $dtagIUIAutomationElement ) If Not IsObj( $oFolder ) Then Return ConsoleWrite( "$oFolder ERR" & @CRLF ) ConsoleWrite( "$oFolder OK" & @CRLF ) Sorry about that. I can't figure out what's happening. Edited April 9, 2020 by NassauSky Link to comment Share on other sites More sharing options...
ldub Posted April 14, 2020 Share Posted April 14, 2020 It works for me : Win 10 (64) $hWindow OK $oUIAutomation OK $oWindow OK $pCondition1 OK $pCondition2 OK $pCondition OK $oFolder OK SetFocus OK $oExpandCollapse OK Expand OK Collapse OK Link to comment Share on other sites More sharing options...
lee321987 Posted July 28, 2022 Share Posted July 28, 2022 I was getting $oFolder ERR Fixed it by EXPANDING the folder tree of the C:\ drive before running the script (in the folder tree pane on the left, click the small arrow next to C drive). 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