Sign in to follow this  
Followers 0

ControlTreeView: Search for Text

2 posts in this topic

#1 ·  Posted (edited)

I enjoyed my foray into recursive-searching and tree traversals. Too bad the UDF's had that figured out a long time ago. I guess I was too excited that TreeView controls now have native support. I post this here so that I don't feel like a total loser.

#Include <GuiTreeView.au3>

Func _TreeViewSearch( $sWinTitle, $sWinText, $sControlID, $sSearchText, $sNode = "" )   
    Local $iItemCount = ControlTreeView( $sWinTitle, $sWinText, $sControlID, "GetItemCount", $sNode )
    Local $sTreeNodeHistory = ""
    if $sNode <> "" then $sTreeNodeHistory = $sNode & "|"       
    For $i = 0 to ( $iItemCount - 1 )
        $sNodeText = ControlTreeView( $sWinTitle, $sWinText, $sControlID, "GetText", $sTreeNodeHistory & "#" & $i )
        If $sNodeText = $sSearchText then 
            Return $sTreeNodeHistory & "#" & $i
            $result = _TreeViewSearch( $sWinTitle, $sWinText, $sControlID, $sSearchText, $sTreeNodeHistory & "#" & $i ) 
            If $result <> "" then Return $result

ShellExecute( "C:\Program Files\AutoIt3\AutoIt3.chm" )
WinWait( "AutoIt Help", "" )
WinActivate( "AutoIt Help", "" )

While ( ControlCommand( "AutoIt Help", "", "SysTabControl321", "CurrentTab" ) > 1 )
    ControlCommand( "AutoIt Help", "", "SysTabControl321", "TabLeft" )
    Sleep( 100 ) 

; METHOD #1: Using UDF's
; This is faster. Too bad for me.
;~  $hWnd = ControlGetHandle( "AutoIt Help", "", "SysTreeView321" )
;~  $hItem = _GUICtrlTreeView_FindItem( $hWnd, "ControlTreeView" )
;~  _GUICtrlTreeView_SelectItem( $hWnd, $hItem )

; METHOD #2: Using my Function + Native ControlTreeView Functions
; Slower. Why did I write all this? I guess to get the ControlTreeView Hierarchy
$location = _TreeViewSearch( "AutoIt Help", "", "SysTreeView321", "ControlTreeView", "#0" )
ConsoleWrite( $location & @CRLF)
ControlTreeView( "AutoIt Help", "", "SysTreeView321", "Select", $location )


Edited by zfisherdrums

Share this post

Link to post
Share on other sites

Last line can be following (to view topic):


BTW. {F6} allows to set focus into content part.

So you can simulate topic's reading, by these additional lines:





The point of world view

Share this post

Link to post
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
Sign in to follow this  
Followers 0