TheReveller Posted April 13, 2009 Share Posted April 13, 2009 Hi, Let's say there is a treeview build with folders and items. Now, I want to know how many total items there is, so I make a loop and I count only items who has no children. But an empty folder has no children, which means he will be count as an item... What can I do ? Also, how can I make a script which ask to click somewhere on a random treeview, then valids if the clicked area is a treeview and then runs the script to count the items in that treeview ? I mean, how can I get the info that AutoIt Window Info retrieves ? Thanks, TheReveller Link to comment Share on other sites More sharing options...
Mat Posted April 13, 2009 Share Posted April 13, 2009 Let's say there is a treeview build with folders and items. Now, I want to know how many total items there is, so I make a loop and I count only items who has no children. But an empty folder has no children, which means he will be count as an item... What can I do ? If it's for folders and files, then you can do something like this: $First = FileFindFirstFile ($Directory & "\*.*") If Not @Error Then $FileNumber = 1 do FileFindNextFile ($First) If Not @Error Then $FileNumber += 1 Until @Error MsgBox (48, "Result", "There are " & $FileNumber & " Files in this directory.") AutoIt Project Listing Link to comment Share on other sites More sharing options...
TheReveller Posted April 14, 2009 Author Share Posted April 14, 2009 Well, it's not real folders... It's only symbolic. Link to comment Share on other sites More sharing options...
TheReveller Posted April 14, 2009 Author Share Posted April 14, 2009 I was wondering how safe is "GetItemCount" because I made a script and with most treeviews it will work fine, but with some other treeviews I must do "Select" and "Expand" on every item because asking "GetItemCount" because it would return "0" and still, if I run the script on the treeview given by "Explore" option of "My Computer" for example, it will still sometimes return "0" so I have to put a sleep after each "Select" & "Expand" before asking "GetItemCount"... It's fast when I don't even have to "Select" & "Expand", then slower when I have to do "Select" & "Expand" and then even slower when I must put a sleep for every "Select" & "Expand"... Any solution ? Thanks, TheReveller My fast-made script for the moment : expandcollapse popup#include <Misc.au3> #include <WinAPI.au3> #include <Excel.au3> HotKeySet("{ESC}", "quit") $oExcel = ObjCreate("Excel.Application") Opt("WinTitleMatchMode", 2) If WinExists("[TITLE:TreeView; CLASS:XLMAIN]") Then WinClose("[TITLE:TreeView; CLASS:XLMAIN]") EndIf $oExcel.WorkBooks.Open(@ScriptDir & "\TreeView.xls", Default, 0, Default, "", "") $oExcel.Visible = 0 FileSetAttrib(@ScriptDir & "\TreeView.xls", "+H") Global $speed = 1, $an = 0, $bn = 0, $cn = 0, $dn = 0, $en = 0, $fn = 0, $gn = 0, $hn = 0, $in = 0, $jn = 0, $kn = 0 Func OnAutoItExit() $oExcel.ActiveWorkBook.Save $oExcel.Quit FileSetAttrib(@ScriptDir & "\TreeView.xls", "-H") EndFunc Func quit() Exit EndFunc Do $tPoint = _WinAPI_GetMousePos() $hWnd = _WinAPI_WindowFromPoint($tPoint) $hWndP = _WinAPI_GetParent($hWnd) $ClassName = _WinAPI_GetClassName($hWnd) ToolTip(ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetText", ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetSelected", 1)) & " : " & ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetSelected", 1)), Default, Default, Default, Default, 4) Until _IsPressed("20") ToolTip("", Default, Default, Default, Default, 4) For $a = 0 To ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "")-1 ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Select", "#"&$a) ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Expand", "#"&$a) $oExcel.Activesheet.Cells(1+$an+$bn+$cn+$dn+$en+$fn+$gn+$hn+$in+$jn+$kn, 1).Value = ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetText", "#"&$a) & " [" & ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a) & "]" $an += 1 Sleep($speed) If ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a) > 0 Then For $b = 0 To ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a)-1 ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Select", "#"&$a&"|#"&$b) ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Expand", "#"&$a&"|#"&$b) $oExcel.Activesheet.Cells(1+$an+$bn+$cn+$dn+$en+$fn+$gn+$hn+$in+$jn+$kn, 2).Value = ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetText", "#"&$a&"|#"&$b) & " [" & ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b) & "]" $bn += 1 Sleep($speed) If ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b) > 0 Then For $c = 0 To ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b )-1 ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Select", "#"&$a&"|#"&$b&"|#"&$c) ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Expand", "#"&$a&"|#"&$b&"|#"&$c) $oExcel.Activesheet.Cells(1+$an+$bn+$cn+$dn+$en+$fn+$gn+$hn+$in+$jn+$kn, 3).Value = ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetText", "#"&$a&"|#"&$b&"|#"&$c) & " [" & ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c) & "]" $cn += 1 Sleep($speed) If ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c) > 0 Then For $d = 0 To ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c)-1 ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Select", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d) ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Expand", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d) $oExcel.Activesheet.Cells(1+$an+$bn+$cn+$dn+$en+$fn+$gn+$hn+$in+$jn+$kn, 4).Value = ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetText", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d) & " [" & ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d) & "]" $dn += 1 Sleep($speed) If ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d) > 0 Then For $e = 0 To ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d)-1 ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Select", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e) ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Expand", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e) $oExcel.Activesheet.Cells(1+$an+$bn+$cn+$dn+$en+$fn+$gn+$hn+$in+$jn+$kn, 5).Value = ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetText", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e) & " [" & ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e) & "]" $en += 1 Sleep($speed) If ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e) > 0 Then For $f = 0 To ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e)-1 ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Select", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f) ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Expand", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f) $oExcel.Activesheet.Cells(1+$an+$bn+$cn+$dn+$en+$fn+$gn+$hn+$in+$jn+$kn, 6).Value = ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetText", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f) & " [" & ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f) & "]" $fn += 1 Sleep($speed) If ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f) > 0 Then For $g = 0 To ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f)-1 ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Select", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g) ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Expand", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g) $oExcel.Activesheet.Cells(1+$an+$bn+$cn+$dn+$en+$fn+$gn+$hn+$in+$jn+$kn, 7).Value = ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetText", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g) & " [" & ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g) & "]" $gn += 1 Sleep($speed) If ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g) > 0 Then For $h = 0 To ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g)-1 ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Select", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h) ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Expand", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h) $oExcel.Activesheet.Cells(1+$an+$bn+$cn+$dn+$en+$fn+$gn+$hn+$in+$jn+$kn, 8).Value = ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetText", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h) & " [" & ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h) & "]" $hn += 1 Sleep($speed) If ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h) > 0 Then For $i = 0 To ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h)-1 ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Select", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h&"|#"&$i) ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Expand", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h&"|#"&$i) $oExcel.Activesheet.Cells(1+$an+$bn+$cn+$dn+$en+$fn+$gn+$hn+$in+$jn+$kn, 9).Value = ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetText", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h&"|#"&$i) & " [" & ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h&"|#"&$i) & "]" $in += 1 Sleep($speed) If ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h&"|#"&$i) > 0 Then For $j = 0 To ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h&"|#"&$i)-1 ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Select", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h&"|#"&$i&"|#"&$j) ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Expand", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h&"|#"&$i&"|#"&$j) $oExcel.Activesheet.Cells(1+$an+$bn+$cn+$dn+$en+$fn+$gn+$hn+$in+$jn+$kn, 10).Value = ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetText", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h&"|#"&$i&"|#"&$j) & " [" & ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h&"|#"&$i&"|#"&$j) & "]" $jn += 1 Sleep($speed) If ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h&"|#"&$i&"|#"&$j) > 0 Then For $k = 0 To ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h&"|#"&$i&"|#"&$j)-1 ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Select", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h&"|#"&$i&"|#"&$j&"|#"&$k) $oExcel.Activesheet.Cells(1+$an+$bn+$cn+$dn+$en+$fn+$gn+$hn+$in+$jn+$kn, 11).Value = ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetText", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h&"|#"&$i&"|#"&$j&"|#"&$k) & " [" & ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "GetItemCount", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h&"|#"&$i&"|#"&$j&"|#"&$k) & "]" $kn += 1 Next ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Collapse", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h&"|#"&$i&"|#"&$j) Else EndIf Next ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Collapse", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h&"|#"&$i) Else EndIf Next ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Collapse", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g&"|#"&$h) Else EndIf Next ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Collapse", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f&"|#"&$g) Else EndIf Next ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Collapse", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e&"|#"&$f) Else EndIf Next ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Collapse", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d&"|#"&$e) Else EndIf Next ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Collapse", "#"&$a&"|#"&$b&"|#"&$c&"|#"&$d) Else EndIf Next ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Collapse", "#"&$a&"|#"&$b&"|#"&$c) Else EndIf Next ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Collapse", "#"&$a&"|#"&$b) Else EndIf Next ControlTreeView($hWndP, "", "[CLASS:"&$ClassName&"]", "Collapse", "#"&$a) Else EndIf Next Link to comment Share on other sites More sharing options...
TheReveller Posted April 15, 2009 Author Share Posted April 15, 2009 I have a problem with treeviews that has unknown childs... I mean, their child are retrieved from database only when we ask to open the parent, so even if I use GetCount UDF, it returns only "1". Any solutions ? Thanks, TheReveller Link to comment Share on other sites More sharing options...
TheReveller Posted April 19, 2009 Author Share Posted April 19, 2009 (edited) Is there a make number of items for a treeview ? Is that a maximum for any windows treeview ?I was wondering because I wanted to test the limits of a script a made and I wanted to test my script when there is more than 65536 end-items so I wanted to create a treeview this way :For $i = 0 To 255 $general[$i] = GUICtrlCreateTreeViewItem("General" & $i, $treeview) For $j = 0 To 255 $level[$i][$j] = GUICtrlCreateTreeViewItem("Other" & $j, $general[$i]) Next NextBut the treeview stopped at General254 with Other252, that means 254*256 + 255 + 253 = 65532 itemsThen I tried this :For $i = 0 To 4095 $general[$i] = GUICtrlCreateTreeViewItem("General" & $i, $treeview) For $j = 0 To 15 $level[$i][$j] = GUICtrlCreateTreeViewItem("Other" & $j, $general[$i]) Next NextAnd the treeview stopped at General3854 with Other12 which means 3854*16 + 3855 + 13 = 65532 items yet.Also, I wanted to know if that treeview limit is true for all Windows treeviews (SysTreeView32).Thanks,TheRevellerEdit : Well, I don't think the max is 65532 items for all treeviews, but maybe only for "known" treeviews. By "known", I mean that all subitems are already known by the treeview. That means that treeviews who get their subitems from a database will certainly be able to have more than 65536 total items... Right ?That's sick because I don't know how to make a huge treeview based on a database only to test if the script a made will still work correctly with more than 65536 items... Edited April 19, 2009 by TheReveller 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