FilipL Posted March 22, 2024 Posted March 22, 2024 I am trying to loop through a branch of a Treeview. When I use the ControlTreeView with the option GetItemCount, it returns 2, being there are 2 items, which is correct. What I can not figure out is how I can loop through these items and select them one by one. I am new to AutoIT so this question can be a low brainer, but do not get any further for the moment.
ioa747 Posted March 22, 2024 Posted March 22, 2024 example: https://www.autoitscript.com/forum/topic/153094-listing-treeview-control-items-gives-unexpected-results/#comment-1100832 I know that I know nothing
FilipL Posted March 22, 2024 Author Posted March 22, 2024 I saw these examples, but am I wrong that first the treeview is being build before using it. Here you have the handle to the tree, but I do seem to succeed to get the handle of the object found in the ControlTreeView. Some example MsgBox(0, "Nr. of items: ", ControlTreeView("Monitor","" ,"" ,"GetItemCount","#0|<Preferences>|interface")) This returns 2 items found. I have taken the code you pointed to, but I do not see the interfaces, which are named "interface" and "interface1". Here I am lost: local $str $TV010 = ControlGetHandle ("Monitor", "", "") 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)
Solution Zedna Posted March 22, 2024 Solution Posted March 22, 2024 (edited) Here is my function _TreeView_GetAll() which gets whole content of TreeView control, in this case even from external application: Here you can see how to simply traverse the whole TreeView ... #Include <String.au3> #Include <GuiTreeView.au3> $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 = '- ' $hWnd = ControlGetHandle($title, $text, $classNN) $sAll = '' 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 Edited March 22, 2024 by Zedna FilipL 1 Resources UDF ResourcesEx UDF AutoIt Forum Search
FilipL Posted March 22, 2024 Author Posted March 22, 2024 My problem lies in the correct setting of the _TreeView_GetAll (or ControlGetHandle) parameters. When Specifying 'Monitor' instead of 'OLE/COM Object viewer' then the routine works, but the content of the wrong SysTreeView322 is shown. The program I want to automate, which I only use, has multiple SysTreeView windows, each with the same ID. All are packed in a control, and these ones are different. By using keystrokes I am able to direct the ControlTreeView to the correct TreeView, but I do not know how to do this for the ControlGetHandle. When I use the second parameter, the result is empty. When I set the ID of the control above the treeview in the third parameter, the result is empty. No idea how this should work.
ioa747 Posted March 22, 2024 Posted March 22, 2024 now I understood that _TreeView is not yours but from another program let's open the auto it help file and try this #include <GuiTreeView.au3> $hWnd = WinActivate("AutoIt Help (v3.3.16.1)", "") $hTreeView = ControlGetHandle($hWnd, "", "SysTreeView321") ConsoleWrite("$hTreeView=" & $hTreeView & @CRLF) $sTViewPath = "AutoIt|Function Reference|Window Management|Controls" $iItemCnt = ControlTreeView ( $hWnd, "", $hTreeView, "GetItemCount" , $sTViewPath) ConsoleWrite("Item Count " & $iItemCnt & @CRLF) $hItemFound = _GUICtrlTreeView_FindItem($hTreeView, "ControlClick") ConsoleWrite("$hItemFound=" & $hItemFound & @CRLF) _GUICtrlTreeView_SelectItem($hTreeView, $hItemFound) Local $hItemOld = $hItemFound For $i = 1 To $iItemCnt -1 $hItemOld = _GUICtrlTreeView_GetNext($hTreeView, $hItemOld ) _GUICtrlTreeView_SelectItem($hTreeView, $hItemOld) Sleep(500) Next FilipL 1 I know that I know nothing
FilipL Posted March 22, 2024 Author Posted March 22, 2024 Found it, thank you. Each SysList32x view gets an x where the x indicated the one that is currently active. By first navigating to the correct window with keypresses and making this one active, i can address the SysList321 and now I have it. Super, thank you.
FilipL Posted March 22, 2024 Author Posted March 22, 2024 Thanks Zedna and ioa747. With understanding how the "SysTreeView321" is define, I can get further now. Thank you to enlighten me. ioa747 1
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