tarretarretarre Posted October 14, 2014 Share Posted October 14, 2014 (edited) Hi, i have searched but couldnt find any similar answer, as the title says: i cant figure out the fundamentals of converting a treeview hwnd with unkown children to an structure of any sort i've looked at _GUICtrlTreeView_IsParent _GUICtrlTreeView_ChildCount, but i cant put the pieces together, could need some help with this one From: #1parent #1parent Child #1parent Child #1parent Child Child To: <parent> <child></child> <child></child> <child> <childOfChild></childOfChild> </child> </parent> I would like to get pointed at the right direction Edited October 14, 2014 by tarretarretarre Socket-IO - An event-driven TCP UDF (Realtime chat example) AutoIt-API-WS - An expressive HTTP server you can use to build your own API with (Screenshots) Link to comment Share on other sites More sharing options...
spudw2k Posted October 14, 2014 Share Posted October 14, 2014 (edited) This might point you in the right direction: Essentially, the logic is Get TreeView Item Count For 1 to ItemCount Get Item Info Get Next Item Next I'm not too sure how you want to handle the output formatting. For example...An item that is four levels deep...would you call that <childOfChildOfChild>? Perhaps your tree only goes three levels deep and it's not an issue. Either way, you can figure out how you want to format it. Edited October 14, 2014 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
LarsJ Posted October 14, 2014 Share Posted October 14, 2014 tarretarretarre, Here here here is all what you need need need.The key point is that the structure of a treeview is uniquely defined by the levels of the items. When you have figured that out, the rest is easy.This code creates a more or less random treeview, and writes the structure to a disk file, TreeView.txt.expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> #include <Array.au3> #include <File.au3> Global $hTV Example() Func Example() ; Create GUI Local $hGui = GUICreate( "Save TreeView to file", 400, 350, 600, 300, $GUI_SS_DEFAULT_GUI ) ; Create TreeView Local $idTV = GUICtrlCreateTreeView( 4, 4, 392, 292, $GUI_SS_DEFAULT_TREEVIEW, $WS_EX_CLIENTEDGE ) $hTV = GUICtrlGetHandle( $idTV ) ; Add items Local $hItem0 = _GUICtrlTreeView_Add( $hTV, 0, 0 ) _GUICtrlTreeView_AddChild( $hTV, $hItem0, 1 ) _GUICtrlTreeView_AddChild( $hTV, $hItem0, "This" ) Local $hItem3 = _GUICtrlTreeView_AddChild( $hTV, $hItem0, "is" ) _GUICtrlTreeView_AddChild( $hTV, $hItem3, 4 ) _GUICtrlTreeView_AddChild( $hTV, $hItem3, "a" ) _GUICtrlTreeView_AddChild( $hTV, $hItem3, "very" ) Local $hItem7 = _GUICtrlTreeView_AddChild( $hTV, $hItem3, "nice" ) _GUICtrlTreeView_AddChild( $hTV, $hItem7, 8 ) _GUICtrlTreeView_AddChild( $hTV, $hItem7, "TreeView" ) Local $hItem10 = _GUICtrlTreeView_Add( $hTV, $hItem0, ", (comma)" ) _GUICtrlTreeView_AddChild( $hTV, $hItem10, 11 ) _GUICtrlTreeView_AddChild( $hTV, $hItem10, "indeed." ) _GUICtrlTreeView_Add( $hTV, $hItem0, 13 ) ; Expand TreeView _GUICtrlTreeView_Expand( $hTV, $hItem0 ) _GUICtrlTreeView_Expand( $hTV, $hItem10 ) ; Create button Local $idButSave = GUICtrlCreateButton( "Save", 160, 310, 80, 30 ) ; Show GUI GUISetState( @SW_SHOW, $hGui ) ; Message loop While 1 Local $iMsg = GUIGetMsg() If $iMsg = 0 Or $iMsg = $GUI_EVENT_MOUSEMOVE Then ContinueLoop Switch $iMsg Case $idButSave SaveTreeView() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete( $hGui ) Exit EndFunc Func SaveTreeView() Local $aLines[100][2], $iLines = 0 Local $hItem = _GUICtrlTreeView_GetFirstItem( $hTV ) ; Get structure and information While $hItem $aLines[$iLines][0] = _GUICtrlTreeView_Level( $hTV, $hItem ) ; The level decides the structure $aLines[$iLines][1] = _GUICtrlTreeView_GetText( $hTV, $hItem ) ; The text is the information $hItem = _GUICtrlTreeView_GetNext( $hTV, $hItem ) $iLines += 1 WEnd ReDim $aLines[$iLines][2] _ArrayDisplay( $aLines ) ; Save structure and information _FileWriteFromArray( "TreeView.txt", $aLines ) EndFuncThis code reads TreeView.txt, and recreates the treeview from the structure.expandcollapse popup#include <GUIConstants.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> #include <Array.au3> #include <File.au3> Global $hTV Example() Func Example() ; Create GUI Local $hGui = GUICreate( "Create TreeView from file", 400, 350, 600, 300, $GUI_SS_DEFAULT_GUI ) ; Create TreeView Local $idTV = GUICtrlCreateTreeView( 4, 4, 392, 292, $GUI_SS_DEFAULT_TREEVIEW, $WS_EX_CLIENTEDGE ) $hTV = GUICtrlGetHandle( $idTV ) ; Create button Local $idButCreate = GUICtrlCreateButton( "Create", 160, 310, 80, 30 ) ; Show GUI GUISetState( @SW_SHOW, $hGui ) ; Message loop While 1 Local $iMsg = GUIGetMsg() If $iMsg = 0 Or $iMsg = $GUI_EVENT_MOUSEMOVE Then ContinueLoop Switch $iMsg Case $idButCreate CreateTreeView() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch WEnd GUIDelete( $hGui ) Exit EndFunc Func CreateTreeView() ; Delete TreeView _GUICtrlTreeView_DeleteAll( $hTV ) ; Read structure and information Local $aLines, $iLines _FileReadToArray( "TreeView.txt", $aLines, 0 ) $iLines = UBound( $aLines ) _ArrayDisplay( $aLines ) ; Create TreeView structure and information Local $aLine, $aLevels[100], $iLevel, $iLevelPrev = 0, $hItem ; Add root $aLine = StringSplit( $aLines[0], "|", 2 ) $hItem = _GUICtrlTreeView_Add( $hTV, 0, $aLine[1] ) $aLevels[0] = $hItem ; $aLevels[$iLevel] contains the last item of that level For $i = 1 To $iLines - 1 $aLine = StringSplit( $aLines[$i], "|", 2 ) $iLevel = $aLine[0] If $iLevel <> $iLevelPrev Then If $iLevel > $iLevelPrev Then ; A child of the previous level $hItem = _GUICtrlTreeView_AddChild( $hTV, $aLevels[$iLevelPrev], $aLine[1] ) Else ; $iLevel < $iLevelPrev ; A sibling of the level $hItem = _GUICtrlTreeView_Add( $hTV, $aLevels[$iLevel], $aLine[1] ) EndIf $aLevels[$iLevel] = $hItem ; $aLevels[$iLevel] contains the last item of that level $iLevelPrev = $iLevel Else ; $iLevel = $iLevelPrev ; A sibling of the level $hItem = _GUICtrlTreeView_Add( $hTV, $aLevels[$iLevel], $aLine[1] ) $aLevels[$iLevel] = $hItem ; $aLevels[$iLevel] contains the last item of that level EndIf Next _GUICtrlTreeView_Expand( $hTV ) EndFunc BigDaddyO 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
tarretarretarre Posted October 14, 2014 Author Share Posted October 14, 2014 Thanks for both of your answers guys, helped alot /T Socket-IO - An event-driven TCP UDF (Realtime chat example) AutoIt-API-WS - An expressive HTTP server you can use to build your own API with (Screenshots) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now