Jump to content

How to access the items found with ControlTreeView?


Go to solution Solved by Zedna,

Recommended Posts

I am trying to loop through a branch of a Treeview.
When I use the ControlTreeView with the option GetItemCount, it returns 2, being there are 2 items, which is correct.
What I can not figure out is how I can loop through these items and select them one by one.

I am new to AutoIT so this question can be a low brainer, but do not get any further for the moment.

Link to comment
Share on other sites

I saw these examples, but am I wrong that first the treeview is being build before using it.
Here you have the handle to the tree, but I do seem to succeed to get the handle of the object found in the ControlTreeView.

Some example

MsgBox(0, "Nr. of items: ", ControlTreeView("Monitor","" ,"" ,"GetItemCount","#0|<Preferences>|interface"))

This returns 2 items found.

I have taken the code you pointed to, but I do not see the interfaces, which are named "interface" and "interface1".
Here I am lost:
 

local $str 
$TV010 = ControlGetHandle ("Monitor", "", "")


    for $1 = 0 to _GUICtrlTreeView_GetCount($TV010)

        $str &= stringformat( 'Text = %-15s Child Switch = %-5s CTLID = %03i Parent CTLID = %03i Parent Handle = %-8s Sibling Count = %03i Child Count = %03i', _
                    _GUICtrlTreeView_GetText($TV010, $1), _
                    _GUICtrlTreeView_GetChildren($TV010,$1), _
                    _GUICtrlTreeView_GetItemParam($tv010,$1), _
                    _GUICtrlTreeView_GetParentParam($TV010,$1), _
                    _GUICtrlTreeView_GetParentHandle($TV010,$1), _
                    _GUICtrlTreeView_GetSiblingCount($TV010,$1), _
                    _GUICtrlTreeView_GetChildCount($TV010,$1) ) & @lf
    next

    ConsoleWrite($str & @LF)

 

Link to comment
Share on other sites

  • Solution
Posted (edited)

Here is my function _TreeView_GetAll() which gets whole content of TreeView control, in this case even from external application:

Here you can see how to simply traverse the whole TreeView ...

 

#Include <String.au3>
#Include <GuiTreeView.au3>

$sAll = _TreeView_GetAll('OLE/COM Object Viewer', '', 'SysTreeView322')

FileDelete('treeview_get_all.txt')
FileWrite('treeview_get_all.txt', $sAll)
;~ClipPut($sAll)

Func _TreeView_GetAll($title, $text, $classNN, $expand = False, $indent = '  ', $bullet = '') ; $bullet = '- '
    $hWnd = ControlGetHandle($title, $text, $classNN)

    $sAll = ''
    If $expand Then _GUICtrlTreeView_Expand($hWnd) ; Expand All

    $hItem = _GUICtrlTreeView_GetFirstItem($hWnd)
    While $hItem <> 0x00000000
        $sItem = _GUICtrlTreeView_GetText($hWnd, $hItem)
        $level = _GUICtrlTreeView_Level($hWnd, $hItem)
        $sIndent = _StringRepeat($indent, $level)
        $sAll &= $sIndent & $bullet & $sItem & @CRLF
        $hItem = _GUICtrlTreeView_GetNext($hWnd, $hItem)
    WEnd

    Return $sAll
EndFunc

 

Edited by Zedna
Link to comment
Share on other sites

My problem lies in the correct setting of the _TreeView_GetAll (or ControlGetHandle) parameters.
When Specifying 'Monitor' instead of 'OLE/COM Object viewer' then the routine works, but the content of the wrong SysTreeView322 is shown.
The program I want to automate, which I only use, has multiple SysTreeView windows, each with the same ID. All are packed in a control, and these ones are different.

By using keystrokes I am able to direct the ControlTreeView to the correct TreeView, but I do not know how to do this for the ControlGetHandle.
When I use the second parameter, the result is empty.

When I set the ID of the control above the treeview in the third parameter, the result is empty.

No idea how this should work.
 

Link to comment
Share on other sites

now I understood that _TreeView is not yours but from another program

let's open the auto it help file and try this

#include <GuiTreeView.au3>

$hWnd = WinActivate("AutoIt Help (v3.3.16.1)", "")
$hTreeView = ControlGetHandle($hWnd, "", "SysTreeView321")
ConsoleWrite("$hTreeView=" & $hTreeView & @CRLF)

$sTViewPath = "AutoIt|Function Reference|Window Management|Controls"


$iItemCnt = ControlTreeView ( $hWnd, "", $hTreeView, "GetItemCount" , $sTViewPath)
ConsoleWrite("Item Count " & $iItemCnt & @CRLF)

$hItemFound = _GUICtrlTreeView_FindItem($hTreeView, "ControlClick")
ConsoleWrite("$hItemFound=" & $hItemFound & @CRLF)

_GUICtrlTreeView_SelectItem($hTreeView, $hItemFound)
Local $hItemOld = $hItemFound

For $i = 1 To $iItemCnt -1
    $hItemOld = _GUICtrlTreeView_GetNext($hTreeView, $hItemOld )
    _GUICtrlTreeView_SelectItem($hTreeView, $hItemOld)
    Sleep(500)
Next

 

I know that I know nothing

Link to comment
Share on other sites

Found it, thank you.
Each SysList32x view gets an x where the x indicated the one that is currently active.
By first navigating to the correct window with keypresses and making this one active, i can address the SysList321 and now I have it.

Super, thank you.

Link to comment
Share on other sites

Create an account or sign in to comment

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

Create an account

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

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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