Jump to content

ListView - for every SubItem set color, backcol and font


BugFix
 Share

Recommended Posts

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 by KaFu
Link to comment
Share on other sites

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

  • 5 months later...

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.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Link to comment
Share on other sites

  • 10 months later...
  • 6 months later...

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(...), ...)

Link to comment
Share on other sites

  • 5 months later...

I can not sort checkboxes included in listview created by this UDF. Does anyone have any idea how to solve it?

#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 by Logman
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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:

#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 by Logman
Link to comment
Share on other sites

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 by RichardL
Link to comment
Share on other sites

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

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

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

Link to comment
Share on other sites

  • 1 month later...

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 by lbsl
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 9 months later...

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 by zotchy
Link to comment
Share on other sites

  • 1 year later...

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 by weirddave
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...