markloman Posted August 6, 2006 Share Posted August 6, 2006 While working on my antispyware expert tool, I stumbled upon some problems/things. Tree view items created with _GUICtrlTreeViewInsertItems() cannot be interfaced with like items created with GUICtrlCreateTreeViewItem().In the example below, using _GUICtrlTreeViewInsertItem(), RootItem3 will NOT be coloured. Also, the context menu is NOT working. expandcollapse popup#include <GUIConstants.au3> #include <GuiTreeView.au3> Opt("MustDeclareVars", 1) Dim $h_GUI, $Msg, $treeview Dim $h_root1, $h_root2, $h_root3 Dim $n_btn_insert Dim $menu, $menuitem Dim $RC $h_GUI = GUICreate("TreeView UDF Sample", 220, 250) $treeview = GUICtrlCreateTreeView(10, 10, 200, 200, -1, $WS_EX_CLIENTEDGE) GUICtrlSetImage(-1, "shell32.dll", 3, 4) GUICtrlSetImage(-1, "shell32.dll", 4, 2) $h_root1 = _GUICtrlTreeViewInsertItem($treeview, "RootItem1") _GUICtrlTreeViewInsertItem($treeview, "SubItem1", $h_root1) _GUICtrlTreeViewInsertItem($treeview, "SubItem2", $h_root1) $h_root2 = _GUICtrlTreeViewInsertItem($treeview, "RootItem2") $h_root3 = _GUICtrlTreeViewInsertItem($treeview, "RootItem3") _GUICtrlTreeViewInsertItem($treeview, "SubItem3", $h_root3) _GUICtrlTreeViewInsertItem($treeview, "SubItem4", $h_root3) $menu = GUICtrlCreateContextMenu ($h_root3) $menuitem = GUICtrlCreateMenuitem ("hello world", $menu) $n_btn_insert = GUICtrlCreateButton("Color RootItem3", 10, 220, 200, 20) GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE ExitLoop Case $n_btn_insert GUICtrlSetColor($h_root3, 0x0080ff) MsgBox(0, $RC, @error) EndSwitch WEnd ExitWhile, in almost the same example but populating the tree view with GUICtrlCreateTreeViewItem(), RootItem3 is coloured like it should. Also, the context menu works fine! expandcollapse popup#include <GUIConstants.au3> #include <GuiTreeView.au3> Opt("MustDeclareVars", 1) Dim $h_GUI, $Msg, $treeview Dim $h_root1, $h_root2, $h_root3 Dim $n_btn_insert Dim $menu, $menuitem Dim $RC $h_GUI = GUICreate("TreeView UDF Sample", 220, 250) $treeview = GUICtrlCreateTreeView(10, 10, 200, 200, -1, $WS_EX_CLIENTEDGE) GUICtrlSetImage(-1, "shell32.dll", 3, 4) GUICtrlSetImage(-1, "shell32.dll", 4, 2) $h_root1 = GUICtrlCreateTreeViewItem("RootItem1", $treeview) GUICtrlCreateTreeViewItem("SubItem1", $h_root1) GUICtrlCreateTreeViewItem("SubItem2", $h_root1) $h_root2 = GUICtrlCreateTreeViewItem("RootItem2", $treeview) $h_root3 = GUICtrlCreateTreeViewItem("RootItem3", $treeview) GUICtrlCreateTreeViewItem("SubItem3", $h_root3) GUICtrlCreateTreeViewItem("SubItem4", $h_root3) $menu = GUICtrlCreateContextMenu ($h_root3) $menuitem = GUICtrlCreateMenuitem ("hello world", $menu) $n_btn_insert = GUICtrlCreateButton("Color RootItem3", 10, 220, 200, 20) GUISetState() While 1 $Msg = GUIGetMsg() Switch $Msg Case $GUI_EVENT_CLOSE ExitLoop Case $n_btn_insert GUICtrlSetColor($h_root3, 0x0080ff) MsgBox(0, $RC, @error) EndSwitch WEnd ExitIn both examples, GUICtrlSetColor() returns the same value and @error.Maybe it's not important but _GUICtrlTreeViewInsertItem() creates handle values much higher than GUICtrlCreateTreeViewItem(). Looking at the examples above, $h_root1 gets control handle 4 from GUICtrlCreateTreeViewItem() while _GUICtrlTreeViewInsertItem() comes up with 1464024. I know it's just a number but since GUICtrlSetColor() and GUICtrlCreateContextMenu() interface with control handles, I thought I'd mention it.The reason why I report this, is that my own tree view, populated with items using GUICtrlCreateTreeViewItem(), behaves weird after a while (first time, it always works). But after deleting all items from the tree view with _GUICtrlTreeViewDeleteAllItems(), depending on sun radiationlevels, the tree view sometimes stays empty. It happens at random (80% of the time it works, sometimes it doesn't). I am not able to reproduce the problem in a small example, so I tried switching the code to _GUICtrlTreeViewInsertItem(). But looking at the problems above, that's not a solution either (for me). I must say that I use Holgers tristate stuff Link to comment Share on other sites More sharing options...
Holger Posted August 7, 2006 Share Posted August 7, 2006 (edited) This is by design. GUICtrlSetColor() and GUICtrlCreateContextMenu() work only with 'official' created controls/items! BTW: _GUICtrlTreeViewInsertItem() returns the handle to the treeview item. If you use the UDF: _GUICtrlTreeViewDeleteAllItems() then internal the items are NOT deleted - try to NOT mix these GUI-Autoit3- and UDF-functions! Edited August 7, 2006 by Holger Old project:GUI/Tray menu with icons and colors Other old stuff:IconFileScanner, TriState/ThreeState GUI TreeView, GUI ContextMenu created out of a TreeView Link to comment Share on other sites More sharing options...
markloman Posted August 7, 2006 Author Share Posted August 7, 2006 (edited) Thanks for the response Holger! I like your tristate tree view very much! As you can see I'm using my own state bitmap; don't tell anyone but I borrowed them from Windows Vista But after reading your reply, I've decided to ban the _GUICtrlTreeViewXXX functions (as much as possible) and almost immediately "designed" a proper solution to empty the tree view (dunno why I didn't thought of it in the first place):I've rerouted GUICtrlCreateTreeViewItem(), GUICtrlCreateContextMenu() and GUICtrlCreateMenuitem() to three custom functions which do the same, but store the control handles in an array. To erase the tree view, I've created a function which walks through the array and deletes the control handles, using GUICtrlDelete(). This way I'm sure all control handles are properly deleted. It works great. I'll check if the "random" glitch I mentioned earlier is also solved now (hope so).Update: Jup, the glitch seems to be fixed too now.BTW, is there a limit on the amount of items / control handles one can have in a tree view? Because I create a LOT of handles in my tree views; every item has its own context menu with 2 or 3 menu options. Edited August 7, 2006 by markloman Link to comment Share on other sites More sharing options...
GaryFrost Posted August 7, 2006 Share Posted August 7, 2006 from the Frequently Asked Questions15. What are the current technical limits of AutoIt v3?Here are details of the current technical limits of AutoIt. Please note that some of the limits are theoretical and you may run into performance or memory related problems before you reach the actual limit. Maximum length of a single script line: 4,095Maximum string length: 2,147,483,647 charactersNumber range (floating point): 1.7E308 to 1.7E+308 with 15-digit precisionNumber range (integers): 64-bit signed integerHexadecimal numbers: 32-bit signed integer (0x80000000 to 0x7FFFFFFF)Arrays: A maximum of 64 dimensions and/or a total of 16 million elementsMaximum depth of recursive function calls: 384 levelsSimultaneous open files: 64Simultaneous active HotKeys: 64Maximum number of variables in use at one time: No limit Maximum number of user defined functions: No limitMaximum number of GUI windows: 1024 Maximum number of GUI controls per window: 4096 SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference.  Link to comment Share on other sites More sharing options...
markloman Posted August 8, 2006 Author Share Posted August 8, 2006 (edited) 4096 seems a lot but is not much when working with tree views. In fact, it's so low that it's almost unusable for me. If one of the developers read this, please take it under consideration to increase the maximum amount of control handles. Thank you.Update: Perhaps it would be even better if AutoIt gets support for right click events (on tree views, etc.). That way we could create context menu and menu items dynamically - and we wouldn't loose the precious mineral called "control handles" to these functions.I use at least 11 control handles for just one file in the tree view. Additional objects under the same category take up 5 handles.To give you an insight on where the control handles go, look at what I have come up with to make things work as it does now. I dynamically keep a list (with control handles) so I know what item is clicked:First, I create the spyware name parent:$ParentItem = GUICtrlCreateTreeViewItem("Malware.SpyAxe", $treeview)$ContextMenu = GUICtrlCreateContextMenu($ParentItem)$ContextMenuItem = GUICtrlCreateMenuItem1("Delete", $ContextMenu)GUICtrlSetOnEvent($ContextMenuItem1, "_ThreatParentDelete")Second, I create the category item:$ParentItemCategory1 = GUICtrlCreateTreeViewItem("Files", $ParentItem)$ContextMenu = GUICtrlCreateContextMenu($ParentItemCategory1)$ContextMenuItem = GUICtrlCreateMenuItem("Delete", $ContextMenu)GUICtrlSetOnEvent($ContextMenuItem, "_ThreatParentDelete")Third, I create the threat object under the category:$ChildItem = GUICtrlCreateTreeViewItem("C:\Program Files\SpywareAxe\spywareaxe.exe", $ParentItemCategory1)$ContextMenu = GUICtrlCreateContextMenu($ChildItem)$ContextMenuItem1 = GUICtrlCreateMenuItem("Go to", $ContextMenu)$ContextMenuItem2 = GUICtrlCreateMenuItem("Delete", $ContextMenu)$ContextMenuItem3 = GUICtrlCreateMenuItem("Trust", $ContextMenu)GUICtrlSetOnEvent($ContextMenuItem1, "_ThreatChildGoto")GUICtrlSetOnEvent($ContextMenuItem2, "_ThreatChildDelete")GUICtrlSetOnEvent($ContextMenuItem3, "_ThreatChildTrust")And finally I have this list:|$ParentItem|$ContextMenu|$ContextMenuItem1||||$ParentItemCategory1|$ContextMenu|$ContextMenuItem1||||$ChildItem|$ContextMenu|$ContextMenuItem1|$ContextMenuItem2|$ContextMenuItem3|To determine what handle triggered the menu event I use macro @Ctrl_ID and then search through the list to retrieve the tree view item ($ParentItem(Category1) or $ChildItem).It works splendid this way but as you can see, to populate the list, I use at least 11 control handles for just one file. Additional files take up 5 handles. But perhaps someone has a more efficient solution? Edited August 8, 2006 by markloman Link to comment Share on other sites More sharing options...
markloman Posted August 8, 2006 Author Share Posted August 8, 2006 (edited) I just counted the amount of handles in my tree view and when your system is infected with ex. HotBar and some other crap, the tree view alone consumes 3592 control handles I must consider removing functionality from my program since the Quarantine function also contains items with context menu's (every item in the Quarantine consumes 4 handles).Please consider increasing the maximum amount of control handles. Edited August 8, 2006 by markloman Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted August 8, 2006 Moderators Share Posted August 8, 2006 I could have swore that someone made a work around for the 4096 limit... I want to say randallc did, but I'm just not sure!!! Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. 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