kylomas Posted July 30, 2013 Share Posted July 30, 2013 I am trying to list items in a TreeView control using the following code. expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <WindowsConstants.au3> #include <array.au3> local $gui010 = guicreate('TreeView Test') local $aSZE = wingetclientsize($gui010) local $TV010 = guictrlcreatetreeview(0,0,$aSZE[0],$aSZE[1]-40) local $btn010 = guictrlcreatebutton('Generate Treeview Debug Data To Console',20,$aSZE[1]-30,$aSZE[0]-40) local $x,$y ; just for handle holders to create child elements local $total_entries = 0 _GUICtrlTreeView_BeginUpdate($TV010) ;For $1 = 1 To Random(1, 10, 1) For $1 = 1 To 5 $x = GUICtrlCreateTreeViewItem(StringFormat("[%02d] Level 1", $1),$TV010) $total_entries += 1 ;For $2 = 1 To Random(1, 10, 1) For $2 = 1 To 5 $y = GUICtrlCreateTreeViewItem(StringFormat("[%02d] Level 2", $2),$x) $total_entries += 1 ;for $3 = 1 to random(1, 10,1) for $3 = 1 to 5 GUICtrlCreateTreeViewItem(StringFormat("[%02d] Level 3", $3),$y) $total_entries += 1 next Next Next _GUICtrlTreeView_EndUpdate($TV010) ConsoleWrite('Generated = ' & $total_entries & ' entries' & @LF) guisetstate() while 1 switch guigetmsg() case $gui_event_close Exit case $btn010 _out() EndSwitch WEnd func _out() local $str ConsoleWrite('GETCOUNT = ' & _GUICtrlTreeView_GetCount($TV010) & @LF) for $1 = 0 to _GUICtrlTreeView_GetCount($TV010) $str &= stringformat( 'Text = %-15s Child Switch = %-5s CTLID = %03i Parent CTLID = %03i Parent Handle = %-8s Sibling Count = %03i Child Count = %03i', _ _GUICtrlTreeView_GetText($TV010, $1), _ _GUICtrlTreeView_GetChildren($TV010,$1), _ _GUICtrlTreeView_GetItemParam($tv010,$1), _ _GUICtrlTreeView_GetParentParam($TV010,$1), _ _GUICtrlTreeView_GetParentHandle($TV010,$1), _ _GUICtrlTreeView_GetSiblingCount($TV010,$1), _ _GUICtrlTreeView_GetChildCount($TV010,$1) ) & @lf next ConsoleWrite($str & @LF) endfunc When I action the button for console output I get Generated = 155 entries GETCOUNT = 155 Text = [01] Level 1 Child Switch = True CTLID = 005 Parent CTLID = 000 Parent Handle = 0x00000000 Sibling Count = 005 Child Count = 005 Text = Child Switch = False CTLID = 000 Parent CTLID = 000 Parent Handle = 0x00000000 Sibling Count = 005 Child Count = -01 Text = Child Switch = False CTLID = 000 Parent CTLID = 000 Parent Handle = 0x00000000 Sibling Count = 005 Child Count = -01 Text = Child Switch = False CTLID = 000 Parent CTLID = 000 Parent Handle = 0x00000000 Sibling Count = 005 Child Count = -01 Text = Child Switch = False CTLID = 000 Parent CTLID = 000 Parent Handle = 0x00000000 Sibling Count = 005 Child Count = -01 Text = [01] Level 1 Child Switch = True CTLID = 005 Parent CTLID = 000 Parent Handle = 0x00000000 Sibling Count = 005 Child Count = 005 Text = [01] Level 2 Child Switch = True CTLID = 006 Parent CTLID = 005 Parent Handle = 0x00ADA448 Sibling Count = 005 Child Count = 005 Text = [01] Level 3 Child Switch = False CTLID = 007 Parent CTLID = 006 Parent Handle = 0x00ADA490 Sibling Count = 005 Child Count = -01 Text = [02] Level 3 Child Switch = False CTLID = 008 Parent CTLID = 006 Parent Handle = 0x00ADA490 Sibling Count = 005 Child Count = -01 Text = [03] Level 3 Child Switch = False CTLID = 009 Parent CTLID = 006 Parent Handle = 0x00ADA490 Sibling Count = 005 Child Count = -01 Text = [04] Level 3 Child Switch = False CTLID = 010 Parent CTLID = 006 Parent Handle = 0x00ADA490 Sibling Count = 005 Child Count = -01 Text = [05] Level 3 Child Switch = False CTLID = 011 Parent CTLID = 006 Parent Handle = 0x00ADA490 Sibling Count = 005 Child Count = -01 Text = [02] Level 2 Child Switch = True CTLID = 012 Parent CTLID = 005 Parent Handle = 0x00ADA448 Sibling Count = 005 Child Count = 005 I don't understand why the first element is followed by 4 blank elements and then repeated. The treeview displays fine. Thanks, kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
spudw2k Posted July 30, 2013 Share Posted July 30, 2013 (edited) After much confusion I think it is quite simple. Your for statement starts at 0 when I think it should start at 1. I may be off-base here. Should've tested first. I was wrong. When i've done treeview exports before I've always used GetNext and such funcs to retrieve the handles. I notice in the help file funcs you are using call for Item ID or Handle, maybe the index ins't returning what you think it should. Edited July 30, 2013 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 Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool 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...
kylomas Posted July 30, 2013 Author Share Posted July 30, 2013 spudw2k, Yes, thanks, I've pretty much came to that conclusion also. I posted this question to see if it was something simple/stupid that I was missing (never used TreeView control before). I started goofing around with this in response to a thread in GH&S. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Solution spudw2k Posted July 30, 2013 Solution Share Posted July 30, 2013 (edited) Well I'm no expert so there may in fact be a simple way to do it. I was about to test your script by creating an array to hold the control id's returned from GUICtrlCreateTreeViewItem and see how it correlates to a straight index value (1-155). Will post the findings. edit: The Controls IDs are consecutive, but they start at 5 instead of 0 (or 1). expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <WindowsConstants.au3> #include <array.au3> local $gui010 = guicreate('TreeView Test') local $aSZE = wingetclientsize($gui010) local $TV010 = guictrlcreatetreeview(0,0,$aSZE[0],$aSZE[1]-40) local $btn010 = guictrlcreatebutton('Generate Treeview Debug Data To Console',20,$aSZE[1]-30,$aSZE[0]-40) local $x,$y ; just for handle holders to create child elements local $total_entries = 0 Local $arrIDs[155][2] $IDindx = 1 _GUICtrlTreeView_BeginUpdate($TV010) ;For $1 = 1 To Random(1, 10, 1) For $1 = 1 To 5 $arrIDs[$IDindx-1][0] = $IDindx $x = GUICtrlCreateTreeViewItem(StringFormat("[%02d] Level 1", $1),$TV010) $arrIDs[$IDindx-1][1] = $x $IDindx += 1 $total_entries += 1 ;For $2 = 1 To Random(1, 10, 1) For $2 = 1 To 5 $arrIDs[$IDindx-1][0] = $IDindx $y = GUICtrlCreateTreeViewItem(StringFormat("[%02d] Level 2", $2),$x) $arrIDs[$IDindx-1][1] = $y $IDindx += 1 $total_entries += 1 ;for $3 = 1 to random(1, 10,1) for $3 = 1 to 5 $arrIDs[$IDindx-1][0] = $IDindx $arrIDs[$IDindx-1][1] = GUICtrlCreateTreeViewItem(StringFormat("[%02d] Level 3", $3),$y) $IDindx += 1 $total_entries += 1 next Next Next _GUICtrlTreeView_EndUpdate($TV010) ConsoleWrite('Generated = ' & $total_entries & ' entries' & @LF) guisetstate() while 1 switch guigetmsg() case $gui_event_close Exit case $btn010 _out() _ArrayDisplay($arrIDs) EndSwitch WEnd func _out() local $str ConsoleWrite('GETCOUNT = ' & _GUICtrlTreeView_GetCount($TV010) & @LF) for $1 = 0 to _GUICtrlTreeView_GetCount($TV010) $str &= stringformat( 'Text = %-15s Child Switch = %-5s CTLID = %03i Parent CTLID = %03i Parent Handle = %-8s Sibling Count = %03i Child Count = %03i', _ _GUICtrlTreeView_GetText($TV010, $1), _ _GUICtrlTreeView_GetChildren($TV010,$1), _ _GUICtrlTreeView_GetItemParam($tv010,$1), _ _GUICtrlTreeView_GetParentParam($TV010,$1), _ _GUICtrlTreeView_GetParentHandle($TV010,$1), _ _GUICtrlTreeView_GetSiblingCount($TV010,$1), _ _GUICtrlTreeView_GetChildCount($TV010,$1) ) & @lf next ConsoleWrite($str & @LF) endfunc Edited July 30, 2013 by spudw2k ioa747 and kylomas 2 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 Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool 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...
kylomas Posted July 30, 2013 Author Share Posted July 30, 2013 (edited) spudw2k, Thanks, Doh! I knew it was something simple I was overlooking. kylomas edit: Jeez, what makes it worse is that the data was SCREAMING this at me... Edited July 30, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
kylomas Posted July 30, 2013 Author Share Posted July 30, 2013 (edited) spudw2k, On second thought, that may not be the entire answer. How do you explain the first entry appearing to be valid followed by 4 blanks and then repeated? edit: Been trying to configure a 3D array to hold the ctlid's w/o success. I don't really want to get into 3 2D linked lists to represent parent/child/sibling ctlid relationships. Perhaps the TreeView UDF's make this a moot point. kylomas Edited July 30, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
spudw2k Posted July 30, 2013 Share Posted July 30, 2013 (edited) Yea, I can't explain why 1 0 returns the first treeviewitem when the actual ID is 5. Perhaps there is something intrinsic about 1 0 being the first "element" in the treeview, but it makes sense why 2 1 - 4 would be invalid. I'd recommend taking the GetNext / NextChild / NextSibling approach rather than maintaining an array or list of the items. edit: strikethoughs Edited July 30, 2013 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 Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool 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...
kylomas Posted July 30, 2013 Author Share Posted July 30, 2013 I'd recommend taking the GetNext / NextChild / NextSibling approach rather than maintaining an array or list of the items. Yes, thanks for your time. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
kylomas Posted July 31, 2013 Author Share Posted July 31, 2013 F.W.I.W. This is how I got it to work. expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <WindowsConstants.au3> #include <array.au3> local $gui010 = guicreate('TreeView Test') local $aSZE = wingetclientsize($gui010) local $TV010 = guictrlcreatetreeview(0,0,$aSZE[0],$aSZE[1]-40) local $btn010 = guictrlcreatebutton('Generate Treeview Debug Data To Console',20,$aSZE[1]-30,$aSZE[0]-40) local $x, $y local $total_entries = 0 _GUICtrlTreeView_BeginUpdate($TV010) For $1 = 0 To random(0,10,1) $x = GUICtrlCreateTreeViewItem(StringFormat("[%02d] Level 1", $1),$TV010) $total_entries += 1 For $2 = 0 To random(0,10,1) $y = GUICtrlCreateTreeViewItem(StringFormat("[%02d] Level 2", $2),$x) $total_entries += 1 for $3 = 0 to random(0,10,1) GUICtrlCreateTreeViewItem(StringFormat("[%02d] Level 3", $3),$y) $total_entries += 1 next Next Next _GUICtrlTreeView_EndUpdate($TV010) ConsoleWrite('Generated = ' & $total_entries & ' entries' & @LF) guisetstate() while 1 switch guigetmsg() case $gui_event_close Exit case $btn010 _out() EndSwitch WEnd func _out() local $str ConsoleWrite('GETCOUNT = ' & _GUICtrlTreeView_GetCount($TV010) & @LF) for $1 = _GUICtrlTreeView_GetItemParam($tv010) to _GUICtrlTreeView_GetCount($TV010) ; <--- changed start count for iteration $str &= stringformat( 'Text = %-15s Child Switch = %-5s CTLID = %03i Parent CTLID = %03i Parent Handle = %-8s Sibling Count = %03i Child Count = %03i', _ _GUICtrlTreeView_GetText($TV010, $1), _ _GUICtrlTreeView_GetChildren($TV010,$1), _ _GUICtrlTreeView_GetItemParam($tv010,$1), _ _GUICtrlTreeView_GetParentParam($TV010,$1), _ _GUICtrlTreeView_GetParentHandle($TV010,$1), _ _GUICtrlTreeView_GetSiblingCount($TV010,$1), _ _GUICtrlTreeView_GetChildCount($TV010,$1) ) & @lf next ConsoleWrite($str & @LF) endfunc Big thanks to spud2wk for pointing out the obvious! kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
spudw2k Posted July 31, 2013 Share Posted July 31, 2013 (edited) Looking pretty good, except your output is still short by the offset of the first item ID...at least in my testing. I copied the output to notepad and counted the lines...4 items less than item count. So close. edit: Give this a go expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <WindowsConstants.au3> #include <array.au3> local $gui010 = guicreate('TreeView Test') local $aSZE = wingetclientsize($gui010) local $TV010 = guictrlcreatetreeview(0,0,$aSZE[0],$aSZE[1]-40) local $btn010 = guictrlcreatebutton('Generate Treeview Debug Data To Console',20,$aSZE[1]-30,$aSZE[0]-40) local $x, $y _GUICtrlTreeView_BeginUpdate($TV010) For $1 = 0 To random(0,10,1) $x = GUICtrlCreateTreeViewItem(StringFormat("[%02d] Level 1", $1),$TV010) For $2 = 0 To random(0,10,1) $y = GUICtrlCreateTreeViewItem(StringFormat("[%02d] Level 2", $2),$x) for $3 = 0 to random(0,10,1) GUICtrlCreateTreeViewItem(StringFormat("[%02d] Level 3", $3),$y) next Next Next _GUICtrlTreeView_EndUpdate($TV010) ConsoleWrite('Generated = ' & _GUICtrlTreeView_GetCount($TV010) & ' entries' & @LF) guisetstate() while 1 switch guigetmsg() case $gui_event_close Exit case $btn010 _out() EndSwitch WEnd func _out() local $str ConsoleWrite('GETCOUNT = ' & _GUICtrlTreeView_GetCount($TV010) & @LF) $id = _GUICtrlTreeView_GetItemParam($tv010) for $1 = 1 to _GUICtrlTreeView_GetCount($TV010) $str &= stringformat( 'Text = %-15s Child Switch = %-5s CTLID = %03i Parent CTLID = %03i Parent Handle = %-8s Sibling Count = %03i Child Count = %03i', _ _GUICtrlTreeView_GetText($TV010, $id), _ _GUICtrlTreeView_GetChildren($TV010,$id), _ _GUICtrlTreeView_GetItemParam($tv010,$id), _ _GUICtrlTreeView_GetParentParam($TV010,$id), _ _GUICtrlTreeView_GetParentHandle($TV010,$id), _ _GUICtrlTreeView_GetSiblingCount($TV010,$id), _ _GUICtrlTreeView_GetChildCount($TV010,$id) ) & @lf $id = _GUICtrlTreeView_GetNext($TV010,$id) next ConsoleWrite($str & @LF) endfunc Sorry I didn't think of it sooner; I forgot about _GUICtrlTreeView_GetItemParam Edited July 31, 2013 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 Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool 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...
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