Mbee Posted July 22, 2020 Share Posted July 22, 2020 Dear wise, @LarsJ I started the following thread a few days ago: How can I identify "Normal" windows? I've been struggling (with the gracious assistance of @Nine ) to distinguish what I call "Normal" windows from the hundreds of other windows returned by WinList() or by traversing the visible, non-tool child windows of the Desktop window, but I haven't found a reliable way to do identify what I'm looking for. So I thought I'd use the various Spy tools available to see if I could identify some aspect of the desired windows that's not present in the other windows, but I failed to find such distinguishing characteristics. Then I launched your amazing UIA Spy tool, and lo, right in the left pane of very first window was just what I needed if one includes only those entries marked "Window"! Here's what I was looking at: And you included the source as well! Unfortunately, I'm insufficiently knowledgeable to follow your rather sophisticated code (no criticism intended, of course -- I'm just not smart enough). If you could spare me the time, could I gently impose on you to explain which attributes you examine in order to identify the "Window" entries? I would be greatly indebted to you! Thank you! Link to comment Share on other sites More sharing options...
LarsJ Posted July 22, 2020 Share Posted July 22, 2020 In UIA code, an application top window is identified by the window control type being either $UIA_WindowControlTypeId or $UIA_PaneControlTypeId. E.g. the Chrome top window is a Pane control. Thus, not all application top windows can be identified solely through the $UIA_WindowControlTypeId. And the window must be a direct child of the Desktop. UIA code to identify all application top windows: expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #AutoIt3Wrapper_UseX64=y ; If target application is running as 64 bit code #include "UIA_Constants.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, $dtag_IUIAutomation ) 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, $dtag_IUIAutomationElement ) If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF ) ConsoleWrite( "$oDesktop OK" & @CRLF ) ; --- Code Snippets --- ConsoleWrite( "--- Code Snippets ---" & @CRLF ) ; --- Or condition to find window/control --- ConsoleWrite( "--- Or condition to find window/control ---" & @CRLF ) Local $pCondition0, $pCondition1, $pOrCondition1 $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_WindowControlTypeId, $pCondition0 ) $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_PaneControlTypeId, $pCondition1 ) $oUIAutomation.CreateOrCondition( $pCondition0, $pCondition1, $pOrCondition1 ) If Not $pOrCondition1 Then Return ConsoleWrite( "$pOrCondition1 ERR" & @CRLF ) ConsoleWrite( "$pOrCondition1 OK" & @CRLF ) ; --- $oUIElement methods --- ConsoleWrite( "--- $oUIElement methods ---" & @CRLF ) Local $pElements ;$oDesktop.FindAll( $TreeScope_Children, $pCondition0, $pElements ) ; Windows only $oDesktop.FindAll( $TreeScope_Children, $pOrCondition1, $pElements ) ; Windows and Panes ConsoleWrite( "$oDesktop.FindAll()" & @CRLF ) ; --- Code Snippets --- ConsoleWrite( "--- Code Snippets ---" & @CRLF ) Local $oUIElementArray1, $iLength1 ; $pElements is a pointer to an UI Automation element array $oUIElementArray1 = ObjCreateInterFace( $pElements, $sIID_IUIAutomationElementArray, $dtag_IUIAutomationElementArray ) $oUIElementArray1.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 Local $sClassName1, $sLocalizedControlType1, $sName1, $hNativeWindowHandle1 For $i = 0 To $iLength1 - 1 $oUIElementArray1.GetElement( $i, $pElement1 ) $oElement1 = ObjCreateInterface( $pElement1, $sIID_IUIAutomationElement, $dtag_IUIAutomationElement ) $oElement1.GetCurrentPropertyValue( $UIA_ClassNamePropertyId, $sClassName1 ) Switch $sClassName1 Case "Progman", "Shell_TrayWnd" ContinueLoop EndSwitch ConsoleWrite( @CRLF & "$sClassName1 = " & $sClassName1 & @CRLF ) $oElement1.GetCurrentPropertyValue( $UIA_LocalizedControlTypePropertyId, $sLocalizedControlType1 ) ConsoleWrite( "$sLocalizedControlType1 = " & $sLocalizedControlType1 & @CRLF ) $oElement1.GetCurrentPropertyValue( $UIA_NamePropertyId, $sName1 ) ConsoleWrite( "$sName1 = " & $sName1 & @CRLF ) $oElement1.GetCurrentPropertyValue( $UIA_NativeWindowHandlePropertyId, $hNativeWindowHandle1 ) ConsoleWrite( "$hNativeWindowHandle1 = " & HWnd( $hNativeWindowHandle1 ) & @CRLF ) Next EndFunc Note the Switch section to exclude windows that are not considered normal windows: Switch $sClassName1 Case "Progman", "Shell_TrayWnd" ContinueLoop EndSwitch Output: expandcollapse popup$oUIAutomation OK $oDesktop OK --- Code Snippets --- --- Or condition to find window/control --- $pOrCondition1 OK --- $oUIElement methods --- $oDesktop.FindAll() --- Code Snippets --- $iLength1 = 11 --- Code Snippets --- $sClassName1 = SciTEWindow $sLocalizedControlType1 = window $sName1 = D:\Programmering\AutoIt\Temp\UIA related issues\How does UIA Spy identify these windows\tst00.au3 - SciTE $hNativeWindowHandle1 = 0x000000000002056C $sClassName1 = Notepad++ $sLocalizedControlType1 = window $sName1 = D:\Programmering\AutoIt\Temp\UIA related issues\How does UIA Spy identify these windows\tst00.au3 - Notepad++ $hNativeWindowHandle1 = 0x000000000006036A $sClassName1 = Chrome_WidgetWin_1 $sLocalizedControlType1 = pane $sName1 = Kind LarsJ, how does UIA Spy identify these windows? - AutoIt General Help and Support - AutoIt Forums - Microsoft Edge $hNativeWindowHandle1 = 0x00000000000201E4 $sClassName1 = AutoIt v3 GUI $sLocalizedControlType1 = window $sName1 = UIASpy - UI Automation Spy Tool $hNativeWindowHandle1 = 0x000000000005035E $sClassName1 = MozillaWindowClass $sLocalizedControlType1 = window $sName1 = Mozilla Firefox $hNativeWindowHandle1 = 0x00000000000905EE $sClassName1 = Chrome_WidgetWin_1 $sLocalizedControlType1 = pane $sName1 = about:blank - Google Chrome $hNativeWindowHandle1 = 0x000000000001043C $sClassName1 = IEFrame $sLocalizedControlType1 = window $sName1 = Blank Page - Internet Explorer $hNativeWindowHandle1 = 0x0000000000020480 $sClassName1 = CabinetWClass $sLocalizedControlType1 = window $sName1 = How does UIA Spy identify these windows $hNativeWindowHandle1 = 0x0000000000030246 $sClassName1 = CabinetWClass $sLocalizedControlType1 = window $sName1 = UIASpy $hNativeWindowHandle1 = 0x00000000000502B8 Decibel and Exit 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...
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