Jump to content

ControlTreeView: Search for Text


zfisherdrums
 Share

Recommended Posts

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
        Else
            $result = _TreeViewSearch( $sWinTitle, $sWinText, $sControlID, $sSearchText, $sTreeNodeHistory & "#" & $i ) 
            If $result <> "" then Return $result
        EndIf
    Next
EndFunc

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 ) 
Wend

; 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 )

Zach...

Edited by zfisherdrums
Link to comment
Share on other sites

Last line can be following (to view topic):

Send('{Enter}')

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

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

Sleep(500)

Send('{F6}')

Sleep(500)

Send('{PgDn}')

The point of world view

Link to comment
Share on other sites

  • 10 years later...

I am currently working on a script to find a string in a SysTreeView32 and click it, so zfisherdrum's code came in handy here.

Func _TreeViewSearch( $sWinTitle, $sWinText, $sControlID, $sSearchText, $sNode = "" ) ==> Why the ="" here for $sNode? Function is called with $sNode = "#0" at least.

1) Why the ="" here for $sNode? Function is called with $sNode = "#0" at least.

2) It seems that something is not working properly.

My treeview has got 9 entries in the root list, each of the entries has got at least one sub-entry and each of those can have a different number of sub-sub-entries, and so the indexing string to capture all of those items would look like this:  "#0|#0 |#0".

First of all, I could not get the  _GUICtrlTreeView_SelectItem( $hWnd, $hItem ) function to work. I am also stuck because I thought that the _GUI commands only work for controls that were built using autoit, instead of trying to work on an external application's treeview. For that one can only use autoit's internal commands.

For some reason the script above does not get the correct number of entries in the root list, i.e. it does not give me 9 children for root, but instead give back 3 children which are actually located below first root entry. So when using the script to find a search string it will only search through first root entry, its sub-entries and sub-sub-entries and then stop without success in case the search string was not found there.

How can I find the correct number of all (root-) entries straight away?

Thanks a lot,

MartyCologne.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...