选择树中的多个项目

时间:2013-06-20 01:25:35

标签: autoit

我在这里有一个代码,搜索并选择名称中带有“Win”的项目。但是我必须修改它以在其名称中搜索带有“Win”,“History”,“Credits”或“#”的项目并选择它。谢谢!

_GUICtrlTreeView_Expand(ControlGetHandle("[CLASS:HH Parent;TITLE:AutoIt Help]","", "[CLASS:SysTreeView32; INSTANCE:1]"),0, True)
Global $hWnd = ControlGetHandle("[CLASS:HH Parent;TITLE:AutoIt Help]", "", "[CLASS:SysTreeView32; INSTANCE:1]")
$searchText = "Win"
$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(1000)
WEnd

我也尝试使用switch但不起作用:

Global $hWnd = ControlGetHandle("[CLASS:HH Parent;TITLE:AutoIt Help]", "", "[CLASS:SysTreeView32; INSTANCE:1]")
$searchText = "Autoit"
$hItemFound = _GUICtrlTreeView_FindItem($hWnd, $searchText, True)
While $hItemFound   
   _GUICtrlTreeView_SelectItem($hWnd, $hItemFound)
   $next = _GUICtrlTreeView_GetNextVisible($hWnd, $hItemFound)

   $foundWinItem = _GUICtrlTreeView_FindItem($hWnd, "Win", True,$next)
   $foundHistoryItem = _GUICtrlTreeView_FindItem($hWnd, "History", True,$next)

   Switch $next
   Case "Win"
      $hItemFound = $foundWinItem
   Case "History"
      $hItemFound = $foundHistoryItem
   EndSwitch
WEnd

1 个答案:

答案 0 :(得分:3)

好吧,似乎索引不是你想要的基础,就像我之前想的那样,因为索引是相对于父级的。

而是手动进行搜索。这是我放在一起的函数,只是迭代每个项目并检查它是否为'|'分隔的字符串列表。

#include <GUITreeview.au3>
#include <Array.au3>

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


For $it In _GUICtrlTreeView_FindAll($hWnd, "Win|History", True)
    _GUICtrlTreeView_SelectItem($hWnd, $it)
Next

Func _GUICtrlTreeView_FindAll($hWnd, $sStrings, $fInStr = False)
    Local $aRet[1] = [0], $hItem

    Local $aStrings = StringSplit($sStrings, Opt("GUIDataSeparatorChar"), 3)

    While 1
        $hItem = _GUICtrlTreeView_GetNext($hWnd, $hItem)
        If $hItem = 0 Then ExitLoop

        $sText = _GUICtrlTreeView_GetText($hWnd, $hItem)

        For $s In $aStrings
            If ($fInStr And StringInStr($sText, $s)) Or $sText = $s Then
                _ArrayAdd($aRet, $hItem)
                $aRet[0] += 1

                ExitLoop
            EndIf
        Next
    WEnd

    Return $aRet
EndFunc   ;==>_GUICtrlTreeView_FindAll