1

我在这里有一个代码,可以搜索并选择名称中带有“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
4

1 回答 1

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
于 2013-06-20T08:43:30.907 回答