2013-06-20 91 views
1

我在这里有一个代码,它的名称中搜索并选择了一个“Win”项目。但是我必须修改它来搜索其名称中包含“赢”,“历史”,“积分”或“#”的项目并选择它。谢谢!选择树中的多个项目

_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 
+2

我不知道,如果你是知道的,但我的人谁回答堆栈溢出AutoIt的问题,极少数中的一个。我也是在autoit论坛上帮助你的人。在两者之间复制你的问题不会让你得到任何地方。请耐心等待,并在自动论坛上重新阅读我的答案,因为您错误地实施了这个答案。 – Matt

回答

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 
+0

我试过这个,但它不会选择项目。 – NullReferenceException

+0

@ user2379805,在这里工作。虽然速度非常快(选择所有项目的时间少于半秒),所以也许你错过了它。 – Matt

+0

我把'睡眠'功能,但它仍然不会表明它实际上选择的项目。我应该使用'clickItem'吗? – NullReferenceException