Sign in to follow this  
Followers 0
Zedna

_TreeView_GetAll() - get content from external TreeView

3 posts in this topic

Just very simple but universal/usefull function to get all content of TreeView from external application.

It's not optimized for speed and error testing is missing, it's just for very simple code ;-)

#Include <String.au3>
#Include <GuiTreeView.au3>

; "C:\Program Files (x86)\Resource Kit\oleview.exe"
; COM Library Objects --> ClassMoniker

$sAll = _TreeView_GetAll('OLE/COM Object Viewer', '', 'SysTreeView322')
FileDelete('treeview_get_all.txt')
FileWrite('treeview_get_all.txt', $sAll)
;~ClipPut($sAll)

Func _TreeView_GetAll($title, $text, $classNN, $expand = False, $indent = '  ', $bullet = '') ; $bullet = '- '
    $sAll = ''
    $hWnd = ControlGetHandle($title, $text, $classNN)
    If $expand Then _GUICtrlTreeView_Expand($hWnd) ; Expand All
    $hItem = _GUICtrlTreeView_GetFirstItem($hWnd)
    While $hItem <> 0x00000000
        $sItem = _GUICtrlTreeView_GetText($hWnd, $hItem)
        $level = _GUICtrlTreeView_Level($hWnd, $hItem)
        $sIndent = _StringRepeat($indent, $level)
        $sAll &= $sIndent & $bullet & $sItem & @CRLF
        $hItem = _GUICtrlTreeView_GetNext($hWnd, $hItem)
    WEnd
    Return $sAll
EndFunc

Hope it can help somebody ...

2 people like this

Share this post


Link to post
Share on other sites



Here is GUI interactive version:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <String.au3>
#Include <GuiTreeView.au3>

$Form1 = GUICreate("TreeView Get All", 574, 422, 260, 136)
$lbl_title = GUICtrlCreateLabel("Title:", 17, 15, 27, 17)
$ed_title = GUICtrlCreateInput("", 49, 13, 121, 21) ; OLE/COM Object Viewer
$lbl_text = GUICtrlCreateLabel("Text:", 189, 15, 27, 17)
$ed_text = GUICtrlCreateInput("", 219, 13, 121, 21)
$lbl_classnn = GUICtrlCreateLabel("ClassNN:", 367, 15, 47, 17)
$ed_classnn = GUICtrlCreateInput("SysTreeView321", 415, 13, 121, 21) ; SysTreeView322
$btn_get_all = GUICtrlCreateButton("TreeView Get All", 232, 48, 100, 25)
$ed_output = GUICtrlCreateEdit("", 16, 88, 537, 313)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $btn_get_all
            GUISetCursor(15,1,$Form1)
            $title = GUICtrlRead($ed_title)
            $text = GUICtrlRead($ed_text)
            $classnn = GUICtrlRead($ed_classnn)
            $sAll = _TreeView_GetAll($title, $text, $classnn, False, '    ')
            GUICtrlSetData($ed_output, $sAll)
            GUISetCursor(2,0,$Form1)
    EndSwitch
WEnd

Func _TreeView_GetAll($title, $text, $classNN, $expand = False, $indent = '  ', $bullet = '') ; $bullet = '- '
    $sAll = ''
    $hWnd = ControlGetHandle($title, $text, $classNN)
    If $expand Then _GUICtrlTreeView_Expand($hWnd) ; Expand All
    $hItem = _GUICtrlTreeView_GetFirstItem($hWnd)
    While $hItem <> 0x00000000
        $sItem = _GUICtrlTreeView_GetText($hWnd, $hItem)
        $level = _GUICtrlTreeView_Level($hWnd, $hItem)
        $sIndent = _StringRepeat($indent, $level)
        $sAll &= $sIndent & $bullet & $sItem & @CRLF
        $hItem = _GUICtrlTreeView_GetNext($hWnd, $hItem)
    WEnd
    Return $sAll
EndFunc

Share this post


Link to post
Share on other sites

Hi Zedna,

thank you for the code.

Did you ever try to add a custom event to an external treeview?
I am still looking for such a function.
(Maybe change OnClick event for an external treeview).
I tried GUISetOnEvent, but it seem that this only works with internal application.

:):P;)

 

 

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

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      hello guys
      how are you؟
      I hope to be fine.
      I have a question  please
      how do I get the menu item that was pressed without that contains a variable؟
      For example I have a menu  of Favorites and I want the script recognizes the existing path in the pressed item
      i'll repeat to tell the item does not contain a variable
      Is there any solution
      if you want to explain more I could write an example of what I want.
      Greetings to all,
      thanks in advance
    • nacerbaaziz
      By nacerbaaziz
      Hello my friends
      I have an urgent question, please help.
      How do I select all the text in the edit or input
      And how to get the currently selected text
      Please help urgently
      Greetings and thanks for all
    • corgano
      By corgano
      I can't explain easily what i want to do, so i made a picture:

      What i want to do is to specify a treeview item, and then be able to move it right to be a child of the previous item, or left to do the opposite (make a child into a sibling). I also want to move and child items of the target with it, like in the bottom half of the above image depicts. However I didn't see any functions in the help file to move items around. All i want is a button that when pressed, makes the selected item and any of selected item's children move one layer to the right / left. Does anyone know how?

      Edit: something along the lines of _GUICtrlTreeView_Level but SET level
    • Tjalve
      By Tjalve
      Hi everyone. Im creating a GUI for an application. Im usinga  treeview item and i want to add some information to the side of the treeview based on what cilditem you are pressing. For the moment i have a "get info" button that works. But that means that you have to select your child in the treeview, and then press a button to gte the info. I want the info to be visable as soon as you select it.
      With uther controls you can just add it to the loop but it doesnt seem to work with tyhe UDF version of the treeview control. Is there anything I can do?
      #include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> ;~ Create GUI dim $guilabel[7] local $currentlevel = 1 Local $hGui = GUICreate( "Grejs", 1000, 500, 600, 300, BitOR( $GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX ) ) Local $iBorderWidth = 4, $aPos = WinGetClientSize( $hGui ) $idTV = _GUICtrlTreeView_Create($hGui, $iBorderWidth, $iBorderWidth, $aPos[0]-2*$iBorderWidth-400, $aPos[1]-2*$iBorderWidth-30 ) $root_level = _GUICtrlTreeView_Add($idTV,0,"Root") $item1 = _GUICtrlTreeView_AddChild($idTV, $root_level, "child1") $item2 = _GUICtrlTreeView_AddChild($idTV, $root_level, "child2") $item3 = _GUICtrlTreeView_AddChild($idTV, $root_level, "child3") ;~ Start Gui GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $idTV MsgBox(0,"","") EndSwitch WEnd GUIDelete($hGui) Exit In this example, i want the msgbox to appear whenevr i select something in the treeview. It ios not my full code, but its an example of the problam i have. Help is much appritiated
      /G
    • xiantez
      By xiantez
      Hey AutoIT Community,
      Just wanted to know if there is a way I can #include all *.au3 files in my script without having to #include each individual .au3 file. For instance, currently I have a laundry list of #includes like this:
      #include <IE.au3>
      #include <Inet.au3>
      #include <AutoItConstants.au3>
      #include <GUIConstantsEx.au3>
      #include <GDIPlus.au3>
      #include <GuiMenu.au3> 
      [ECT...ECT...]
      Would there be a way I could include all of the files above or all  .au3 file in a one liner? That way I do not have to burn up a bunch of lines of code for just my includes.... Your help is greatly appreciated...