WildByDesign Posted March 20 Posted March 20 You're welcome. It was all worth it in the end. This UDF is fully featured now and I have no more ideas. I was able to just drop it into my project and everything just worked perfectly. The UDF is a very high level of quality and stability that should help people who need it. And so many of the functions would be great for people to learn from. Kanashius 1
Kanashius Posted March 20 Author Posted March 20 (edited) Well, nearly fully featured, I found something I thought should be there and added that with v2.10.0: - A possibility to add a filter for the files/folders (e.g. in the example I filter the ListView for folders or .au3 files) - I added the possibility to enable/disable the navigation through the ListView with a doubleclick, if someone wants to use it only to show one folder But I left the $bShowFiles/$bShowFolders untouched, because if you only want to differentiate between them and not more details, that is faster then using the filter callback (less calls and testing/splitting strings for extensions,...). Edited March 20 by Kanashius WildByDesign 1 My Website: Kanashius Webside (Some of my Programs you can find there)
WildByDesign Posted March 20 Posted March 20 The filter callback is really quite nice. I put it through some good testing and found no issues. I tested it in treeview as well. I can see a lot of possibilities with it. Kanashius 1
WildByDesign Posted March 21 Posted March 21 In my current project, I only use TreeView and I am able to get all the needed details from _selectCallback. My __TreeListExplorer_CreateSystem and __TreeListExplorer_AddView look like this at the moment: ; Create TLE system for the right side Global $hTLESystemRight = __TreeListExplorer_CreateSystem($hGUI_1, "", "_currentFolder", "_selectCallback") If @error Then ConsoleWrite("__TreeListExplorer_CreateSystem failed: "&@error&":"&@extended&@crlf) ; Add Views to TLE system: ShowFolders=True, ShowFiles=True __TreeListExplorer_AddView($hTLESystemRight, $hTreeViewRight, True, True, "_clickCallback", "_doubleClickCallback", "_loadingCallback") If @error Then ConsoleWrite("__TreeListExplorer_AddView $hTreeView failed: "&@error&":"&@extended&@crlf) Considering that I get all of the details from _selectCallback, how can I disable all of those other calls (except _selectCallback) to make things as efficient as possible?
Kanashius Posted March 21 Author Posted March 21 (edited) If you look into the UDF: expandcollapse popup; #FUNCTION# ==================================================================================================================== ; Name ..........: __TreeListExplorer_CreateSystem ; Description ...: Create a new TLE System. This is used to manage the views by settings the root folder, the current folder,... ; Multiple views (TreeView/ListView) can be added, all managed by this system. ; Syntax ........: __TreeListExplorer_CreateSystem($hGui[, $sRootFolder = ""[, $sCallbackFolder = Default[, $sCallbackSelect = Default ; [, $iMaxDepth = Default[, $iLineNumber = @ScriptLineNumber]]]]]) ; Parameters ....: $hGui - the window handle for all views used by this system. ; $sRootFolder - [optional] the root folder as string. Default is "", making the drive overview the root ; $sCallbackFolder - [optional] callback function as string. Using Default will not call any function. ; $sCallbackSelect - [optional] callback function as string. Using Default will not call any function. ; $iMaxDepth - [optional] the max depth, to which TreeViews are limited. Default = No limit. ; $iLineNumber - [optional] linenumber of the function call. Default is @ScriptLineNumber. ; (Automatic, no need to change; only used for error messages) ; Return values .: The system handle $hSystem, used by the other functions ; Author ........: Kanashius ; Modified ......: ; Remarks .......: When $sRootFolder = "", there is no root directory, enabling all drives to be accessed. Otherwise the User can ; only select child folders of the root folder. ; The $sCallbackFolder calls the provided function, which must have 4 parameters ($hSystem, $sRoot, $sFolder, $sSelected) and ; is called, when the root folder or the current folder changes. If the parameter number is wrong an error ; message will be written to the console at runtime (using $iLineNumber to find it better). ; $sCallbackSelect must be a function with 4 parameters ($hSystem, $sRoot, $sFolder, $sSelected) ; and is called, when an item in the Tree-/ListView is selected (Mouse/Keyboard) ; If $iMaxDepth is set, it is not possible to go deeper then that depth (Example: Drive selection with $sRoot="" and $iMaxDepth=0). ; ListViews are not limited by $iMaxDepth. ; ; Errors: ; 1 - Parameter is invalid (@extended 1 - $hGui, 3 - $sCallbackFolder, 4 - $sCallbackSelect, 5 - $iLineNumber) ; 2 - Setting WinProc for $hGui failed ; 3 - TLE system could not be added to map ; 4 - TLE system ID could not be converted to TLE system handle ; 5 - $sRootFolder is invalid and could not be set (try __TreeListExplorer_SetRoot for details) ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func __TreeListExplorer_CreateSystem($hGui, $sRootFolder = "", $sCallbackFolder = Default, $sCallbackSelect = Default, $iMaxDepth = Default, $iLineNumber = @ScriptLineNumber) Then you can see, that a lot of parameters are optional. So you can just not define them. If no parameter is defined, the one written in the Function definition is used. So: $sCallbackFolder = Default means, that the parameter is optional, so if it is not defined when the function is called, it is "Default". In the UDF description you can read, that Default means, nothing will be called ($sCallbackFolder - [optional] callback function as string. Using Default will not call any function.). The only problem is, if there are multiple optional parameters, but you only want one of them. If it is not the first, you have to provide values for the parameters before that. Some programming languages (for example python) let you name optional parameters like _CoolFunction(optionalParameter10="Something"), but that is not the case in AutoIt. In AutoIt you have to look at the documentation of the function to find out, what the value is, when you do not define it and use that. So a call would look like: ; Create TLE system for the right side Global $hTLESystemRight = __TreeListExplorer_CreateSystem($hGUI_1, "", Default, "_selectCallback") If @error Then ConsoleWrite("__TreeListExplorer_CreateSystem failed: "&@error&":"&@extended&@crlf) ; Add Views to TLE system: ShowFolders=True, ShowFiles=True __TreeListExplorer_AddView($hTLESystemRight, $hTreeViewRight, True, True) If @error Then ConsoleWrite("__TreeListExplorer_AddView $hTreeView failed: "&@error&":"&@extended&@crlf) Edited March 21 by Kanashius WildByDesign 1 My Website: Kanashius Webside (Some of my Programs you can find there)
WildByDesign Posted March 21 Posted March 21 5 hours ago, Kanashius said: In AutoIt you have to look at the documentation of the function to find out, what the value is, when you do not define it and use that. So a call would look like: Thank you, I appreciate it. The explanation helped me to understand it all better as well. You are right, some functions and some UDFs have different ways to do this. So I wasn't sure. I followed your suggestion and everything is working well.
getit Posted October 24 Posted October 24 (edited) Thank you, @Kanashius. That looks really great. I haven't tested it yet extensively, but the supplied example refuses to run. TreeListExplorer.au3 v2.10.0 misses an #include <WinAPIConstants.au3> statement. Otherwise it throws an error "Variable used without being declared." for $WH_KEYBOARD_LL in line 145. $__TreeListExplorer__Data.hKeyPrevHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($__TreeListExplorer__Data.hKeyProc), _WinAPI_GetModuleHandle(0), 0) Thanks again. Now I need some use case for your UDF. 🤠 Edited October 24 by getit
Kanashius Posted October 24 Author Posted October 24 Hey, thanks for the hint, @getit. It is actually because of a change in the AutoIt-Version (v3.3.18.0), causing it to break. I added the include to the UDF so it works with the new AutoIt-Version as well. Glad you like the UDF and hopefully it will be helpful one day My Website: Kanashius Webside (Some of my Programs you can find there)
WildByDesign Posted November 24 Posted November 24 @Kanashius There has been some discussion recently in the thread Bug in map ( and how to avoid it ) about a potential problem in AutoIt's Maps. I don't fully understand it all but I figured I should let you know since your current UDF uses Maps quite extensively. Do you know if your UDF is done in a way that would avoid this bug?
Kanashius Posted November 24 Author Posted November 24 (edited) Hi, yes, I saw that and it may impact this UDF. But to the best of my knowledge, the probability should be rather slim. The Integer/String mixup is not happening, because I am using one data type per map (as key) and the hashes are not simple/short numbers, but larger/more complex (CtrlIDs/Strings/...) The more concerning part would be the sharing of memory between multiple maps, because I use the same Map keys rather often... but I did not see any problems until now, so it is probably not affected. Overall, I do not really see a way for me to address this without a complete rewrite with DllStructs or something (I used maps instead, because it is easier and similarily fast and provides a better coding experience then using array indices, e.g. numbers instead of telling names) and it is a bug that should be addressed at the autoit level and probably will be (or already is for future versions, according to the bug tracker)... So unless some specific problem pops up, I would leave it as it is and wait for the fix in the language (which needs to be done anyway). Its not a specific edge case only affecting this UDF. Edited November 24 by Kanashius WildByDesign 1 My Website: Kanashius Webside (Some of my Programs you can find there)
WildByDesign Posted November 24 Posted November 24 Thank you for following up. I am likely going to start another project with your UDF, so I figured that I should mention the discussion about the map bug. For what it’s worth, my previous large project that uses your UDF has not experienced any problems at all. And you are right, it makes sense to wait until a fix in AutoIt. Kanashius 1
WildByDesign Posted December 13 Posted December 13 I would like to allow multiple selections in the ListView which I've already enabled in the control. However, the UDF only allows one item to be selected at a time. I was able to allow multiple selections in the UDF by uncommenting the following line: ;_GUICtrlListView_SetItemSelected($hView, $arSel[$j], False) Will this cause any negative consequences? I understand that the callback functions will not pick up on the multiple selections. However, I can still get the callbacks to trigger my own function to give me a list of all selected items which is enough for me.
Kanashius Posted December 13 Author Posted December 13 Hey, yes that will have negativ consequences. You are essentially disabling the deselection. The point to address this would be the __TreeListExplorer__WinProc function at the end: If $iCode=$NM_CLICK Or $bKeyPressed Then If $iIndex<>-1 And Not ($iIndex=0 And _GUICtrlListView_GetItemText($hView, $iIndex, 0)="..") Then Local $arPath = __TreeListExplorer__GetPathAndLast(__TreeListExplorer__GetCurrentPath($iSystem) & _GUICtrlListView_GetItemText($hView, $iIndex, 0)) __TreeListExplorer__OpenPath($iSystem, $arPath[0], $arPath[1]) If $iCode=$NM_CLICK Then __TreeListExplorer__HandleViewCallback($hView, "sCallbackClick", $iIndex) EndIf EndIf The __TreeListExplorer__OpenPath call here sets the select, triggering the custom selection in the update function (you changed). When calling __TreeListExplorer__OpenPath with the $sSelect parameter, it is wanted behaviour to select one item and deselect everything else. Now it depends on how you select multiple files. This should be handled in the __TreeListExplorer__WinProc function. Clicking while holding shift already selects multiple files. With STRG, it does not work currently and would have to be implemented as well as for any other key combinations. Maybe you would like to think about the different key combinations and I will take a look at how to best implement that (probably with some keyboard hooks or _IsPressed to check, which keys are pressed). So the solution would be to not call __TreeListExplorer__OpenPath when selecting multiple files in __TreeListExplorer__WinProc. (Also applies to $LVN_KEYDOWN, if multi-file selection sould be supported with keystrokes as well.) Another thing to think about: Should that also apply to the TreeView? Should multiple selections be syncted between the List/Treeview (if they even show the same files/folders/...) So it looks like thats a bit more complicated and something for me to think about a little bit more to implement a good solution into the UDF. Not sure, when I will have the time for that currently. My Website: Kanashius Webside (Some of my Programs you can find there)
pixelsearch Posted December 13 Posted December 13 @Kanashius Great job with this UDF ! Could you please confirm what follows, using your 2 scripts downloadable from 1st post, which are : * TreeListExplorer.au3 updated version 2.10.2, which solves the bug of icons id's found in $iParam in function GUICtrlListView_AddItem, thx @ioa747 * TreeListExplorer-Example.au3 1) Add 3 lines to the example (main loop) which are : Local $iMsg = GUIGetMsg() ; line already exists If $iMsg <> 0 And $iMsg <> -11 Then ; $GUI_EVENT_NONE = 0 , $GUI_EVENT_MOUSEMOVE = -11 (both happen very often) ConsoleWrite("$iMsg = " & $iMsg & @crlf) EndIf Switch $iMsg ; line already exists 2) Run the example and click immediately on a hard drive line in the listview from the left side (in the left lower part of the screen). A single left click should display this in the console : $iMsg = -7 $iMsg = -8 -7 is $GUI_EVENT_PRIMARYDOWN and -8 is $GUI_EVENT_PRIMARYUP, so far so good 3) Comment out 1 line in the UDF : ; If $NM_CLICK Then Return 1 ; required, otherwise some events are sent, where the icon index is the event id => random GuiGetMsg events triggered This line seemed superfluous, now that the icon issue has been solved in the UDF version 2.10.2 but... 4) Run again the example as in 2) and this is what is displayed in the console (on my computer) : $iMsg = -7 $iMsg = -8 $iMsg = 5 <====== ? Could you please confirm that you got this extra line in the Console ($iMsg = 5) after you commented out the line in the UDF ? Thanks Kanashius, WildByDesign and ioa747 1 2 "I think you are searching a bug where there is no bug... don't listen to bad advice."
Kanashius Posted December 13 Author Posted December 13 (edited) Hey @pixelsearch, thank you, glad you like the UDF. And yes, I overlooked one call to _GUICtrlListView_AddItem when adding drives, which is now fixed (v2.10.3). I also removed that no longer needed line. Thanks for finding and pointing it out Edited December 13 by Kanashius WildByDesign and pixelsearch 2 My Website: Kanashius Webside (Some of my Programs you can find there)
pixelsearch Posted December 13 Posted December 13 You're welcome ! Everything seems fixed now and icons id's won't interfere anymore with control id's, fingers crossed (not really important but sure you'll update soon the last line of your 1st post which still indicates "Update v2.10.1") I hope @WildByDesign integrates asap your last version 2.10.3 in his project, so he'll get rid of the workaround, i.e. no use to create 2000 dummy controls, which consumes memory for nothing. This workaround was needed when using your UDF version 2.10.1 or 2.10.2 (to separate icons id's and control id's) but it's not necessary anymore when using your UDF version 2.10.3 Just a question if you don't mind : why a "Date created" in the UDF's listview and not the more important "Date modified" instead ? Was it a choice you had to do in your original script ? WildByDesign and ioa747 2 "I think you are searching a bug where there is no bug... don't listen to bad advice."
Kanashius Posted December 13 Author Posted December 13 Quote Just a question if you don't mind : why a "Date created" in the UDF's listview and not the more important "Date modified" instead ? Was it a choice you had to do in your original script ? No real reason, except it was that way in the orginal UDF I made years ago for another project. I added an item to the todo list to make this customizable with a callback function (should be the best solution for an UDF), so that will probably be possible in the future. WildByDesign 1 My Website: Kanashius Webside (Some of my Programs you can find there)
WildByDesign Posted December 13 Posted December 13 9 minutes ago, pixelsearch said: hope @WildByDesign integrates asap your last version 2.10.3 in his project, so he'll get rid of the workaround, i.e. no use to create 2000 dummy controls, which consumes memory for nothing Yes, absolutely. The teamwork in this forum amazes me almost every day. I ended up adding multiple file/folder selection to the ListView so that the statusbar now shows a count of how many folders and/or files are selected plus a total selection count of file sizes. Doing the math for bytes, MB, GB, etc. took a bit of time today but it’s ready tonight. 13 minutes ago, pixelsearch said: Just a question if you don't mind : why a "Date created" in the UDF's listview and not the more important "Date modified" instead ? I agree that Date modified would probably. be better. Or a possibility in the future of adding more options.
ioa747 Posted December 13 Posted December 13 (edited) Thank you for sharing it. Edited December 15 by ioa747 update I know that I know nothing
WildByDesign Posted December 14 Posted December 14 8 hours ago, Kanashius said: Hey, yes that will have negativ consequences. You are essentially disabling the deselection. The point to address this would be the __TreeListExplorer__WinProc function at the end: Thank you for letting me know. If you have some time, please try release FilesAu3-2025-12-13 from the Files Au3 thread. Since I don't fully understand the WinProc stuff and, at least as a temporary solution, I went ahead with that uncommented line for now until I can understand how to address it in a more proper way. For what it's worth, I haven't noticed any consequences or issues with that uncommented line. 9 hours ago, Kanashius said: Now it depends on how you select multiple files. This should be handled in the __TreeListExplorer__WinProc function. Clicking while holding shift already selects multiple files. With STRG, it does not work currently and would have to be implemented as well as for any other key combinations. Maybe you would like to think about the different key combinations and I will take a look at how to best implement that (probably with some keyboard hooks or _IsPressed to check, which keys are pressed). In the FilesAu3-2025-12-13 release, I have multiple file/folder selection by mouse click/drag selection, Ctrl+left-click and Shift+left-click. Those all work very well. However, the Ctrl+A (Select All) does not work currently in that release. I haven't really looked into how to implement it yet, but I would assume I likely need to set up a hotkey. 9 hours ago, Kanashius said: Another thing to think about: Should that also apply to the TreeView? Should multiple selections be syncted between the List/Treeview (if they even show the same files/folders/...) Those are very good questions. At least in my case, I don't think that I need multiple selections in the TreeView. I don't believe that multiple selections need to be synchronized either. Eventually, I would like to attempt to implement drag and drop from ListView to TreeView. Although I don't think that it will need changes in the UDF for that. The file changes would occur and I would just need to refresh the TreeListExplorer system. But I am just doing things one step at a time and learning along the way.
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