KaFu Posted April 6, 2010 Share Posted April 6, 2010 (edited) I've been taking a look at this UDF, nice work ! A reason for the memory leak might be, that in the functions __DrawDefault() and __DrawItemCol() , which are called for every item, a new object handle $hFont = _WinAPI_CreateFont() is created without being destroyed. Comment those creations out, define the handle one time a the top of the script and destroy the object on exit with _WinAPI_DeleteObject($hFont). All what is really needed in those two functions is the allocation to the item via _WinAPI_SelectObject($hDC, $h_Report_ListView_Font). Edit: Of course this makes only sense if you just want to use one specific font , otherwise I guess it's sufficient if you take care of deleting the font object handle via _WinAPI_DeleteObject($hFont) at the end of the functions. Edited April 6, 2010 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
hench Posted April 7, 2010 Share Posted April 7, 2010 wow, really appreciated your comments, I added the DeleteObject, and so far so good, it looks like the leak is gone. I'm gonna have to run several longer test... but I could learn with this..thanks you so much! Really appreciated KaFu, you are an ace !! It's a good day!, hench Link to comment Share on other sites More sharing options...
jennico Posted September 27, 2010 Share Posted September 27, 2010 great piece of work ! rated 5 stars. unfortunately, you cannot use it on large or many listviews, too much cpu load. i wonder if this could be optimized. j. Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96 Link to comment Share on other sites More sharing options...
BugFix Posted August 6, 2011 Author Share Posted August 6, 2011 Made some changes. See Best Regards BugFix Link to comment Share on other sites More sharing options...
BugFix Posted August 10, 2011 Author Share Posted August 10, 2011 - Fixed: in v1.1 was "lost" one script line -- font has had no DC handle - new: Function to add/insert new item accepts now arrays- new: Function to get current Defaultssee Best Regards BugFix Link to comment Share on other sites More sharing options...
LarsJ Posted February 27, 2012 Share Posted February 27, 2012 I have downloaded this UDF today. It runs without errors under 3.3.6.1. But I get errors under 3.3.8.0. It's the following lines in LV_Format_include1.3.au3 that gives errors: $FORMATLV_oPARAM_SEARCH.Add( ..., ...) $FORMATLV_oPARAM_SEARCH.Item( ..., ...) $FORMATLV_oPARAM_SEARCH.Remove( ..., ...) It seems as if a solution is to replace the lines with the following: $FORMATLV_oPARAM_SEARCH.Add( String(...), ...) $FORMATLV_oPARAM_SEARCH.Item( String(...), ...) $FORMATLV_oPARAM_SEARCH.Remove( String(...), ...) Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Logman Posted August 7, 2012 Share Posted August 7, 2012 (edited) I can not sort checkboxes included in listview created by this UDF. Does anyone have any idea how to solve it? expandcollapse popup#include <GuiListView.au3> #include <EditConstants.au3> #include 'LV_Format_include.au3' $Debug_LV = False Global $GUI Global $hLV Global $hListView, $B_DESCENDING Local $col = '' For $i = 1 To 5 $col &= $i & '|' Next ; Main GUI $GUI = GUICreate('') ; LV_Format $hListView = GUICtrlCreateListView(StringTrimRight($col,1), 10, 10, 380, 150, -1, $LVS_EX_CHECKBOXES) ; << ListBox with checkboxes $hLV = GUICtrlGetHandle($hListView) For $i = 0 To 5 _GUICtrlListView_SetColumnWidth($hLV, $i, 75) Next ; initialize Global vars Local $aHWnd[1] = [$hLV] _GUICtrlListView_Formatting_Startup($GUI, $hLV) ; add new Items _GUICtrlListView_AddOrIns_Item($hLV, 'Test0|Test1|Test2|Test3|Test4|Test5') _GUICtrlListView_AddOrIns_Item($hLV, 'Blub0|Blub1|Blub2|Blub3|Blub4|Blub5') _GUICtrlListView_AddOrIns_Item($hLV, 'Club0|Club1|Club2|Club3|Club4|Club5') _GUICtrlListView_AddOrIns_Item($hLV, 'Blab0|Blab1|Blab2|Blab3|Blab4|Blab5') _GUICtrlListView_AddOrIns_Item($hLV, 'Bumm0|Bumm1|Bumm2|Bumm3|Bumm4|Bumm5') ;~ ; standard way ;~ $hListView = GUICtrlCreateListView(StringTrimRight($col,1), 10, 10, 380, 150, -1, $LVS_EX_CHECKBOXES) ; << ListBox with checkboxes ;~ $hLV = GUICtrlGetHandle($hListView) ;~ GUICtrlCreateListViewItem('Test0|Test1|Test2|Test3|Test4|Test5', $hListView) ;~ GUICtrlCreateListViewItem('Blub0|Blub1|Blub2|Blub3|Blub4|Blub5', $hListView) ;~ GUICtrlCreateListViewItem('Club0|Club1|Club2|Club3|Club4|Club5', $hListView) ;~ GUICtrlCreateListViewItem('Blab0|Blab1|Blab2|Blab3|Blab4|Blab5', $hListView) ;~ GUICtrlCreateListViewItem('Bumm0|Bumm1|Bumm2|Bumm3|Bumm4|Bumm5', $hListView) ;~ For $i = 0 To 5 ;~ _GUICtrlListView_SetColumnWidth($hLV, $i, 75) ;~ Next GUISetState(@SW_SHOW, $GUI) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Global $B_DESCENDING[_GUICtrlListView_GetColumnCount($hListView)] While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case Else EndSwitch Sleep (10) WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iCode, $tNMHDR $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_COLUMNCLICK ; A column was clicked $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) ; a LV_Format sort function ; __GUICtrlListView_SimpleSort($hLV, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) ; modified to sort also IParam __GUICtrlListView_SimpleSort($hLV, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) ; modified to sort also IParam ; standard way ;_GUICtrlListView_SimpleSort($hWndListView, $B_DESCENDING, DllStructGetData($tInfo, "SubItem")) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Edited August 7, 2012 by Logman Link to comment Share on other sites More sharing options...
LarsJ Posted August 7, 2012 Share Posted August 7, 2012 Hi Logman In your script: Remove the WM_NOTIFY function at the bottom the script. Add the command _GUICtrlListView_RegisterSortCallBack( $hLV ) just below the line with GUISetState. Remove the line GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") In LV_Format_include.au3: Uncomment the line with __GUICtrlListView_SimpleSort (line 373) Insert this line in stead _GUICtrlListView_SortItems($hLV, DllStructGetData($tInfo, "SubItem")) LarsJ. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
Logman Posted August 7, 2012 Share Posted August 7, 2012 (edited) LarsJ, thanks a lot. The modified code really works! Perfect! Only a small change in the UDF on line 373 (changed the first parameter from $hLV to $hWndFrom): _GUICtrlListView_SortItems($hWndFrom, DllStructGetData($tInfo, "SubItem")) Functional sort: expandcollapse popup#include <GuiListView.au3> #include <EditConstants.au3> #include 'LV_Format_include.au3' Global $GUI Global $hLV Global $hListView Local $col = '' For $i = 1 To 5 $col &= $i & '|' Next ; Main GUI $GUI = GUICreate('') $hListView = GUICtrlCreateListView(StringTrimRight($col,1), 10, 10, 380, 150, -1, $LVS_EX_CHECKBOXES) ; << ListBox with checkboxes $hLV = GUICtrlGetHandle($hListView) For $i = 0 To 5 _GUICtrlListView_SetColumnWidth($hLV, $i, 75) Next ; initialize Global vars Local $aHWnd[1] = [$hLV] _GUICtrlListView_Formatting_Startup($GUI, $hLV) ; add new Items _GUICtrlListView_AddOrIns_Item($hLV, 'Test0|Test1|Test2|Test3|Test4|Test5') _GUICtrlListView_AddOrIns_Item($hLV, 'Blub0|Blub1|Blub2|Blub3|Blub4|Blub5') _GUICtrlListView_AddOrIns_Item($hLV, 'Club0|Club1|Club2|Club3|Club4|Club5') _GUICtrlListView_AddOrIns_Item($hLV, 'Blab0|Blab1|Blab2|Blab3|Blab4|Blab5') _GUICtrlListView_AddOrIns_Item($hLV, 'Bumm0|Bumm1|Bumm2|Bumm3|Bumm4|Bumm5') GUISetState(@SW_SHOW, $GUI) _GUICtrlListView_RegisterSortCallBack($hLV) While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case Else EndSwitch Sleep (10) WEnd _GUICtrlListView_UnRegisterSortCallBack($hLV) ;... Thanks again so much! Edited August 7, 2012 by Logman Link to comment Share on other sites More sharing options...
RichardL Posted August 9, 2012 Share Posted August 9, 2012 (edited) This looks really good, but fails for me. C:...LV_Format_include.au3 (209) : ==> The requested action with this object has failed.: $FORMATLV_oPARAM_SEARCH.Add(DllStructGetData($tITEMPARAM, 1), 0) $FORMATLV_oPARAM_SEARCH.Add(DllStructGetData($tITEMPARAM, 1), 0)^ ERROR I've tried to understand it, but don't know what is a 'Scripting.Dictionary' - where's the documentation for that? Edited August 9, 2012 by RichardL Link to comment Share on other sites More sharing options...
LarsJ Posted August 9, 2012 Share Posted August 9, 2012 RichardL, take a look at post #26. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
RichardL Posted August 9, 2012 Share Posted August 9, 2012 That's better, thanks LarsJ Wow, a few tools can have a facelift now. Link to comment Share on other sites More sharing options...
RichardL Posted August 11, 2012 Share Posted August 11, 2012 I've started merging this into an existing project and run into a problem. If I add an item with the GUI visible, it crashes. You can see this with the example program simply by copying one of the AddOrInsert lines to after the GUISetState. GUISetState(@SW_SHOW, $GUI) _GUICtrlListView_AddOrIns_Item($hLV, 'Test0|Test1|Test2|Test3|Test4|Test5') AutoIt3.exe has encountered a problem and needs to close... AutoIT3.exe ended.rc:-1073741819 It doesn't crash if the added item is off the end of the visible part of the list, or if I hide the GUI while adding items. So these few lines have to be run with the window hidden: Func _GUICtrlListView_AddOrIns_Item2($hWnd, $vText, $iItem=-1) ... GUISetState(@SW_HIDE) If $bAdd Then $iItem = _GUICtrlListView_AddItem($hWnd, $aItemTxt[1]) Else _GUICtrlListView_InsertItem($hWnd, $aItemTxt[1], $iItem) EndIf _GUICtrlListView_SetItemParam($hWnd, $iItem, DllStructGetData($tITEMPARAM, 1) +$SHIFT_PARAMVALUE) GUISetState(@SW_SHOW) ... So the problem is that after adding the item, the screen draw does not have the parameter yet (some bluff here), and the fix is to change the AddItem to include the parameter. It seems to work. (Not tested the InsertItem change yet.) If $bAdd Then $iItem = _GUICtrlListView_AddItem($hWnd, $aItemTxt[1], -1, DllStructGetData($tITEMPARAM, 1) +$SHIFT_PARAMVALUE) Else _GUICtrlListView_InsertItem($hWnd, $aItemTxt[1], $iItem, -1, DllStructGetData($tITEMPARAM, 1) +$SHIFT_PARAMVALUE) EndIf ;_GUICtrlListView_SetItemParam($hWnd, $iItem, DllStructGetData($tITEMPARAM, 1) +$SHIFT_PARAMVALUE) Link to comment Share on other sites More sharing options...
RichardL Posted August 12, 2012 Share Posted August 12, 2012 I think there's a problem with font setting. Where the example program sets the colour and font of a cell, the font is changed for all the subsequent cells in the row. Where it's the last cell, the following row is affected. Try commenting out all the 6 _GUICtrlListView_FormattingCell lines, all cells show same font, looks like 'Courier New' (that could be a default on my PC). Add the first two lines back in, and the right columns are changed. Maybe changed to Arial which might be the default and might be the default on your PC so you won't see the problem. I'll try some more to pin it down, but would appreciate any comments. Link to comment Share on other sites More sharing options...
LarsJ Posted August 13, 2012 Share Posted August 13, 2012 RichardL,I have just seen your posts. If you just wants colors and fonts in your TreeViews and ListViews there are much easier (and faster) ways to do it. Take a look at this thread http://www.autoitscript.com/forum/index.php?showtopic=138250. The zip can be opened with 7-Zip.LarsJ Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
lbsl Posted October 3, 2012 Share Posted October 3, 2012 (edited) RichardL, I have just seen your posts. If you just wants colors and fonts in your TreeViews and ListViews there are much easier (and faster) ways to do it. Take a look at this thread http://www.autoitscript.com/forum/index.php?showtopic=138250. The zip can be opened with 7-Zip. LarsJ While your examples are fairly simple on code size, the overview is quite harder to grasp for a beginner. The OP did a very good job in creating convenience functions that perform a lot of the work whereas your examples don't come with convenience functions However i had a pretty hard time getting these files from BugFix to work properly. It seems that with the combined fixes up to post #26 the only thing you need to know is that you need to add an extra non-used column to take care all other rows are affected if you want to refer to $Index using a variable in a For ... Next loop. (without the extra column, it seems only to affect the first row, if it already affects the first row at all.) I even had to add a space in the column header to make sure something in his routine was convinced not needing to process "all" available columns. I haven't included RichardL's changes into the file because i wasn't capable of reproducing his problems. I don't know which version of AutoIt3 he is using. Attached file was changed to work with 3.3.8.1. LV_Format_include1.4.zip Still these routines are not stable though, i have noticed when generating large lists, the redraw update sometimes fails during fast scrolling of the list and some lines are not altered or partically altered. It gets fixed if you scroll back and forth slowly. Lars, your routines seem doing a better job on the supplied examples, but i have more trouble in adapting your code to my projects. So how about adding some similar reference function calls like BugFix's routine to perform the job? Edited October 3, 2012 by lbsl Link to comment Share on other sites More sharing options...
LarsJ Posted October 3, 2012 Share Posted October 3, 2012 lbsl, Good idea. Have you considered to do it yourself? I think you should. You have been working with BugFix's code and you have testet my examples, so you probably already have some ideas. And if you can use it in your projects you have a good reason to do it. You can find the documentation here: http://msdn.microsoft.com/en-us/library/windows/desktop/ff919569(v=vs.85).aspx. I'm sure some convenience functions would be appreciated.Regards Lars. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions Link to comment Share on other sites More sharing options...
zotchy Posted July 22, 2013 Share Posted July 22, 2013 (edited) First of all. This UDF is brilliant!!! It was very helpful! Could you kindly assist me with couple of issues here? Here is my case. I need to update cells by array returned from SQL server. This is the part: if $rs.RecordCount Then $i=0 while not $rs.EOF _GUICtrlListView_AddItem($cListView1,$rs.Fields(0).Value, $i) for $j = 1 to 4 if $j = 4 Then _GUICtrlListView_AddSubItem($cListView1,$i,$rs.Fields($j), $j) ; this cell ($j=4) contains a hyperlink EndIf _GUICtrlListView_AddSubItem($cListView1,$i,$rs.Fields($j).Value, $j) Next $rs.MoveNext $i=$i+1 WEnd EndIf Update is working as expected and no problems here. But one of columns from SQL DB contains a hyperlink, which I need to convert to hyperlink (word a "Link" with hyperlink behind). As far as I understand inserting of hyperlinks is not that obvious. All examples on the forum are explaining how to work with lables, but my case is not similar. And another question is very simple: how to copy something from the table? Ctrl+C is not working. Thank you for your assistance. Edited July 23, 2013 by zotchy Link to comment Share on other sites More sharing options...
weirddave Posted March 5, 2015 Share Posted March 5, 2015 (edited) I've created a simple script which I can't get to work: #include 'LV_Format_include.1.4.au3' $MyGUI = GUICreate("listview items", 320, 200, 0,-1, -1) $idListview = GUICtrlCreateListView("A|B|C", 10, 10, 250, 155) $idButton = GUICtrlCreateButton("Add", 125, 175, 70, 20) $hListview = GUICtrlGetHandle($idListview) _GUICtrlListView_Formatting_Startup($MyGUI, $hListview) GUISetState(@SW_SHOW) while 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE ExitLoop Case $idButton GUICtrlCreateListViewItem("a|b|c", $idListview) $LogItemCount = _GUICtrlListView_GetItemCount($idListview)-1 _GUICtrlListView_FormattingCell($hListview, $LogItemCount, 2, 0xff0000, -1, -1, -1, -1) EndSwitch sleep(10) wend The script locks up and I have to kill the process. If I comment out the Formatting_Startup and FormattingCell commands, the add button adds a new row to the listview correctly. Any pointers would be appreciated. Edit: code window didn't work Edited March 5, 2015 by weirddave Link to comment Share on other sites More sharing options...
LarsJ Posted March 6, 2015 Share Posted March 6, 2015 Take a look at post 26.If you want faster code then take a look at Custom drawn TreeViews and ListViews Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions 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