Search tree and select items

2019-04-16 20:21发布

问题:

Do you know how to scan a tree and select an item. For example is the autoit help file. I expand all the tree and what it has to do next is scan the items with a "history" in its name. If true, it has to select it and sleep for 5 seconds and continue select the next item it finds until end loop.

Global $hWnd = ControlGetHandle("[CLASS:HH Parent;TITLE:AutoIt Help]", "", "[CLASS:SysTreeView32; INSTANCE:1]")

$hItemFound = _GUICtrlTreeView_FindItem($hWnd, "History",True)

_GUICtrlTreeView_SelectItem($hWnd, $hItemFound)

回答1:

It's that easy:

#include <GuiTreeView.au3>

Global $hWnd = ControlGetHandle("[CLASS:HH Parent;TITLE:AutoIt Help]", _
                                "", "[CLASS:SysTreeView32; INSTANCE:1]")

$searchText = "History"
$hItemFound = _GUICtrlTreeView_FindItem($hWnd, $searchText, True)
While $hItemFound
   _GUICtrlTreeView_SelectItem($hWnd, $hItemFound)
   $next = _GUICtrlTreeView_GetNextVisible($hWnd, $hItemFound)
   $hItemFound = _GUICtrlTreeView_FindItem($hWnd, $searchText, True, $next)
   Sleep(5000)
WEnd

By the way, you can use _GUICtrlTreeView_GetNext(...) instead for not only searching the visible next entry but the probably collapsed one as well. The ..._FindItem will search for collapsed Items anyways.

And you'd probably want to use _GUICtrlTreeView_ClickItem(...) in addition to _GUICtrlTreeView_SelectItem(...) to get the proper action performed with a selection as well.



标签: autoit