ListView - SubItem einzeln färben/formatieren, Finale Version! (v1.3)

    • Offizieller Beitrag

    Hi,
    ich denke, dass ihr sicherlich reichlich Anwendung für dieses Workaround diese UDF finden werdet.
    Mit den Standardfunktionen ließen sich ja nur abwechselnd die Zeilen einfärben. Nun habt ihr folgende Möglichkeiten:
    - jedes SubItem einzeln färben (TextColor, BackColor) und
    - formatieren (Größe, Weite, Schriftart etc....)

    Edit 30.08.2009
    Hab das nochmal etwas überarbeitet und ein Problem gefixed. Die in IParam gespeicherten Werte konnten mit Control-IDs kollidieren. Das ist jetzt behoben.
    Die wesentlichen Punkte im Skript sind kommentiert, damit ihr nachvollziehen könnt, was passiert.

    Edit 27.09.2009
    Ich habe nochmal zugeschlagen :D
    - keine Begrenzung der Spaltenzahl mehr!
    - Auch bei mehreren Listview werden alle Formatierungsdaten in einem Array verwaltet
    - die Prüfung, ob ein (Sub)Item formatiert ist, läuft wesentlich schneller
    - Management zur Verwaltung der Formatinfos zu den Items ist integriert (UDF-Funktionen angepaßt)
    - Listview kann sortiert, Einträge können eingefügt, gelöscht werden etc.

    autoit.de/wcf/attachment/5913/

    Finale Version (30.09.09)
    So, nun bin ich wohl endlich bei der endgültigen Version angelangt. 8o

    Der User braucht nun keine Handstände mehr zu machen. Alles Lästige ist in eine Include-Datei ausgelagert. Auch WM_NOTIFY. Die Funktionsnamen habe ich analog zu denen der Listview-UDF erstellt. Ich habe als Standard eingerichtet, dass mit Klick auf die Spalte sortiert werden kann.

    Edit 06.08.11
    Nach langer Zeit mal wieder einige kleine Änderungen:
    1. Da alle Funktionen ausgelöst werden durch Auswertung von $WM_NOTIFY, mußten eigene Auswertungen ins Include geschrieben werden -- schlecht :huh:
    Jetzt hooke ich die Message, sodass $WM_NOTIFY ganz normal mit GuiRegisterMsg registriert und verwendet werden kann.

    2. Es wird jetzt eine Globale Variable ( $FORMATLV_aITEM_INDEX ) bereitgestellt, die mit den Formatinformationen des per Rechtsklick markierten SubItem befüllt ist.
    Inhalt: [Status geklickt:True/False, $hWndFrom, "Index", "SubItem", $iBkCol, $iCol, $iSize, $iWeight, $sFont]. Verwendung s. Func _RightClick() im Bsp.-Skript.

    3. Die Funktion _GUICtrlListView_Formatting_Shutdown() braucht nicht mehr ins Skript eingebaut werden, da sie jetzt beim Beenden des Skripts automatisch aufgerufen wird.

    Die alten Versionen habe ich jetzt entfernt.

    Edit 08.08.2011
    Und noch etwas geschraubt:
    1. Zum Erstellen der Listvieweinträge (_GUICtrlListView_AddOrIns_Item) kann jetzt auch ein Array übergeben werden.
    Im Test hatte ich für 10.000 Item (6 spaltig) mit Einzelaufruf 2.241 sec benötigt. Bei Übergabe mit Array schrumpfte das auf 87 sec.
    Ich benötige jetzt also <4 % der Zeit, das nenn ich eine gelungene Einsparung. Hauptbremse war natürlich ReDim - sollte man immer sehr sparsam verwenden.

    2. Die Performance sollte jetzt auch etwas flüssiger sein. Ich habe Abfragen eingefügt, sodass Neuzeichnungen nur erfolgen, wenn eine Änderung zum vorhergehenden Element besteht.

    3. Die Funktion _GUICtrlListView_DefaultsGet() habe ich noch hinzugefügt. War schon im letzten Anhang dabei, hatte ich nur vergessen zu erwähnen.
    Damit können die Standardformatierungswerte ausgelesen werden. [$iBkCol, $iCol, $iSize, $iWeight, $sFont]

    Eine Funktion zum Spalten einfügen wird es vermutlich nicht geben. Um das realisieren zu können, müßte ich wohl mein Programmkonzept völlig neu gestalten, d.h. alles nochmal neu entwickeln. In den bisherigen Ablauf läßt sich diese Funktion nicht sinnvoll einbringen.

    Edit 10.08.2011
    Fix: Beim Einfügen eines Arrays neuer Item, wurde die Reihenfolge der eingefügten Item vertauscht, v1.3 aktualisiert

    Hier die Funktionen:

    Initialisierung beim Start (nach Erstellung der GUI)
    _GUICtrlListView_Formatting_Startup($GUI, $hListView)
    $GUI Handle der GUI
    $hListView Listview Handle, bei mehreren LV die Handle als Array übergeben

    Ressourcen löschen am Skriptende
    _GUICtrlListView_Formatting_Shutdown() erfolgt jetzt automatisch mit Beendigung des Skripts

    Neue Listvieweinträge an- oder einfügen
    _GUICtrlListView_AddOrIns_Item($hWnd, $vText, $iItem=-1)
    $hWnd Listview Handle
    $vText einfacher String um nur das Item zu setzen (dann muß SubItem mit _GUICtrlListView_AddSubItem gesetzt werden)
    oder
    "Item|SubItem|SubItem.." um Item und alle SubItem auf einmal zu setzen
    oder
    ein Array mit derartigen Strings
    $iItem Item Index, mit -1 wird das neue Item am Ende angefügt (Standard)
    sonst
    das Item wird an der Indexposition eingefügt

    Löschen von einem, markierten oder allen Item:
    _GUICtrlListView_FormattedDeleteItem($hWnd, $iIndex)
    _GUICtrlListView_FormattedDeleteItemsSelected($hWnd)
    _GUICtrlListView_FormattedDeleteAllItems($hWnd)


    Standards zur Formatierung setzen/abfragen
    _GUICtrlListView_DefaultsSet($iBkCol=0xFFFFFF, $iCol=0x000000, $iSize=14, $iWeight=400, $sFont='Arial')
    $iBkCol back color Standard: weiß
    $iCol text color Standard: schwarz
    $iSizefont size Standard: 14
    $iWeight font weight Standard: 400
    $sFontfont name Standard: Arial

    _GUICtrlListView_DefaultsGet()
    Return: [$iBkCol, $iCol, $iSize, $iWeight, $sFont]

    (Sub)Item Formatieren
    _GUICtrlListView_FormattingCell($hWnd, $iItem, $iSubItem, $iBkCol=-1, $iCol=-1, $iSize=-1, $iWeight=-1, $sFont=-1)
    $hWnd Listview Handle
    $iItem Item Index
    $iSubItem SubItem Index
    $iBkCol back color (-1 = default BkCol)
    $iCol text color (-1 = default txtCol)
    $iSize height of font (-1 = 14)
    $iWeight font weight (-1 = 400)
    $sFont typefont name (-1 = Arial)


    Edit
    Habe noch ein Skript erstellt um die Funktionen den Calltipps von SciTE hinzuzufügen.

    Edit 08.04.2012
    Mit AutoIt-Version3.3.8.0 ist folgende Änderung erforderlich:

    [autoit]

    ; statt:
    $FORMATLV_oPARAM_SEARCH.Add( ..., ...)
    $FORMATLV_oPARAM_SEARCH.Item( ..., ...)
    $FORMATLV_oPARAM_SEARCH.Remove( ..., ...)

    [/autoit][autoit][/autoit][autoit]

    ; den ersten Parameter als String übergeben:

    [/autoit][autoit][/autoit][autoit]

    $FORMATLV_oPARAM_SEARCH.Add( String(...), ...)
    $FORMATLV_oPARAM_SEARCH.Item( String(...), ...)
    $FORMATLV_oPARAM_SEARCH.Remove( String(...), ...)

    [/autoit]
    LV_Format_Include v 1.3
    [autoit]

    #Region - TimeStamp
    ; 2011-08-08 16:15:02 v 1.3
    #EndRegion - TimeStamp

    [/autoit] [autoit][/autoit] [autoit]

    #cs
    Initialize Global vars at startup
    _GUICtrlListView_Formatting_Startup($hGUI, $hListView)
    $hGUI Handle of your GUI
    $hListView Listview handle, for several LV commit handle's as array

    [/autoit] [autoit][/autoit] [autoit]

    [ Clean up ressources ==> Changed! ==> now automatically called on AutoIt exit ]
    _GUICtrlListView_Formatting_Shutdown()

    [/autoit] [autoit][/autoit] [autoit]

    Add or insert new Listview Item:
    _GUICtrlListView_AddOrIns_Item($hWnd, $sText, $iItem=-1)
    $hWnd Listview handle
    $vText String with:
    lonely string to set only Item text (than SubItem must set with _GUICtrlListView_AddSubItem)
    or
    "Item|SubItem|SubItem.." to set all text at once
    or..
    an Array with this strings to set more than one Item at once
    $iItem Item index, if -1 a new Item will add at the end (default)
    otherwise
    the Item will insert at index position

    [/autoit] [autoit][/autoit] [autoit]

    Delete one, selected or all Item:
    _GUICtrlListView_FormattedDeleteItem($hWnd, $iIndex)
    _GUICtrlListView_FormattedDeleteItemsSelected($hWnd)
    _GUICtrlListView_FormattedDeleteAllItems($hWnd)

    [/autoit] [autoit][/autoit] [autoit]

    Set defaults
    _GUICtrlListView_DefaultsSet($iBkCol=0xFFFFFF, $iCol=0x000000, $iSize=14, $iWeight=400, $sFont='Arial')
    $iBkCol back color default white
    $iCol text color default black
    $iSize font size default 14
    $iWeight font weight default 400
    $sFont font name default Arial

    [/autoit] [autoit][/autoit] [autoit]

    Get defaults
    _GUICtrlListView_DefaultsGet()
    Return: [$iBkCol, $iCol, $iSize, $iWeight, $sFont]

    [/autoit] [autoit][/autoit] [autoit]

    Format Listview Item
    _GUICtrlListView_FormattingCell($hWnd, $iItem, $iSubItem, $iBkCol=-1, $iCol=-1, $iSize=-1, $iWeight=-1, $sFont=-1)
    $hWnd Listview handle
    $iItem Item index
    $iSubItem SubItem index
    $iBkCol back color (-1 = default BkCol)
    $iCol text color (-1 = default txtCol)
    $iSize height of font (-1 = 14)
    $iWeight font weight (-1 = 400)
    $sFont typefont name (-1 = Arial)

    [/autoit] [autoit][/autoit] [autoit]

    Sort Listview:
    By default SimpleSort doesn't really sort Items - only Item-/SubItem text moves. Because that, IParam stands at same
    position like before. I've modified this function, so that IParam also will sorted.
    __GUICtrlListView_SimpleSort($hWnd, ByRef $vDescending, $iCol)

    [/autoit] [autoit][/autoit] [autoit]

    Call from WM_NOTIFY_LV_FORMAT
    __getMarked($hWnd, $iItem, $iSubItem) ==> check if SubItem is formatted
    __DrawItemCol(ByRef $hDC, ByRef $tCustDraw, $hWnd, $iItem, $iSubitem) ==> draw formatted SubItem
    __DrawDefault(ByRef $hDC, ByRef $tCustDraw) ==> draw unformatted SubItem
    for simple sort:
    __GUICtrlListView_SimpleSort($hWnd, ByRef $vDescending, $iCol)

    [/autoit] [autoit][/autoit] [autoit]

    #ce

    [/autoit] [autoit][/autoit] [autoit]

    #include-once
    #include <Array.au3>
    #include <FontConstants.au3>
    #include <GuiListView.au3>
    #include <ListViewConstants.au3>
    #include <Constants.au3>
    #include <WindowsConstants.au3>
    #include <StructureConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WinAPI.au3>

    [/autoit] [autoit][/autoit] [autoit]

    OnAutoItExitRegister("_GUICtrlListView_Formatting_Shutdown")

    [/autoit] [autoit][/autoit] [autoit]

    Global Const $SHIFT_PARAMVALUE = 9000 ; == if you have higher Ctrl-ID in your script - increase this value
    Global $FORMATLV_hPROC, $FORMATLV_hHOOK, $FORMATLV_hGUI
    Global $FORMATLV_aITEM_INDEX
    ; == $FORMATLV_aITEM_INDEX
    ; == use in your script this Global array variable with information about right clicked Item [state clicked:TrueFalse, $hWndFrom, "Index", "SubItem", $iBkCol, $iCol, $iSize, $iWeight, $sFont]
    ; == use GuiRegisterMessage($WM_NOTIFY, 'Function') to react
    ; == how to use, see Func _RightClick() inside "Example_LV_Format.au3"

    [/autoit] [autoit][/autoit] [autoit]

    Global $FORMATLV_DEF_BKCOL = 0xFFFFFF
    Global $FORMATLV_DEF_COL = 0x000000
    Global $FORMATLV_DEF_SIZE = 14
    Global $FORMATLV_DEF_WEIGHT = 400
    Global $FORMATLV_DEF_FONT = 'Arial'
    Global $FORMATLV_LAST_FONT_SIZE = $FORMATLV_DEF_SIZE
    Global $FORMATLV_LAST_FONT_WEIGHT = $FORMATLV_DEF_WEIGHT
    Global $FORMATLV_LAST_FONT_TYPE = $FORMATLV_DEF_FONT
    Global $FORMATLV_LAST_COL = $FORMATLV_DEF_COL
    Global $FORMATLV_LAST_BKCOL = $FORMATLV_DEF_BKCOL
    Global $FORMATLV_LAST_DEF = False
    Global $FORMATLV_aHWND, $FORMATLV_CURR_WINDOW, $FORMATLV_MAX_COLUMN, $FORMATLV_aIPARAM[1][1][5]
    Global $FORMATLV_oPARAM_SEARCH, $FORMATLV_hFONT, $FORMATLV_B_DESCENDING

    [/autoit] [autoit][/autoit] [autoit]

    Func _GUICtrlListView_Formatting_Startup($hGUI, $hListView)
    $FORMATLV_hGUI = $hGUI
    ; initialize Callback Function to analyze $WM_NOTIFY
    $FORMATLV_hPROC = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;wparam;lparam')
    $FORMATLV_hHOOK = _WinAPI_SetWindowLong($FORMATLV_hGUI, $GWL_WNDPROC, DllCallbackGetPtr($FORMATLV_hPROC))
    Local $count
    If IsArray($hListView) Then
    $FORMATLV_MAX_COLUMN = _GUICtrlListView_GetColumnCount($hListView[0])
    For $i = 0 To UBound($hListView) -1
    If Not IsHWnd($hListView[$i]) Then
    $hListView[$i] = GUICtrlGetHandle($hListView[$i])
    EndIf
    $count = _GUICtrlListView_GetColumnCount($hListView[$i])
    If $count > $FORMATLV_MAX_COLUMN Then
    $FORMATLV_MAX_COLUMN = $count
    EndIf
    Next
    $FORMATLV_aHWND = $hListView
    Else
    If Not IsHWnd($hListView) Then
    $hListView = GUICtrlGetHandle($hListView)
    EndIf
    $FORMATLV_MAX_COLUMN = _GUICtrlListView_GetColumnCount($hListView)
    Local $aTmp[1] = [$hListView]
    $FORMATLV_aHWND = $aTmp
    EndIf
    ReDim $FORMATLV_aIPARAM[1][$FORMATLV_MAX_COLUMN+1][5] ; [n][0][0]=ItemStruct, [n][1..Count][0..4]=SubItemValue
    $FORMATLV_oPARAM_SEARCH = ObjCreate('Scripting.Dictionary')
    $FORMATLV_CURR_WINDOW = $FORMATLV_hGUI
    If Not IsHWnd($FORMATLV_CURR_WINDOW) Then $FORMATLV_CURR_WINDOW = WinGetHandle($FORMATLV_CURR_WINDOW)
    EndFunc ;==>_GUICtrlListView_Formatting_Startup

    [/autoit] [autoit][/autoit] [autoit]

    Func _GUICtrlListView_Formatting_Shutdown()
    $FORMATLV_aIPARAM = 0
    $FORMATLV_oPARAM_SEARCH = 0
    _WinAPI_SetWindowLong($FORMATLV_hGUI, $GWL_WNDPROC, $FORMATLV_hHOOK) ; to reconstruct original WinProcedure
    EndFunc ;==>_GUICtrlListView_Formatting_Shutdown

    [/autoit] [autoit][/autoit] [autoit]

    Func _GUICtrlListView_DefaultsSet($iBkCol=0xFFFFFF, $iCol=0x000000, $iSize=14, $iWeight=400, $sFont='Arial')
    $FORMATLV_DEF_BKCOL = $iBkCol
    $FORMATLV_DEF_COL = $iCol
    $FORMATLV_DEF_SIZE = $iSize
    $FORMATLV_DEF_WEIGHT = $iWeight
    $FORMATLV_DEF_FONT = $sFont
    _WinAPI_RedrawWindow($FORMATLV_CURR_WINDOW)
    EndFunc ;==>_GUICtrlListView_DefaultsSet

    [/autoit] [autoit][/autoit] [autoit]

    Func _GUICtrlListView_DefaultsGet()
    Local $aRet[5] = [ _
    $FORMATLV_DEF_BKCOL, _
    $FORMATLV_DEF_COL, _
    $FORMATLV_DEF_SIZE, _
    $FORMATLV_DEF_WEIGHT, _
    $FORMATLV_DEF_FONT]
    Return $aRet
    EndFunc ;==>_GUICtrlListView_DefaultsGet

    [/autoit] [autoit][/autoit] [autoit]

    Func _GUICtrlListView_AddOrIns_Item($hWnd, $vText, $iItem=-1)
    Local $tagITEMPARAM = "int_ptr;byte[" & $FORMATLV_MAX_COLUMN & "];", $tITEMPARAM, $aItem = $vText, $aItemTxt, $1stItemFilled = 0
    Local $lastIndex, $bAdd = False, $ub_aItem, $ub_aIPARAM, $DataSep = Opt('GUIDataSeparatorChar'), $n = 0
    If Not IsHWnd($hWnd) Then
    $hWnd = GUICtrlGetHandle($hWnd)
    EndIf
    Local $itemCount = _GUICtrlListView_GetItemCount($hWnd)
    ; == if not is array $vText ==> create array
    If Not IsArray($aItem) Then
    Local $aTmp[1] = [$aItem]
    $aItem = $aTmp
    EndIf
    $ub_aItem = UBound($aItem)
    ; == check insert position ($iItem)
    Select
    Case ( $iItem < 0 ) Or ( $iItem >= $itemCount ); append at the end
    $iItem = -1
    $bAdd = True
    Case $iItem < $itemCount
    $bAdd = False
    EndSelect
    ; == one item or array of item - append/insert
    ; == increase array if necessary
    $ub_aIPARAM = UBound($FORMATLV_aIPARAM)
    $lastIndex = $ub_aIPARAM -1
    $1stItemFilled = IsDllStruct($FORMATLV_aIPARAM[0][0][0])
    If $1stItemFilled = 1 Then ; == 1st entry not empty
    ReDim $FORMATLV_aIPARAM[$ub_aIPARAM +$ub_aItem][$FORMATLV_MAX_COLUMN+1][5]
    $lastIndex += 1
    Else ; == 1st entry is empty
    If $ub_aItem > 1 Then
    ReDim $FORMATLV_aIPARAM[$ub_aIPARAM +$ub_aItem -1][$FORMATLV_MAX_COLUMN+1][5]
    EndIf
    EndIf
    For $i = 0 To $ub_aItem -1
    $1stItemFilled = IsDllStruct($FORMATLV_aIPARAM[0][0][0])
    ; == create structure, fill with zeros, store to array
    ; == storage index from array stored about integer pointer in an dictionary object: key=IntegerPointer, val=ArrayIndex
    $tITEMPARAM = DllStructCreate($tagITEMPARAM)
    DllStructSetData($tITEMPARAM, 1, DllStructGetPtr($tITEMPARAM, 2))
    For $j = 1 To $FORMATLV_MAX_COLUMN
    DllStructSetData($tITEMPARAM, 2, 0, $j)
    Next
    If $1stItemFilled = 0 Then
    $FORMATLV_aIPARAM[0][0][0] = $tITEMPARAM
    $FORMATLV_oPARAM_SEARCH.Add(DllStructGetData($tITEMPARAM, 1), 0)
    Else
    $FORMATLV_aIPARAM[$lastIndex +$i][0][0] = $tITEMPARAM
    $FORMATLV_oPARAM_SEARCH.Add(DllStructGetData($tITEMPARAM, 1), $lastIndex +$i)
    EndIf
    ; == create listview -Item, -SubItem, store IntegerPointer as ItemParam
    $aItemTxt = StringSplit($aItem[$i], $DataSep, 1)
    If $bAdd Then
    $iItem = _GUICtrlListView_AddItem($hWnd, $aItemTxt[1])
    Else
    _GUICtrlListView_InsertItem($hWnd, $aItemTxt[1], $iItem +$i)
    $n = $i
    EndIf
    _GUICtrlListView_SetItemParam($hWnd, $iItem +$n, DllStructGetData($tITEMPARAM, 1) +$SHIFT_PARAMVALUE)
    If $aItemTxt[0] > 1 Then
    For $j = 2 To UBound($aItemTxt) -1
    _GUICtrlListView_AddSubItem($hWnd, $iItem +$n, $aItemTxt[$j], $j-1)
    Next
    EndIf
    Next
    EndFunc ;==>_GUICtrlListView_AddOrIns_Item

    [/autoit] [autoit][/autoit] [autoit]

    Func _GUICtrlListView_FormattedDeleteItem($hWnd, $iIndex)
    Local $iParam = _GUICtrlListView_GetItemParam($hWnd, $iIndex) -$SHIFT_PARAMVALUE
    $FORMATLV_aIPARAM[$FORMATLV_oPARAM_SEARCH.Item($iParam)][0][0] = ''
    $FORMATLV_oPARAM_SEARCH.Remove($iParam)
    _GUICtrlListView_DeleteItem($hWnd, $iIndex)
    EndFunc ;==>_GUICtrlListView_FormattedDeleteItem

    [/autoit] [autoit][/autoit] [autoit]

    Func _GUICtrlListView_FormattedDeleteItemsSelected($hWnd)
    Local $aSelected = _GUICtrlListView_GetSelectedIndices($hWnd, True)
    For $i = 1 To $aSelected[0]
    Local $iParam = _GUICtrlListView_GetItemParam($hWnd, $aSelected[$i]) -$SHIFT_PARAMVALUE
    $FORMATLV_aIPARAM[$FORMATLV_oPARAM_SEARCH.Item($iParam)][0][0] = ''
    $FORMATLV_oPARAM_SEARCH.Remove($iParam)
    _GUICtrlListView_DeleteItem($hWnd, $aSelected[$i])
    Next
    EndFunc ;==>_GUICtrlListView_FormattedDeleteItemsSelected

    [/autoit] [autoit][/autoit] [autoit]

    Func _GUICtrlListView_FormattedDeleteAllItems($hWnd)
    Local $item = _GUICtrlListView_GetItemCount($hWnd)
    For $i = 0 To $item -1
    Local $iParam = _GUICtrlListView_GetItemParam($hWnd, $i) -$SHIFT_PARAMVALUE
    $FORMATLV_aIPARAM[$FORMATLV_oPARAM_SEARCH.Item($iParam)][0][0] = ''
    $FORMATLV_oPARAM_SEARCH.Remove($iParam)
    Next
    _GUICtrlListView_DeleteAllItems($hWnd)
    EndFunc ;==>_GUICtrlListView_FormattedDeleteAllItems

    [/autoit] [autoit][/autoit] [autoit]

    Func _GUICtrlListView_FormattingCell($hWnd, $iItem, $iSubItem, $iBkCol=-1, $iCol=-1, $iSize=-1, $iWeight=-1, $sFont=-1)
    Local $sumParam = 0
    Local $iParam = _GUICtrlListView_GetItemParam($hWnd, $iItem) -$SHIFT_PARAMVALUE
    Local $index = $FORMATLV_oPARAM_SEARCH.Item($iParam)
    If $iBkCol = -1 Then
    $iBkCol = $FORMATLV_DEF_BKCOL
    $sumParam += 1
    EndIf
    If $iCol = -1 Then
    $iCol = $FORMATLV_DEF_COL
    $sumParam += 1
    EndIf
    If $iSize = -1 Then
    $iSize = $FORMATLV_DEF_SIZE
    $sumParam += 1
    EndIf
    If $iWeight = -1 Then
    $iWeight = $FORMATLV_DEF_WEIGHT
    $sumParam += 1
    EndIf
    If $sFont = -1 Then
    $sFont = $FORMATLV_DEF_FONT
    $sumParam += 1
    EndIf
    $FORMATLV_aIPARAM[$index][$iSubItem+1][0] = $iBkCol
    $FORMATLV_aIPARAM[$index][$iSubItem+1][1] = $iCol
    $FORMATLV_aIPARAM[$index][$iSubItem+1][2] = $iSize
    $FORMATLV_aIPARAM[$index][$iSubItem+1][3] = $iWeight
    $FORMATLV_aIPARAM[$index][$iSubItem+1][4] = $sFont
    ; if SubItem not registered in IParam OR all values by -1 (delete Sub from IParam) ==> switch Sub value in IParam
    Local $mark = DllStructGetData($FORMATLV_aIPARAM[$index][0][0], 2, $iSubItem+1)
    If Not $mark Or $sumParam = 5 Then
    DllStructSetData($FORMATLV_aIPARAM[$index][0][0], 2, BitXOR($mark, 1), $iSubItem+1)
    EndIf
    If DllStructGetData($FORMATLV_aIPARAM[$index][0][0], 2, $iSubItem+1) <> $mark Or $sumParam <> 5 Then
    _GUICtrlListView_RedrawItems($hWnd, $iItem, $iItem)
    EndIf
    EndFunc ;==>_GUICtrlListView_FormattingCell

    [/autoit] [autoit][/autoit] [autoit]

    Func __DrawItemCol(ByRef $hDC, ByRef $tCustDraw, $hWnd, $iItem, $iSubitem) ; draw formatted item
    Local $aDefFont[14] = [14,0,0,0,$FW_NORMAL,False,False,False, _
    $DEFAULT_CHARSET,$OUT_DEFAULT_PRECIS,$CLIP_DEFAULT_PRECIS,$DEFAULT_QUALITY,0,'Arial']
    Local $iSZ = $FORMATLV_aIPARAM[$iItem][$iSubItem+1][2]
    Local $iWT = $FORMATLV_aIPARAM[$iItem][$iSubItem+1][3]
    Local $sTP = $FORMATLV_aIPARAM[$iItem][$iSubItem+1][4]
    Local $iTX = $FORMATLV_aIPARAM[$iItem][$iSubItem+1][1]
    Local $iBK = $FORMATLV_aIPARAM[$iItem][$iSubItem+1][0]
    Local $bFontChanged = False
    If ( $iSZ <> $FORMATLV_LAST_FONT_SIZE ) Or ( $iWT <> $FORMATLV_LAST_FONT_WEIGHT ) Or ( $sTP <> $FORMATLV_LAST_FONT_TYPE ) Then
    $aDefFont[0] = $iSZ
    $aDefFont[4] = $iWT
    $aDefFont[13] = $sTP
    $FORMATLV_LAST_FONT_SIZE = $iSZ
    $FORMATLV_LAST_FONT_WEIGHT = $iWT
    $FORMATLV_LAST_FONT_TYPE = $sTP
    $bFontChanged = True
    EndIf
    If ( $iTX <> $FORMATLV_LAST_COL ) Then
    DllStructSetData($tCustDraw, 'clrText', RGB2BGR($iTX))
    $FORMATLV_LAST_COL = $iTX
    EndIf
    If ( $iBK <> $FORMATLV_LAST_BKCOL ) Then
    DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($iBK))
    $FORMATLV_LAST_BKCOL = $iBK
    EndIf
    If $bFontChanged Then
    $FORMATLV_hFONT = _WinAPI_CreateFont($iSZ,$aDefFont[1],$aDefFont[2],$aDefFont[3],$iWT,$aDefFont[5],$aDefFont[6], _
    $aDefFont[7],$aDefFont[8],$aDefFont[9],$aDefFont[10],$aDefFont[11],$aDefFont[12],$sTP)
    _WinAPI_SelectObject($hDC, $FORMATLV_hFONT)
    _WinAPI_DeleteObject($FORMATLV_hFONT)
    EndIf
    $FORMATLV_LAST_DEF = False
    EndFunc ;==>__DrawItemCol

    [/autoit] [autoit][/autoit] [autoit]

    Func __DrawDefault(ByRef $hDC, ByRef $tCustDraw) ; draw unformatted item
    If $FORMATLV_LAST_DEF Then Return
    $hDC = DllStructGetData($tCustDraw, 'hdc')
    DllStructSetData($tCustDraw, 'clrText', RGB2BGR($FORMATLV_DEF_COL))
    DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($FORMATLV_DEF_BKCOL))
    $FORMATLV_hFONT = _WinAPI_CreateFont(14,0,0,0,$FW_NORMAL,False,False,False,$DEFAULT_CHARSET,$OUT_DEFAULT_PRECIS, _
    $CLIP_DEFAULT_PRECIS,$DEFAULT_QUALITY,0,'Arial')
    _WinAPI_SelectObject($hDC, $FORMATLV_hFONT)
    _WinAPI_DeleteObject($FORMATLV_hFONT)
    $FORMATLV_LAST_DEF = True
    $FORMATLV_LAST_FONT_SIZE = $FORMATLV_DEF_SIZE
    $FORMATLV_LAST_FONT_WEIGHT = $FORMATLV_DEF_WEIGHT
    $FORMATLV_LAST_FONT_TYPE = $FORMATLV_DEF_FONT
    $FORMATLV_LAST_COL = $FORMATLV_DEF_COL
    $FORMATLV_LAST_BKCOL = $FORMATLV_DEF_BKCOL
    EndFunc ;==>__DrawDefault

    [/autoit] [autoit][/autoit] [autoit]

    Func __getMarked($hWnd, $iItem, $iSubItem) ; get index from array if item is formatted
    Local $cntCOL = _GUICtrlListView_GetColumnCount($hWnd)
    Local $iParam = _GUICtrlListView_GetItemParam($hWnd, $iItem) -$SHIFT_PARAMVALUE
    Local $struct = DllStructCreate("byte[" & $cntCOL & "]", $iParam)
    If DllStructGetData($struct, 1, $iSubItem+1) Then
    Return $FORMATLV_oPARAM_SEARCH.Item($iParam)
    Else
    Return -1
    EndIf
    EndFunc ;==>__getMarked

    [/autoit] [autoit][/autoit] [autoit]

    Func RGB2BGR($iColor)
    Local $sH = Hex($iColor,6)
    Return '0x' & StringRight($sH, 2) & StringMid($sH,3,2) & StringLeft($sH, 2)
    EndFunc ;==>RGB2BGR

    [/autoit] [autoit][/autoit] [autoit]

    Func _WinProc($hWnd, $Msg, $wParam, $lParam)
    If $Msg <> $WM_NOTIFY Then Return _WinAPI_CallWindowProc($FORMATLV_hHOOK, $hWnd, $Msg, $wParam, $lParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 0 To UBound($FORMATLV_aHWND) -1
    If $hWndFrom = $FORMATLV_aHWND[$i] Then
    Switch $iCode
    Case $LVN_COLUMNCLICK
    Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
    __GUICtrlListView_SimpleSort($hWndFrom, $FORMATLV_B_DESCENDING, DllStructGetData($tInfo, "SubItem"))
    Case $NM_CUSTOMDRAW
    If Not _GUICtrlListView_GetViewDetails($hWndFrom) Then Return $GUI_RUNDEFMSG
    Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
    Local $iDrawStage, $iItem, $iSubitem, $hDC = DllStructGetData($tCustDraw, 'hdc'), $tRect
    $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage')
    Switch $iDrawStage
    Case $CDDS_ITEMPREPAINT
    Return $CDRF_NOTIFYSUBITEMDRAW
    Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
    $iItem = DllStructGetData($tCustDraw, 'dwItemSpec')
    $iSubitem = DllStructGetData($tCustDraw, 'iSubItem')
    Local $index = __getMarked($hWndFrom, $iItem, $iSubitem)
    If $index = -1 Then
    __DrawDefault($hDC, $tCustDraw)
    Else
    __DrawItemCol($hDC, $tCustDraw, $hWndFrom, $index, $iSubitem)
    EndIf
    Return $CDRF_NEWFONT
    EndSwitch
    Case $NM_RCLICK ;== fill Global array $FORMATLV_aITEM_INDEX
    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
    Local $aInfo[9] = [True,$hWndFrom, DllStructGetData($tInfo, "Index"), DllStructGetData($tInfo, "SubItem")]
    If $aInfo[2] < 0 Then
    $aInfo[0] = False
    Return $GUI_RUNDEFMSG
    EndIf
    Local $isFormatted = __getMarked($hWndFrom, $aInfo[2], $aInfo[3]) ; always formatted?
    If $isFormatted = -1 Then
    For $i = 4 To 8
    $aInfo[$i] = -1
    Next
    Else ; read formatting values
    $aInfo[4] = $FORMATLV_aIPARAM[$aInfo[2]][$aInfo[3]+1][0]
    $aInfo[5] = $FORMATLV_aIPARAM[$aInfo[2]][$aInfo[3]+1][1]
    $aInfo[6] = $FORMATLV_aIPARAM[$aInfo[2]][$aInfo[3]+1][2]
    $aInfo[7] = $FORMATLV_aIPARAM[$aInfo[2]][$aInfo[3]+1][3]
    $aInfo[8] = $FORMATLV_aIPARAM[$aInfo[2]][$aInfo[3]+1][4]
    EndIf
    $FORMATLV_aITEM_INDEX = $aInfo
    ; if desired - use this array now in main script
    EndSwitch
    EndIf
    Next
    ; call default WinProcedure, which can be analyzed in main script with GuiRegisterMsg
    Return _WinAPI_CallWindowProc($FORMATLV_hHOOK, $hWnd, $Msg, $wParam, $lParam)
    EndFunc ;==>_WinProc

    [/autoit] [autoit][/autoit] [autoit]

    Func __GUICtrlListView_SimpleSort($hWnd, ByRef $vDescending, $iCol) ; modified to sort also IParam
    Local $x, $Y, $Z, $b_desc, $columns, $items, $v_item, $temp_item, $iFocused = -1
    Local $SeparatorChar = Opt('GUIDataSeparatorChar')
    If _GUICtrlListView_GetItemCount($hWnd) Then
    If (IsArray($vDescending)) Then
    $b_desc = $vDescending[$iCol]
    Else
    $b_desc = $vDescending
    EndIf
    $columns = _GUICtrlListView_GetColumnCount($hWnd)
    $items = _GUICtrlListView_GetItemCount($hWnd)
    For $x = 1 To $columns
    $temp_item = $temp_item & " " & $SeparatorChar
    Next
    $temp_item = StringTrimRight($temp_item, 1)
    Local $a_lv[$items][$columns + 2], $i_selected ; add column for IParam ### MODIFIED ###

    [/autoit] [autoit][/autoit] [autoit]

    $i_selected = StringSplit(_GUICtrlListView_GetSelectedIndices($hWnd), $SeparatorChar)
    For $x = 0 To UBound($a_lv) - 1 Step 1
    If $iFocused = -1 Then
    If _GUICtrlListView_GetItemFocused($hWnd, $x) Then $iFocused = $x
    EndIf
    _GUICtrlListView_SetItemSelected($hWnd, $x, False)
    For $Y = 0 To UBound($a_lv, 2) - 3 Step 1 ; ### MODIFIED ###
    $v_item = StringStripWS(_GUICtrlListView_GetItemText($hWnd, $x, $Y), 2)
    If (StringIsFloat($v_item) Or StringIsInt($v_item)) Then
    $a_lv[$x][$Y] = Number($v_item)
    Else
    $a_lv[$x][$Y] = $v_item
    EndIf
    Next
    $a_lv[$x][$Y] = $x
    $a_lv[$x][$Y+1] = _GUICtrlListView_GetItemParam($hWnd, $x) ; ### NEW ###
    Next
    _ArraySort($a_lv, $b_desc, 0, 0, $iCol)
    For $x = 0 To UBound($a_lv) - 1 Step 1
    For $Y = 0 To UBound($a_lv, 2) - 3 Step 1 ; ### MODIFIED ###
    _GUICtrlListView_SetItemText($hWnd, $x, $a_lv[$x][$Y], $Y)
    Next
    _GUICtrlListView_SetItemParam($hWnd, $x, $a_lv[$x][$Y+1]) ; ### NEW ###
    For $Z = 1 To $i_selected[0]
    If $a_lv[$x][UBound($a_lv, 2) - 2] = $i_selected[$Z] Then ; ### MODIFIED ###
    If $a_lv[$x][UBound($a_lv, 2) - 2] = $iFocused Then ; ### MODIFIED ###
    _GUICtrlListView_SetItemSelected($hWnd, $x, True, True)
    Else
    _GUICtrlListView_SetItemSelected($hWnd, $x, True)
    EndIf
    ExitLoop
    EndIf
    Next
    Next
    If (IsArray($vDescending)) Then
    $vDescending[$iCol] = Not $b_desc
    Else
    $vDescending = Not $b_desc
    EndIf
    EndIf
    EndFunc ;==>__GUICtrlListView_SimpleSort

    [/autoit]
    Example_LV_Format v 1.1
    [autoit]

    #Region - TimeStamp
    ; 2011-08-08 15:19:57 v 1.1
    #EndRegion - TimeStamp

    [/autoit] [autoit][/autoit] [autoit]

    #cs
    Initialize Global vars at startup
    _GUICtrlListView_Formatting_Startup($hGUI, $hListView)
    $hGUI Handle of your GUI
    $hListView Listview handle, for several LV commit handle's as array

    [/autoit] [autoit][/autoit] [autoit]

    [ Clean up ressources ==> Changed! ==> now automatically called on AutoIt exit ]
    _GUICtrlListView_Formatting_Shutdown()

    [/autoit] [autoit][/autoit] [autoit]

    Add or insert new Listview Item:
    _GUICtrlListView_AddOrIns_Item($hWnd, $sText, $iItem=-1)
    $hWnd Listview handle
    $sText lonely string to set only Item text (than SubItem must set with _GUICtrlListView_AddSubItem)
    or
    "Item|SubItem|SubItem.." to set all text at once
    $iItem Item index, if -1 a new Item will add at the end (default)
    otherwise
    the Item will insert at index position

    [/autoit] [autoit][/autoit] [autoit]

    Delete one, selected or all Item:
    _GUICtrlListView_FormattedDeleteItem($hWnd, $iIndex)
    _GUICtrlListView_FormattedDeleteItemsSelected($hWnd)
    _GUICtrlListView_FormattedDeleteAllItems($hWnd)

    [/autoit] [autoit][/autoit] [autoit]

    Set defaults
    _GUICtrlListView_DefaultsSet($iBkCol=0xFFFFFF, $iCol=0x000000, $iSize=14, $iWeight=400, $sFont='Arial')
    $iBkCol back color default white
    $iCol text color default black
    $iSize font size default 14
    $iWeight font weight default 400
    $sFont font name default Arial

    [/autoit] [autoit][/autoit] [autoit]

    Format Listview Item
    _GUICtrlListView_FormattingCell($hWnd, $iItem, $iSubItem, $iBkCol=-1, $iCol=-1, $iSize=-1, $iWeight=-1, $sFont=-1)
    $hWnd Listview handle
    $iItem Item index
    $iSubItem SubItem index
    $iBkCol back color (-1 = default BkCol)
    $iCol text color (-1 = default txtCol)
    $iSize height of font (-1 = 14)
    $iWeight font weight (-1 = 400)
    $sFont typefont name (-1 = Arial)

    [/autoit] [autoit][/autoit] [autoit]

    #ce

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; == Variable: $FORMATLV_aITEM_INDEX
    ; == created as Global array variable inside include, filled with values in WM_NOTIFY() by right click [state formatting:TrueFalse, $hWndFrom, "Index", "SubItem", $iBkCol, $iCol, $iSize, $iWeight, $sFont]
    ; == how to use see Func _RightClick()

    [/autoit] [autoit][/autoit] [autoit]

    #include <GuiListView.au3>
    #include <EditConstants.au3>
    #include 'LV_Format_include.au3'

    [/autoit] [autoit][/autoit] [autoit]

    Local $col = ''
    For $i = 1 To 6
    $col &= $i & '|'
    Next

    [/autoit] [autoit][/autoit] [autoit]

    ; Main GUI
    $GUI = GUICreate('')
    $lv = GUICtrlCreateListView(StringTrimRight($col,1), 10, 10, 300, 150)
    $hLV = GUICtrlGetHandle($lv)
    For $i = 0 To 5
    _GUICtrlListView_SetColumnWidth($hLV, $i, 49)
    Next
    $col = StringTrimRight($col, 2)
    $lv2 = GUICtrlCreateListView(StringTrimRight($col,1), 10, 180, 300, 150)
    $hLV2 = GUICtrlGetHandle($lv2)
    For $i = 0 To 4
    _GUICtrlListView_SetColumnWidth($hLV2, $i, 59)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    ; initialize Global vars
    ; for more than one Listview commit Listview handle as array
    Local $aHWnd[2] = [$hLV,$hLV2]
    _GUICtrlListView_Formatting_Startup($GUI, $aHWnd)
    ;~ _GUICtrlListView_Formatting_Startup($GUI, $hLV)

    [/autoit] [autoit][/autoit] [autoit]

    ; 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')
    ; set format
    _GUICtrlListView_FormattingCell($hLV, 0, 2, 0xff0000, -1, -1, 600, 'Times New Roman')
    _GUICtrlListView_FormattingCell($hLV, 1, 3, 0xff0000, -1, -1, 400, 'Times New Roman')
    _GUICtrlListView_FormattingCell($hLV, 1, 4, 0xffff00, -1, -1, 600, 'Comic Sans MS')

    [/autoit] [autoit][/autoit] [autoit]

    ; add new Items from array
    Local $aInsert[5] = [ _
    'Test0|Test1|Test2|Test3|Test4', _
    'Blub0|Blub1|Blub2|Blub3|Blub4', _
    'Club0|Club1|Club2|Club3|Club4', _
    'Blab0|Blab1|Blab2|Blab3|Blab4', _
    'Bumm0|Bumm1|Bumm2|Bumm3|Bumm4']
    _GUICtrlListView_AddOrIns_Item($hLV2, $aInsert)
    ;~ ; set format
    _GUICtrlListView_FormattingCell($hLV2, 0, 2, 0xff0000, -1, -1, 600, 'Times New Roman')
    _GUICtrlListView_FormattingCell($hLV2, 1, 4, 0xffff00, -1, -1, 600, 'Comic Sans MS')
    _GUICtrlListView_FormattingCell($hLV2, 1, 3, 0xff0000, -1, -1, 400, 'Times New Roman')

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState(@SW_SHOW, $GUI)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; GUI formatting
    GUICtrlCreateLabel('With right click on single SubItem' & @LF & 'will formatting GUI load', 10, 350, 300, 40)
    $GUI_Format = GUICreate('set formatting', 200, 180)
    GUICtrlCreateLabel(' Control | Index row | column', 10, 10, 180, 17)
    $ctrl = GUICtrlCreateInput('', 10, 30, 85, 20, $ES_READONLY)
    $zeile = GUICtrlCreateInput('', 100, 30, 30, 20, BitOR($ES_READONLY,$ES_RIGHT))
    $spalte = GUICtrlCreateInput('', 135, 30, 30, 20, BitOR($ES_READONLY,$ES_RIGHT))
    GUICtrlCreateLabel(' BkColor | TextColor | Size', 10, 70, 180, 17)
    $inBkCol = GUICtrlCreateInput('-1', 10, 90, 55, 20, $ES_RIGHT)
    $inTxtCol = GUICtrlCreateInput('-1', 75, 90, 55, 20, $ES_RIGHT)
    $inSize = GUICtrlCreateInput('-1', 140, 90, 50, 20, $ES_RIGHT)
    GUICtrlCreateLabel(' Weight | Font', 10, 130, 150, 17)
    $inWeight = GUICtrlCreateInput('-1', 10, 150, 50, 20, $ES_RIGHT)
    $inFont = GUICtrlCreateInput('-1', 75, 150, 115, 20, $ES_RIGHT)

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    [/autoit] [autoit][/autoit] [autoit]

    ;~ $timer = TimerInit()
    While 1
    ;~ If TimerDiff($timer) >= 3000 Then
    ;~ ControlMove($GUI, '', $lv, 10, 10, 300+40, 150)
    ;~ _GUICtrlListView_AddOrIns_Column($hLV, -1, 'NEU', 40)
    ;~ EndIf
    $msg = GUIGetMsg(1)
    Switch $msg[1]
    Case $GUI
    If $msg[0] = -3 Then ExitLoop
    Case $GUI_Format
    If $msg[0] = -3 Then
    GUISetState(@SW_HIDE, $GUI_Format)
    _setFormat()
    EndIf
    EndSwitch
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _RightClick()
    If Not IsArray($FORMATLV_aITEM_INDEX) Then Return
    If Not $FORMATLV_aITEM_INDEX[0] Then Return
    $FORMATLV_aITEM_INDEX[0] = False
    GUICtrlSetData($ctrl, $FORMATLV_aITEM_INDEX[1])
    GUICtrlSetData($zeile, $FORMATLV_aITEM_INDEX[2])
    GUICtrlSetData($spalte, $FORMATLV_aITEM_INDEX[3])
    Local $bk = $FORMATLV_aITEM_INDEX[4]
    If $bk = -1 Then
    GUICtrlSetData($inBkCol, $bk)
    Else
    GUICtrlSetData($inBkCol, '0x' & Hex($bk,6))
    EndIf
    Local $tx = $FORMATLV_aITEM_INDEX[5]
    If $tx = -1 Then
    GUICtrlSetData($inTxtCol, $tx)
    Else
    GUICtrlSetData($inTxtCol, '0x' & Hex($tx,6))
    EndIf
    GUICtrlSetData($inSize, $FORMATLV_aITEM_INDEX[6])
    GUICtrlSetData($inWeight, $FORMATLV_aITEM_INDEX[7])
    GUICtrlSetData($inFont, $FORMATLV_aITEM_INDEX[8])
    GUISetState(@SW_SHOW, $GUI_Format)
    EndFunc ;==>_RightClick

    [/autoit] [autoit][/autoit] [autoit]

    Func _setFormat()
    Local $bk = GUICtrlRead($inBkCol)
    Local $tx = GUICtrlRead($inTxtCol)
    Local $sz = GUICtrlRead($inSize)
    Local $wt = GUICtrlRead($inWeight)
    Local $ft = GUICtrlRead($inFont)
    If $bk = '' Or $tx = '' Or $sz = '' Or $wt = '' Or $ft = '' Then Return
    _GUICtrlListView_FormattingCell($FORMATLV_aITEM_INDEX[1], $FORMATLV_aITEM_INDEX[2], $FORMATLV_aITEM_INDEX[3], $bk, $tx, $sz, $wt, $ft)
    EndFunc ;==>_setFormat

    [/autoit] [autoit][/autoit] [autoit]

    Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iCode, $tNMHDR
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    If ($hWndFrom = $hLV Or $hWndFrom = $hLV2) And $iCode = $NM_RCLICK Then _RightClick()
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit]
    • Offizieller Beitrag

    Im großen und ganzen funktioniert alles.Das einzige ist, das die Farbänderung beim mir erst wirksam wird ,wenn ich durch das LIstview scrolle. Kann aber nicht genau sagen ob das jetzt eventuell an Vista liegt. Habe gerade keinen anderen Rechner zum testen .

    Edit: Habe den Fehler gefunden .

    Folgenden Code :

    [autoit]

    _WinAPI_PostMessage($hListView, $LVM_UPDATE, 0, 0)

    [/autoit]


    gegen diese ersetzen :

    [autoit]

    _WinAPI_InvalidateRect($hListView)

    [/autoit]

    Hier mal der geänderte Scriptcode

    Spoiler anzeigen
    [autoit]

    #include <FontConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GuiListView.au3>
    #include <ListViewConstants.au3>
    #include <StructureConstants.au3>
    #include <WinAPI.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    #region - notwendige Deklarationen für Farbsetzung SubItem
    Global $hFont, $defColLV = 0x000000, $defBkColLV = 0xFFFFFF
    ; Font = $nHeight, $nWidth[, $nEscape = 0[, $nOrientn = 0[, $fnWeight = $FW_NORMAL[,
    ; $bItalic = False[, $bUnderline = False[, $bStrikeout = False[, $nCharset = $DEFAULT_CHARSET[,
    ; $nOutputPrec = $OUT_DEFAULT_PRECIS[, $nClipPrec = $CLIP_DEFAULT_PRECIS[, $nQuality = $DEFAULT_QUALITY[,
    ; $nPitch = 0[, $szFace = 'Arial']]]]]]]]]]]])]
    Global $aSubItemSet[1][5] = [[-1]] ; [$i][$iItem, $iSubItem, $iBkCol, $iCol, $sFont]
    #endregion

    [/autoit] [autoit][/autoit] [autoit]

    Global $setIndex, $setSubIndex

    [/autoit] [autoit][/autoit] [autoit]

    $GUI = GUICreate("Listview Custom Draw", 400, 380)
    $cListView = GUICtrlCreateListView("", 2, 2, 394, 268, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
    $hListView = GUICtrlGetHandle($cListView)
    _GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
    _GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
    _GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)
    For $i = 1 To 30
    _GUICtrlListView_AddItem($hListView, "Row" & $i & ": Col 1", $i-1)
    For $j = 1 To 2
    _GUICtrlListView_AddSubItem ($hListView, $i-1, "Row" & $i & ": Col " & $j+1, $j)
    Next
    Next
    GUICtrlCreateLabel('Item:', 2, 283, 50, 17)
    $inItem = GUICtrlCreateInput('10', 50, 280, 25, 20)
    GUICtrlCreateLabel('SubItem:', 90, 283, 45, 17)
    $inSubItem = GUICtrlCreateInput('1', 145, 280, 25, 20)
    GUICtrlCreateLabel('( 0-Index )', 185, 283, 50, 17)
    $btSet = GUICtrlCreateButton('Set', 260, 280, 50, 20)
    $btOff = GUICtrlCreateButton('Off', 340, 280, 50, 20)
    GUICtrlCreateLabel('Bk-Color', 2, 313, 40, 17)
    $inBkCol = GUICtrlCreateInput('0x3DF8FF', 50, 310, 60, 20)
    GUICtrlCreateLabel('Color', 130, 313, 40, 17)
    $inCol = GUICtrlCreateInput('0xFF0000', 170, 310, 60, 20)
    GUICtrlCreateLabel('Font', 2, 343, 40, 17)
    $inFont = GUICtrlCreateInput('14, 0, 0, 0, 700', 50, 340, 300, 20)

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    While True
    $msg = GUIGetMsg()
    Switch $msg
    Case -3
    ExitLoop
    Case $btSet
    $setIndex = GUICtrlRead($inItem)
    $setSubIndex = GUICtrlRead($inSubItem)
    If ($setIndex <> '' And $setSubIndex <> '') Then _
    _SubItemColSet($setIndex, $setSubIndex, GUICtrlRead($inBkCol), GUICtrlRead($inCol), GUICtrlRead($inFont))
    Case $btOff
    $setIndex = GUICtrlRead($inItem)
    $setSubIndex = GUICtrlRead($inSubItem)
    If ($setIndex <> '' And $setSubIndex <> '') Then _
    _SubItemColOff($setIndex, $setSubIndex)
    EndSwitch
    WEnd
    _WinAPI_DeleteObject($hFont)
    Exit

    [/autoit] [autoit][/autoit] [autoit]

    #region - Funktionen für Farbsetzung SubItem
    Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
    Case $hListView
    Switch $iCode
    Case $NM_CUSTOMDRAW
    If Not _GUICtrlListView_GetViewDetails($hWndFrom) Then Return $GUI_RUNDEFMSG
    Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
    Local $iDrawStage, $iItem, $iSubitem, $hDC, $tRect
    $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage')
    Switch $iDrawStage
    Case $CDDS_ITEMPREPAINT
    Return $CDRF_NOTIFYSUBITEMDRAW
    Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
    $iItem = DllStructGetData($tCustDraw, 'dwItemSpec')
    $iSubitem = DllStructGetData($tCustDraw, 'iSubItem')
    _SetItemCol($hDC, $tCustDraw, $iItem, $iSubitem)
    Return $CDRF_NEWFONT
    EndSwitch
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit] [autoit][/autoit] [autoit]

    Func _SetItemCol(ByRef $hDC, ByRef $tCustDraw, $iItem, $iSubitem)
    If $aSubItemSet[0][0] = -1 Then Return
    Local $indx, $aIndex = _ArrayFindAll($aSubItemSet, $iItem)
    If @error Then Return
    For $i = 0 To UBound($aIndex) -1
    If $aSubItemSet[$aIndex[$i]][1] = $iSubitem Then
    $indx = $aIndex[$i]
    ExitLoop
    EndIf
    Next
    Local $aDefFont[14] = [14,0,0,0,$FW_NORMAL,False,False,False, _
    $DEFAULT_CHARSET,$OUT_DEFAULT_PRECIS,$CLIP_DEFAULT_PRECIS,$DEFAULT_QUALITY,0,'Arial']
    Local $splitFont = StringSplit($aSubItemSet[$indx][4], ',')
    For $i = 1 To UBound($splitFont) -1
    $aDefFont[$i-1] = $splitFont[$i]
    Next
    If ($aSubItemSet[$indx][0] = $iItem) And ($aSubItemSet[$indx][1] = $iSubitem) Then
    $hDC = DllStructGetData($tCustDraw, 'hdc')
    DllStructSetData($tCustDraw, 'clrText', RGB2BGR($aSubItemSet[$indx][3]))
    DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($aSubItemSet[$indx][2]))
    $hFont = _WinAPI_CreateFont($aDefFont[0],$aDefFont[1],$aDefFont[2],$aDefFont[3],$aDefFont[4],$aDefFont[5],$aDefFont[6], _
    $aDefFont[7],$aDefFont[8],$aDefFont[9],$aDefFont[10],$aDefFont[11],$aDefFont[12],$aDefFont[13])
    _WinAPI_SelectObject($hDC, $hFont)
    Else
    $hDC = DllStructGetData($tCustDraw, 'hdc')
    DllStructSetData($tCustDraw, 'clrText', RGB2BGR($defColLV))
    DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($defBkColLV))
    $hFont = _WinAPI_CreateFont(14,0,0,0,$FW_NORMAL,False,False,False,$DEFAULT_CHARSET,$OUT_DEFAULT_PRECIS, _
    $CLIP_DEFAULT_PRECIS,$DEFAULT_QUALITY,0,'Arial')
    _WinAPI_SelectObject($hDC, $hFont)
    EndIf
    EndFunc ;==>_SetItemCol

    [/autoit] [autoit][/autoit] [autoit]

    Func RGB2BGR($iColor)
    Local $sH = Hex($iColor,6)
    Return '0x' & StringRight($sH, 2) & StringMid($sH,3,2) & StringLeft($sH, 2)
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func _SubItemColSet($iItem, $iSubItem, $iBkCol, $iCol, $sFont)
    If $aSubItemSet[0][0] <> -1 Then ReDim $aSubItemSet[UBound($aSubItemSet)+1][5]
    $aSubItemSet[UBound($aSubItemSet)-1][0] = $iItem
    $aSubItemSet[UBound($aSubItemSet)-1][1] = $iSubItem
    $aSubItemSet[UBound($aSubItemSet)-1][2] = $iBkCol
    $aSubItemSet[UBound($aSubItemSet)-1][3] = $iCol
    $aSubItemSet[UBound($aSubItemSet)-1][4] = $sFont
    _WinAPI_InvalidateRect($hListView)
    EndFunc ;==>_SubItemColSet

    [/autoit] [autoit][/autoit] [autoit]

    Func _SubItemColOff($iItem, $iSubItem)
    Local $indx, $aIndex = _ArrayFindAll($aSubItemSet, $iItem)
    If @error Then Return
    For $i = 0 To UBound($aIndex) -1
    If $aSubItemSet[$aIndex[$i]][1] = $iSubitem Then
    $indx = $aIndex[$i]
    ExitLoop
    EndIf
    Next
    If UBound($aSubItemSet) > 1 Then
    _ArrayDelete($aSubItemSet, $indx)
    Else
    $aSubItemSet[0][0] = -1
    $aSubItemSet[0][1] = 0
    $aSubItemSet[0][2] = 0
    $aSubItemSet[0][3] = 0
    $aSubItemSet[0][4] = 0
    EndIf
    _WinAPI_InvalidateRect($hListView)
    EndFunc ;==>_SubItemColOff
    #endregion

    [/autoit]


    Kannst ja mal schauen ob das ganze für WinXp auch gilt. Sonst wie immer 1A Arbeit :thumbup::thumbup:

    • Offizieller Beitrag

    Danke Raupi für den Tipp. Werde die Änderung einfügen, dann ist es universell.
    Ich werde sowieso noch versuchen, die Parametereingabe für den Font zu vereinfachen. Dieser 14-Parameter String, von dem man auch alle setzen muß, wenn man eine andere Schriftart wählen will, da diese blöderweise der letzte Parameter ist, ist mir etwas zu stressig.
    Ich habe auch festgestellt, dass die Parameter für italic, strike, underlined ohne Wirkung bleiben. Und die anderen Parameter (precision etc.) verwendet doch wohl auch niemand. Am Besten, ich lasse diesen Format-String und einen kürzeren Alternativ-String zu. Ich probier mal. Das Ergebnis poste ich dann.

  • Hallo BugFix,

    nette Funktionen, aber irgendwie stimmt da was nicht mit deinen Dateien.

    Du schreibst, daß die aktuellste Version in der Datei "FormatSubItemLV_new.au3" zu finden ist. Die ist aber viel kleiner als "FormatSubItemLVex.au3" (10 anstatt 18kb).
    Obendrein ist nichts kommentiert und es fehlen Funktionen, wie z.B. _OneRowSetCol.

    Ist das Absicht, oder Versehen?

    Besten Dank im voraus und weiterhin happy computing!
    R@iner

    • Offizieller Beitrag

    Du schreibst, daß die aktuellste Version in der Datei "FormatSubItemLV_new.au3" zu finden ist. Die ist aber viel kleiner als "FormatSubItemLVex.au3" (10 anstatt 18kb).
    Obendrein ist nichts kommentiert und es fehlen Funktionen, wie z.B. _OneRowSetCol.

    Ja klar ist die neueste Version viel kleiner, habe ich doch auch geschrieben:

    Zitat

    Code ist kürzer und schneller. s. Post 1, Bsp.: FormatSubItemLV_new.au3


    Mit der Funktion:
    _SetItemParam($hWnd, $iItem, $iSubItem, $iBkCol=-1, $iCol=-1, $iSize=-1, $iWeight=-1, $sFont=-1)
    kannst du alle notwendigen Einstellungen vornehmen, also Einzelzelle, Zeile oder Spalte formatieren. Mußt sie halt notwendigerweise in einer Schleife mehrfach ausführen.

  • Hallo BugFix,

    das hab ich alles gelesen, trotzdem hat es mich gewundert, das die letzte Version abgespeckt und vor allem ohne Kommentare war. Egal.

    Ich hab Dein Script jetzt mal als Basis genommen um zu verstehen, wie das colorieren funktioniert. So richtig verstanden habe ich es nicht, aber den Aufruf von _SetItemParam hab ich verstanden. :)

    Mein eigentliches Ziel ist es, in meiner Tabelle (ca. 70 Zeilen, 15 Spalten), jede zweite Reihe farbig mit einer Farbe zu versehen. Font ist mir derzeit nicht wichtig.

    Ich hab jetzt mal dein Script genommen und es etwas erweitert, allerdings ist das Scrollen der Listen, egal ob horizontal oder vertikal, sehr träge.
    Deaktiviere ich den WM_NOTIFY, werden die Felder logischerweise nicht mehr farbig gemacht, aber der Geschwindigkeitsunterschied ist schon sehr deutlich.
    Gut, mein Rechner ist alt, aber vielleicht haste noch ne Idee, wo man was noch schneller machen könnte.

    Hier mein Wurf:

    Spoiler anzeigen
    [autoit]


    ; Original von User BugFix aus Thread http://www.autoit.de/index.php?page=Thread&threadID=10104

    [/autoit] [autoit][/autoit] [autoit]

    #cs Änderungen:

    - Mehr Kommentare eingefügt
    - Spalten und Zeilen starten bei 0, also auch in der Bezeichnung
    - Funktionen gruppiert (Region)
    - MustDeclareVars gesetzt
    - Anzahl Reihen und Spalten definierbar gemacht
    - Neue Funktionen: _ColorRow, _ColorColumn

    Für einen Test:
    70 Reihen, 18 Spalten
    LV1: Wahllos irgendwelche Reihe einfärben
    LV2: Jede zweite Reihe einfärben
    #ce

    [/autoit] [autoit][/autoit] [autoit]

    #include <FontConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GuiListView.au3>
    #include <ListViewConstants.au3>
    #include <StructureConstants.au3>
    #include <WinAPI.au3>
    #include <WindowsConstants.au3>
    Opt("GUIOnEventMode", 1)
    Opt("MustDeclareVars", 1)

    [/autoit] [autoit][/autoit] [autoit]

    #cs
    #Region Funktions-Definitionen

    #Region Knoepfe aus der Gui
    Func _exit() ; Programm-Exit
    Func _GetLV() ; Liefert die selektierte ListView zurück
    Func _SetInput($aRet) ; Schreibt in die Gui das selektierte Feld zurück (Reihe, Spalte)
    Func _btSet() ; Knopf "Set"
    Func _btOff() ; Knopf "Off"
    Func _btDo() ; Knopf "Do"
    #EndRegion Knoepfe aus der Gui

    #Region LV-Funktionen
    Func _ColorRow($hWnd, $row, $iBkCol = -1, $iCol = -1) ; Färbt eine Reihe. Font wird nicht berücksichtigt!
    Func _ColorColumn($hWnd, $col, $iBkCol = -1, $iCol = -1) ; Färbt eine Spalte. Font wird nicht berücksichtigt!
    Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) ; Window-Handler
    Func _SetItemParam($hWnd, $iItem, $iSubitem, $iBkCol = -1, $iCol = -1, $iSize = -1, $iWeight = -1, $sFont = -1) ; eigentliche Funktion zum Setzen
    Func _DrawItemCol(ByRef $hDC, ByRef $tCustDraw, $hWnd, $iItem, $iSubitem) ; ???
    Func _DrawDefault(ByRef $hDC, ByRef $tCustDraw) ; ???
    Func RGB2BGR($iColor)
    #EndRegion LV-Funktionen

    #Region Help-Functions
    Func dd($a, $b = "", $c = "", $d = "", $e = "", $f = "") ; Debug-Ausgabe in Console
    #EndRegion Help-Functions

    #EndRegion Funktions-Definitionen
    #ce

    [/autoit] [autoit][/autoit] [autoit]

    ; --- Spalten und Reihen ---
    Global $my_rows = 70 ; Starts with 0
    Global $my_colms = 18 ; Starts with 0
    ; Farben
    ; Global $my_rowBKColor = 0xFFFFC6 ; ganz helles Gelb
    Global $my_rowBKColor = 0xAEFFFF ; helles Blau
    Global $my_rowColor = 0x0000FF ; Blau
    ; Global $my_rowColor = 0x000000 ; Schwarz

    [/autoit] [autoit][/autoit] [autoit]

    ; Temp
    Global $Content

    [/autoit] [autoit][/autoit] [autoit]

    #Region - GUI
    ; Gui erzeugen
    Global $GUI = GUICreate("Listview Custom Draw [ You can choose element by leftclick ]", 600, 440)
    GUISetOnEvent($GUI_EVENT_CLOSE, '_exit')

    [/autoit] [autoit][/autoit] [autoit]

    ; ListView 1 erzeugen
    Global $cListView1 = GUICtrlCreateListView("", 2, 2, 290, 250, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
    Global $hListView1 = GUICtrlGetHandle($cListView1)

    [/autoit] [autoit][/autoit] [autoit]

    ; ListView 2 erzeugen
    Global $cListView2 = GUICtrlCreateListView("", 300, 2, 290, 250, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
    Global $hListView2 = GUICtrlGetHandle($cListView2)

    [/autoit] [autoit][/autoit] [autoit]

    ; Beide Tabellen "füllen"
    For $c = 0 To $my_colms
    ; Überschriften LV1 erzeugen
    _GUICtrlListView_InsertColumn($hListView1, $c, "Column " & $c, 90)
    ; Überschriften LV2 erzeugen
    _GUICtrlListView_InsertColumn($hListView2, $c, "Column " & $c, 90)

    [/autoit] [autoit][/autoit] [autoit]

    ; Zeilen "füllen"
    For $r = 0 To $my_rows
    $Content = "Row" & $r & ": Col " & $c
    If $c == 0 Then
    ; Spalte 0
    _GUICtrlListView_AddItem($hListView1, $Content, $r)
    _GUICtrlListView_AddItem($hListView2, $Content, $r)
    Else
    ; Spalte >0
    _GUICtrlListView_AddSubItem($hListView1, $r, $Content, $c)
    _GUICtrlListView_AddSubItem($hListView2, $r, $Content, $c)
    EndIf
    Next
    Next

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; Group: Settings for
    GUICtrlCreateGroup(' Settings for ', 2, 255, 590, 40)
    Global $rLV1 = GUICtrlCreateRadio('ListView 1', 130, 270, 150, 17)
    GUICtrlSetState(-1, $GUI_CHECKED)
    Global $rLV2 = GUICtrlCreateRadio('ListView 2', 430, 270, 150, 17)
    GUICtrlCreateGroup('', -99, -99, 1, 1)

    [/autoit] [autoit][/autoit] [autoit]

    ; Group: Settings
    GUICtrlCreateGroup(' Settings ', 2, 315, 290, 120)
    GUICtrlCreateLabel('Item', 32, 332, 50, 17)
    GUICtrlCreateLabel('or Row', 32, 344, 50, 17)
    Global $inItem = GUICtrlCreateInput('10', 80, 334, 25, 20)

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlCreateLabel('SubItem', 116, 332, 45, 17)
    GUICtrlCreateLabel('or Column', 116, 344, 50, 17)
    Global $inSubItem = GUICtrlCreateInput('1', 175, 334, 25, 20)
    GUICtrlCreateLabel('( 0-Index )', 215, 337, 50, 17)

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlCreateLabel('Bk-Color', 32, 366, 40, 17)
    GUICtrlCreateLabel('or odd', 32, 378, 40, 17)
    Global $inBkCol = GUICtrlCreateInput('0x3DF8FF', 80, 368, 60, 20)

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlCreateLabel('Color', 160, 366, 40, 17)
    GUICtrlCreateLabel('or even', 160, 378, 40, 17)
    Global $inCol = GUICtrlCreateInput('0xFF0000', 200, 368, 60, 20)

    [/autoit] [autoit][/autoit] [autoit]

    GUICtrlCreateLabel('Font', 32, 405, 40, 17)
    Global $inFont = GUICtrlCreateInput('14,600,Comic Sans MS', 80, 402, 180, 20)
    GUICtrlCreateGroup('', -99, -99, 1, 1)

    [/autoit] [autoit][/autoit] [autoit]

    ; Group: Single Item
    GUICtrlCreateGroup(' Single Item ', 320, 315, 90, 120)
    Global $btSet = GUICtrlCreateButton('Set', 340, 350, 50, 20)
    GUICtrlSetOnEvent(-1, '_btSet')

    [/autoit] [autoit][/autoit] [autoit]

    Global $btOff = GUICtrlCreateButton('Off', 340, 390, 50, 20)
    GUICtrlSetOnEvent(-1, '_btOff')
    GUICtrlCreateGroup('', -99, -99, 1, 1)

    [/autoit] [autoit][/autoit] [autoit]

    ; Group; Columns or rows
    GUICtrlCreateGroup(' Columns or rows ', 440, 315, 150, 120)
    ; Global $rRows = GUICtrlCreateRadio('Rows rotatory', 445, 330, 130)
    ; $rCols = GUICtrlCreateRadio('Columns rotatory', 445, 350, 130)
    Global $rOneRow = GUICtrlCreateRadio('Single Row', 445, 370, 130)
    GUICtrlSetState(-1, $GUI_CHECKED)
    Global $rOneCol = GUICtrlCreateRadio('Single Column', 445, 390, 130)
    Global $btDo = GUICtrlCreateButton('Do', 450, 412, 50, 18)
    GUICtrlSetOnEvent(-1, '_btDo')
    ; $btOff2 = GUICtrlCreateButton('Off', 530,
    GUICtrlCreateGroup('', -99, -99, 1, 1)
    #EndRegion - GUI

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    #Region - Global settings (needed, whenever you want to use formatting)
    ; create an array for every LV with same count of elements like in LV
    ; IMPORTANT:
    ; By deleting an LV-Item it's required to delete also the according item from array!
    ; Also by insert an item in LV or sort LV you must modulate the array!
    ; [Item][SubItem][0] = iBkCol
    ; [Item][SubItem][1] = iCol
    ; [Item][SubItem][2] = iSize
    ; [Item][SubItem][3] = iWeight
    ; [Item][SubItem][4] = sFont
    Global $aLV1[_GUICtrlListView_GetItemCount($hListView1)][_GUICtrlListView_GetColumnCount($hListView1)][5]
    Global $aLV2[_GUICtrlListView_GetItemCount($hListView2)][_GUICtrlListView_GetColumnCount($hListView2)][5]
    ; create array to hold ListView-handle and accordingly array
    Global $ahWndSets[2][2] = [[$hListView1, $aLV1],[$hListView2, $aLV2]]
    Global $hFont, $defColLV = 0x000000, $defBkColLV = 0xFFFFFF
    #EndRegion - Global settings (needed, whenever you want to use formatting)

    [/autoit] [autoit][/autoit] [autoit]

    ; Windows-Handler registrieren
    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    ; Fenster zeigen
    GUISetState(@SW_SHOW, $GUI)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; -- Hauptschleife --
    ; Wahllos irgendwelche Reihen einfärben - LV1
    _GUICtrlListView_BeginUpdate($hListView1) ; Refresh stoppen
    Local $max = 10
    If $max > $my_rows Then $max = $my_rows
    For $a = 1 To $max
    _ColorRow($hListView1, Random(0, $my_rows, 1), $my_rowBKColor, $my_rowColor)
    Next
    _GUICtrlListView_EndUpdate($hListView1) ; Refresh wieder erlauben

    [/autoit] [autoit][/autoit] [autoit]

    ; Jede zweite Reihe einfärben - LV2
    _GUICtrlListView_BeginUpdate($hListView2) ; Refresh stoppen
    For $a = 0 To $my_rows
    If Mod($a, 2) Then _ColorRow($hListView2, $a, $my_rowBKColor, $my_rowColor)
    Next
    _GUICtrlListView_EndUpdate($hListView2) ; Refresh wieder erlauben

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; GUIRegisterMsg($WM_NOTIFY, "") ; Zum Deaktivieren des Handlers

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While True
    Sleep(100)
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    #Region Funktions-Definitionen

    [/autoit] [autoit][/autoit] [autoit]

    #Region Knoepfe aus der Gui
    Func _exit() ; Programm-Exit
    _WinAPI_DeleteObject($hFont)
    Exit
    EndFunc ;==>_exit

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _GetLV() ; Liefert die selektierte ListView zurück
    If BitAND(GUICtrlRead($rLV1), $GUI_CHECKED) Then
    Return $hListView1
    Else
    Return $hListView2
    EndIf
    EndFunc ;==>_GetLV

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _SetInput($aRet) ; Schreibt in die Gui das selektierte Feld zurück (Reihe, Spalte)
    If $aRet[0] = $hListView1 Then
    GUICtrlSetState($rLV1, $GUI_CHECKED)
    Else
    GUICtrlSetState($rLV2, $GUI_CHECKED)
    EndIf
    GUICtrlSetData($inItem, $aRet[1])
    GUICtrlSetData($inSubItem, $aRet[2])
    EndFunc ;==>_SetInput

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _btSet() ; Knopf "Set"
    Local $setIndex = GUICtrlRead($inItem) ; Row
    Local $setSubIndex = GUICtrlRead($inSubItem) ; Column

    [/autoit] [autoit][/autoit] [autoit]

    If ($setIndex <> '' And $setSubIndex <> '') Then
    Local $aFont = StringSplit(GUICtrlRead($inFont), ',')
    _SetItemParam(_GetLV(), $setIndex, $setSubIndex, GUICtrlRead($inBkCol), GUICtrlRead($inCol), $aFont[1], $aFont[2], $aFont[3])
    EndIf
    EndFunc ;==>_btSet

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _btOff() ; Knopf "Off"
    Local $setIndex = GUICtrlRead($inItem)
    Local $setSubIndex = GUICtrlRead($inSubItem)
    If ($setIndex <> '' And $setSubIndex <> '') And BitAND(_GUICtrlListView_GetItemParam(_GetLV(), $setIndex), 2 ^ $setSubIndex) Then _
    _SetItemParam(_GetLV(), $setIndex, $setSubIndex, -1, -1, -1, -1, -1)
    EndFunc ;==>_btOff

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _btDo() ; Knopf "Do"

    [/autoit] [autoit][/autoit] [autoit]

    Local $setIndex = GUICtrlRead($inItem)
    Local $setSubIndex = GUICtrlRead($inSubItem)
    Local $SelectedLV = _GetLV()

    [/autoit] [autoit][/autoit] [autoit]

    _GUICtrlListView_BeginUpdate($SelectedLV)

    [/autoit] [autoit][/autoit] [autoit]

    ; Eine Reihe einfärben
    If BitAND(GUICtrlRead($rOneRow), $GUI_CHECKED) Then ; Single Row
    ; If ($setIndex <> '' And $setSubIndex <> '') And BitAND(_GUICtrlListView_GetItemParam($SelectedLV, $setIndex), 2 ^ $setSubIndex) Then _
    If $setIndex <> '' And $setSubIndex <> '' Then _
    _ColorRow($SelectedLV, $setIndex, GUICtrlRead($inBkCol), GUICtrlRead($inCol))

    [/autoit] [autoit][/autoit] [autoit]

    ElseIf BitAND(GUICtrlRead($rOneCol), $GUI_CHECKED) Then ; Single Column
    ; If ($setIndex <> '' And $setSubIndex <> '') And BitAND(_GUICtrlListView_GetItemParam($SelectedLV, $setIndex), 2 ^ $setSubIndex) Then _
    If $setIndex <> '' And $setSubIndex <> '' Then _
    _ColorColumn($SelectedLV, $setSubIndex, GUICtrlRead($inBkCol), GUICtrlRead($inCol))
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    _GUICtrlListView_EndUpdate($SelectedLV) ; Refresh wieder erlauben

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc ;==>_btDo
    #EndRegion Knoepfe aus der Gui

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    #Region LV-Funktionen

    [/autoit] [autoit][/autoit] [autoit]

    Func _ColorRow($hWnd, $row, $iBkCol = -1, $iCol = -1) ; Färbt eine Reihe. Font wird nicht berücksichtigt!

    [/autoit] [autoit][/autoit] [autoit]

    dd("_ColorRow", $hWnd, $row, $iBkCol, $iCol) ; Console-Ausgaben

    [/autoit] [autoit][/autoit] [autoit]

    For $c = 0 To _GUICtrlListView_GetColumnCount($hWnd) - 1
    _SetItemParam($hWnd, $row, $c, $iBkCol, $iCol, -1, -1, -1)
    Next
    EndFunc ;==>_ColorRow

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _ColorColumn($hWnd, $col, $iBkCol = -1, $iCol = -1) ; Färbt eine Spalte. Font wird nicht berücksichtigt!

    [/autoit] [autoit][/autoit] [autoit]

    dd("_ColorColumn", $hWnd, $col, $iBkCol, $iCol) ; Console-Ausgaben

    [/autoit] [autoit][/autoit] [autoit]

    For $r = 0 To _GUICtrlListView_GetItemCount($hWnd) - 1
    _SetItemParam($hWnd, $r, $col, $iBkCol, $iCol, -1, -1, -1)
    Next
    EndFunc ;==>_ColorColumn

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) ; Window-Handler
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
    Case $hListView1, $hListView2
    Switch $iCode
    Case $NM_CLICK ; only to set index to input in example
    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
    Local $aRet[3] = [$hWndFrom, DllStructGetData($tInfo, "Index"), DllStructGetData($tInfo, "SubItem")]
    Return _SetInput($aRet)
    Case $NM_CUSTOMDRAW
    If Not _GUICtrlListView_GetViewDetails($hWndFrom) Then Return $GUI_RUNDEFMSG
    Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
    Local $iDrawStage, $iItem, $iSubitem, $hDC, $tRect
    $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage')
    Switch $iDrawStage
    Case $CDDS_ITEMPREPAINT
    Return $CDRF_NOTIFYSUBITEMDRAW
    Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
    $iItem = DllStructGetData($tCustDraw, 'dwItemSpec')
    $iSubitem = DllStructGetData($tCustDraw, 'iSubItem')
    If BitAND(_GUICtrlListView_GetItemParam($hWndFrom, $iItem), 2 ^ $iSubitem) Then
    _DrawItemCol($hDC, $tCustDraw, $hWndFrom, $iItem, $iSubitem)
    Else
    _DrawDefault($hDC, $tCustDraw)
    EndIf
    Return $CDRF_NEWFONT
    EndSwitch
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; use _SetItemParam() with defaults to set off
    ; to mark an SubItem as set, 2^SubItem-index are stored in ItemParam as sum for all SubItem,
    ; so the max. count of columns are 31 !!
    Func _SetItemParam($hWnd, $iItem, $iSubitem, $iBkCol = -1, $iCol = -1, $iSize = -1, $iWeight = -1, $sFont = -1) ; eigentliche Funktion zum Setzen
    Local $accArray, $sumParam = 0
    For $i = 0 To UBound($ahWndSets) - 1
    If $ahWndSets[$i][0] = $hWnd Then
    $accArray = $ahWndSets[$i][1] ; temp array
    ExitLoop
    EndIf
    Next
    If $iBkCol = -1 Then
    $iBkCol = $defBkColLV
    $sumParam += 1
    EndIf
    If $iCol = -1 Then
    $iCol = $defColLV
    $sumParam += 1
    EndIf
    If $iSize = -1 Then
    $iSize = 14
    $sumParam += 1
    EndIf
    If $iWeight = -1 Then
    $iWeight = 400
    $sumParam += 1
    EndIf
    If $sFont = -1 Then
    $sFont = 'Arial'
    $sumParam += 1
    EndIf
    $accArray[$iItem][$iSubitem][0] = $iBkCol
    $accArray[$iItem][$iSubitem][1] = $iCol
    $accArray[$iItem][$iSubitem][2] = $iSize
    $accArray[$iItem][$iSubitem][3] = $iWeight
    $accArray[$iItem][$iSubitem][4] = $sFont
    $ahWndSets[$i][1] = $accArray ; write back to original array
    ; if SubItem not registered in IParam OR all values by -1 (delete Sub from IParam) ==> switch Sub value in IParam
    If (Not BitAND(_GUICtrlListView_GetItemParam($hWnd, $iItem), 2 ^ $iSubitem)) Or ($sumParam = 5) Then _
    _GUICtrlListView_SetItemParam($hWnd, $iItem, BitXOR(_GUICtrlListView_GetItemParam($hWnd, $iItem), 2 ^ $iSubitem))
    If BitAND(_GUICtrlListView_GetItemParam($hWnd, $iItem), 2 ^ $iSubitem) Then _WinAPI_InvalidateRect($hWnd) ; only if values changed
    EndFunc ;==>_SetItemParam

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _DrawItemCol(ByRef $hDC, ByRef $tCustDraw, $hWnd, $iItem, $iSubitem) ; ???
    Local $accArray
    For $i = 0 To UBound($ahWndSets) - 1
    If $ahWndSets[$i][0] = $hWnd Then
    $accArray = $ahWndSets[$i][1]
    ExitLoop
    EndIf
    Next
    Local $aDefFont[14] = [14, 0, 0, 0, $FW_NORMAL, False, False, False, _
    $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial']
    $aDefFont[0] = $accArray[$iItem][$iSubitem][2]
    $aDefFont[4] = $accArray[$iItem][$iSubitem][3]
    $aDefFont[13] = $accArray[$iItem][$iSubitem][4]
    $hDC = DllStructGetData($tCustDraw, 'hdc')
    DllStructSetData($tCustDraw, 'clrText', RGB2BGR($accArray[$iItem][$iSubitem][1]))
    DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($accArray[$iItem][$iSubitem][0]))
    $hFont = _WinAPI_CreateFont($aDefFont[0], $aDefFont[1], $aDefFont[2], $aDefFont[3], $aDefFont[4], $aDefFont[5], $aDefFont[6], _
    $aDefFont[7], $aDefFont[8], $aDefFont[9], $aDefFont[10], $aDefFont[11], $aDefFont[12], $aDefFont[13])
    _WinAPI_SelectObject($hDC, $hFont)
    EndFunc ;==>_DrawItemCol

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _DrawDefault(ByRef $hDC, ByRef $tCustDraw) ; ???
    $hDC = DllStructGetData($tCustDraw, 'hdc')
    DllStructSetData($tCustDraw, 'clrText', RGB2BGR($defColLV))
    DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($defBkColLV))
    $hFont = _WinAPI_CreateFont(14, 0, 0, 0, $FW_NORMAL, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, _
    $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial')
    _WinAPI_SelectObject($hDC, $hFont)
    EndFunc ;==>_DrawDefault

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func RGB2BGR($iColor)
    Local $sH = Hex($iColor, 6)
    Return '0x' & StringRight($sH, 2) & StringMid($sH, 3, 2) & StringLeft($sH, 2)
    EndFunc ;==>RGB2BGR

    [/autoit] [autoit][/autoit] [autoit]

    #EndRegion LV-Funktionen

    [/autoit] [autoit][/autoit] [autoit]

    #Region Help-Functions

    [/autoit] [autoit][/autoit] [autoit]

    Func dd($a, $b = "", $c = "", $d = "", $e = "", $f = "") ; Debug-Ausgabe in Console
    ConsoleWrite($a)
    If $b <> "" Then ConsoleWrite(", " & $b)
    If $c <> "" Then ConsoleWrite(", " & $c)
    If $d <> "" Then ConsoleWrite(", " & $d)
    If $e <> "" Then ConsoleWrite(", " & $e)
    If $f <> "" Then ConsoleWrite(", " & $f)
    ConsoleWrite(@CRLF)
    EndFunc ;==>dd

    [/autoit] [autoit][/autoit] [autoit]

    #EndRegion Help-Functions

    [/autoit] [autoit][/autoit] [autoit]

    #EndRegion Funktions-Definitionen

    [/autoit]

    Besten Dank im voraus!
    R@iner

    • Offizieller Beitrag

    jede zweite Reihe farbig mit einer Farbe zu versehen. Font ist mir derzeit nicht wichtig.


    Also das Ziel erreichst du ohne meine Formatfunktion. Das geht schon seit geraumer Zeit standardmäßig:

    [autoit]

    #include <GuiListView.au3>
    #include <GUIConstantsEx.au3>
    GUICreate('Test')

    [/autoit][autoit][/autoit][autoit]

    $ListView1 = GUICtrlCreateListView("Spalte 1|Spalte 2", 15, 15, 300, 250)
    GUICtrlSetBkColor(-1, 0xFF4400) ; Farbe ungerade Zeilen
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE)
    _GUICtrlListView_SetColumnWidth($ListView1, 0, 148)
    _GUICtrlListView_SetColumnWidth($ListView1, 1, 148)

    [/autoit][autoit][/autoit][autoit]

    For $i = 1 To 10
    GUICtrlCreateListViewItem(Random(10000, 1000000, 1) & '|' & Random(10000, 1000000, 1), $ListView1)
    GUICtrlSetBkColor(-1, 0xFFFF23) ; Farbe gerade Zeilen
    Next

    [/autoit][autoit][/autoit][autoit]

    GUISetState()

    [/autoit][autoit][/autoit][autoit]

    Do
    Until GUIGetMsg() = -3

    [/autoit]
  • Hallo BugFix,

    danke für deine Antwort. Ich hab mich wohl etwas unglücklich ausgedrückt. Besser sollte es heissen:

    Mein eigentliches Ziel ist es, in meiner Tabelle (ca. 70 Zeilen, 15 Spalten), jede zweite Reihe farbig mit irgendeiner Farbe zu versehen. Nicht abwechselnd 2 Farben.
    Z.B. Zeile 1 in rot, Zeile 2 weiß, Zeile 3 orange, Zeile 4 weiß, Zeile 5 in grün, ....

    Und genau dafür brauche ich deinen Lösung, oder kann man das anders auch lösen?

    Happy computing!
    R@iner

    • Offizieller Beitrag

    Und genau dafür brauche ich deinen Lösung, oder kann man das anders auch lösen?


    Ja, kann man. Da ist es nicht nötig für jede Zelle die Werte zu hinterlegen. Es wird einfach der Farbwert für die Zeile in einem Array hinterlegt:

    Spoiler anzeigen
    [autoit]

    #include <FontConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GuiListView.au3>
    #include <ListViewConstants.au3>
    #include <StructureConstants.au3>
    #include <WinAPI.au3>
    #include <WindowsConstants.au3>
    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    #region - GUI
    $GUI = GUICreate("Test", 600, 440)
    GUISetOnEvent($GUI_EVENT_CLOSE, '_exit')
    $cListView1 = GUICtrlCreateListView("", 2, 2, 290, 420, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
    $hListView1 = GUICtrlGetHandle($cListView1)
    _GUICtrlListView_InsertColumn($hListView1, 0, "Column 1", 90)
    _GUICtrlListView_InsertColumn($hListView1, 1, "Column 2", 90)
    _GUICtrlListView_InsertColumn($hListView1, 2, "Column 3", 90)
    $cListView2 = GUICtrlCreateListView("", 300, 2, 290, 420, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
    $hListView2 = GUICtrlGetHandle($cListView2)
    _GUICtrlListView_InsertColumn($hListView2, 0, "Column 1", 90)
    _GUICtrlListView_InsertColumn($hListView2, 1, "Column 2", 90)
    _GUICtrlListView_InsertColumn($hListView2, 2, "Column 3", 90)
    For $i = 1 To 30
    _GUICtrlListView_AddItem($hListView1, "Row" & $i & ": Col 1", $i-1)
    _GUICtrlListView_AddItem($hListView2, "Row" & $i & ": Col 1", $i-1)
    For $j = 1 To 2
    _GUICtrlListView_AddSubItem ($hListView1, $i-1, "Row" & $i & ": Col " & $j+1, $j)
    _GUICtrlListView_AddSubItem ($hListView2, $i-1, "Row" & $i & ": Col " & $j+1, $j)
    Next
    Next
    #endregion - GUI

    [/autoit] [autoit][/autoit] [autoit]

    #region - Global settings
    Global $hFont, $defColLV = 0x000000
    ; Array mit Farben für jede Zeile:
    Global $aColor[30] = [ _
    0x0033FF,0xCCFFFF,0x3333FF,0x99FFFF,0x6633FF,0xFF99FF,0x0099FF,0xCC99FF,0x00FFFF,0xFF33FF, _
    0xFFFF00,0x003300,0x99FF00,0x663300,0xFF9900,0x009900,0xFF3300,0x669900,0x00BFFF,0xDAA520, _
    0x87CEEB,0xD2691E,0xFFDEAD,0x7B68EE,0xDEB887,0xEE82EE,0x3CB371,0xF4A460,0xADD8E6,0x00FF7F]
    #endregion - Global settings

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    GUISetState(@SW_SHOW, $GUI)

    [/autoit] [autoit][/autoit] [autoit]

    While True
    Sleep(100)
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func _exit()
    _WinAPI_DeleteObject($hFont)
    Exit
    EndFunc ;==>_exit

    [/autoit] [autoit][/autoit] [autoit]

    Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
    Case $hListView1, $hListView2
    Switch $iCode
    Case $NM_CUSTOMDRAW
    If Not _GUICtrlListView_GetViewDetails($hWndFrom) Then Return $GUI_RUNDEFMSG
    Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
    Local $iDrawStage, $iItem, $hDC
    $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage')
    Switch $iDrawStage
    Case $CDDS_ITEMPREPAINT
    Return $CDRF_NOTIFYSUBITEMDRAW
    Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
    $iItem = DllStructGetData($tCustDraw, 'dwItemSpec')
    DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($aColor[$iItem])) ; Hintergrundfarbe aus Array
    DllStructSetData($tCustDraw, 'clrText', RGB2BGR($defColLV)) ; Standardschriftfarbe
    $hFont = _WinAPI_CreateFont(14,0,0,0,$FW_NORMAL,False,False,False,$DEFAULT_CHARSET,$OUT_DEFAULT_PRECIS, _
    $CLIP_DEFAULT_PRECIS,$DEFAULT_QUALITY,0,'Arial')
    _WinAPI_SelectObject($hDC, $hFont)
    Return $CDRF_NEWFONT
    EndSwitch
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit] [autoit][/autoit] [autoit]

    Func RGB2BGR($iColor)
    Local $sH = Hex($iColor,6)
    Return '0x' & StringRight($sH, 2) & StringMid($sH,3,2) & StringLeft($sH, 2)
    EndFunc ;==>RGB2BGR

    [/autoit]
  • Hallo Bugfix,

    vielen herzlichen Dank für den neuen Code!

    Ich habe ihn mal mit mehr Reihen und Spalten versehen. Aber auf meinem 1,8 GHz P4 ist das Scrollen grausam rucklig und sehr langsam :( Speziell horizontal, also links-rechts. Von der Geschwindigkeit an meinem Notebook, P3, 648 Mhz will ich erst garnicht reden.

    Spoiler anzeigen
    [autoit]


    #include <FontConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GuiListView.au3>
    #include <ListViewConstants.au3>
    #include <StructureConstants.au3>
    #include <WinAPI.au3>
    #include <WindowsConstants.au3>
    Opt("GUIOnEventMode", 1)
    Opt("MustDeclareVars", 1)

    [/autoit] [autoit][/autoit] [autoit]

    ; --- Spalten und Reihen ---
    Global $my_rows = 90
    Global $my_colms = 18
    Global $my_colWidth=240
    Global $Content

    [/autoit] [autoit][/autoit] [autoit]

    #Region - GUI
    ; Gui erzeugen
    Global $GUI = GUICreate("Test", 600, 440)
    GUISetOnEvent($GUI_EVENT_CLOSE, '_exit')

    [/autoit] [autoit][/autoit] [autoit]

    ; ListView 1 erzeugen
    Global $cListView1 = GUICtrlCreateListView("", 2, 2, 290, 250, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
    Global $hListView1 = GUICtrlGetHandle($cListView1)

    [/autoit] [autoit][/autoit] [autoit]

    ; ListView 2 erzeugen
    Global $cListView2 = GUICtrlCreateListView("", 300, 2, 290, 250, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
    Global $hListView2 = GUICtrlGetHandle($cListView2)

    [/autoit] [autoit][/autoit] [autoit]

    ; Beide Tabellen "füllen"
    For $c = 0 To $my_colms-1
    ; Überschriften LV1 erzeugen
    _GUICtrlListView_InsertColumn($hListView1, $c, "Column " & $c, $my_colWidth)
    ; Überschriften LV2 erzeugen
    _GUICtrlListView_InsertColumn($hListView2, $c, "Column " & $c, $my_colWidth)

    [/autoit] [autoit][/autoit] [autoit]

    ; Zeilen "füllen"
    For $r = 0 To $my_rows-1
    $Content = "Row" & $r & ": Col " & $c
    If $c == 0 Then
    ; Spalte 0
    _GUICtrlListView_AddItem($hListView1, $Content, $r)
    _GUICtrlListView_AddItem($hListView2, $Content, $r)
    Else
    ; Spalte >0
    _GUICtrlListView_AddSubItem($hListView1, $r, $Content, $c)
    _GUICtrlListView_AddSubItem($hListView2, $r, $Content, $c)
    EndIf
    Next
    Next
    #EndRegion - GUI

    [/autoit] [autoit][/autoit] [autoit]

    #Region - Global settings
    Global $hFont, $defColLV = 0x000000
    ; Array mit Farben für jede Zeile:
    Global $aColor[$my_rows] = [ _
    0x0033FF, 0xCCFFFF, 0x3333FF, 0x99FFFF, 0x6633FF, 0xFF99FF, 0x0099FF, 0xCC99FF, 0x00FFFF, 0xFF33FF, _
    0xFFFF00, 0x003300, 0x99FF00, 0x663300, 0xFF9900, 0x009900, 0xFF3300, 0x669900, 0x00BFFF, 0xDAA520, _
    0x87CEEB, 0xD2691E, 0xFFDEAD, 0x7B68EE, 0xDEB887, 0xEE82EE, 0x3CB371, 0xF4A460, 0xADD8E6, 0x00FF7F, _
    0x0033FF, 0xCCFFFF, 0x3333FF, 0x99FFFF, 0x6633FF, 0xFF99FF, 0x0099FF, 0xCC99FF, 0x00FFFF, 0xFF33FF, _
    0xFFFF00, 0x003300, 0x99FF00, 0x663300, 0xFF9900, 0x009900, 0xFF3300, 0x669900, 0x00BFFF, 0xDAA520, _
    0x87CEEB, 0xD2691E, 0xFFDEAD, 0x7B68EE, 0xDEB887, 0xEE82EE, 0x3CB371, 0xF4A460, 0xADD8E6, 0x00FF7F, _
    0x0033FF, 0xCCFFFF, 0x3333FF, 0x99FFFF, 0x6633FF, 0xFF99FF, 0x0099FF, 0xCC99FF, 0x00FFFF, 0xFF33FF, _
    0xFFFF00, 0x003300, 0x99FF00, 0x663300, 0xFF9900, 0x009900, 0xFF3300, 0x669900, 0x00BFFF, 0xDAA520, _
    0x87CEEB, 0xD2691E, 0xFFDEAD, 0x7B68EE, 0xDEB887, 0xEE82EE, 0x3CB371, 0xF4A460, 0xADD8E6, 0x00FF7F _
    ]
    #EndRegion - Global settings

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
    GUISetState(@SW_SHOW, $GUI)

    [/autoit] [autoit][/autoit] [autoit]

    While True
    Sleep(100)
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; ---------- Funktions-Definitionen ----------

    [/autoit] [autoit][/autoit] [autoit]

    Func _exit()
    _WinAPI_DeleteObject($hFont)
    Exit
    EndFunc ;==>_exit

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR

    [/autoit] [autoit][/autoit] [autoit]

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    [/autoit] [autoit][/autoit] [autoit]

    Switch $hWndFrom
    Case $hListView1, $hListView2
    Switch $iCode
    Case $NM_CUSTOMDRAW
    If Not _GUICtrlListView_GetViewDetails($hWndFrom) Then Return $GUI_RUNDEFMSG
    Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
    Local $iDrawStage, $iItem, $hDC
    $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage')
    Switch $iDrawStage
    Case $CDDS_ITEMPREPAINT
    Return $CDRF_NOTIFYSUBITEMDRAW
    Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
    $iItem = DllStructGetData($tCustDraw, 'dwItemSpec')
    DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($aColor[$iItem])) ; Hintergrundfarbe aus Array
    DllStructSetData($tCustDraw, 'clrText', RGB2BGR($defColLV)) ; Standardschriftfarbe
    $hFont = _WinAPI_CreateFont(14, 0, 0, 0, $FW_NORMAL, False, False, False, $DEFAULT_CHARSET, $OUT_DEFAULT_PRECIS, _
    $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, 0, 'Arial')
    _WinAPI_SelectObject($hDC, $hFont)
    Return $CDRF_NEWFONT
    EndSwitch
    EndSwitch
    EndSwitch

    [/autoit] [autoit][/autoit] [autoit]

    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func RGB2BGR($iColor)
    Local $sH = Hex($iColor, 6)
    Return '0x' & StringRight($sH, 2) & StringMid($sH, 3, 2) & StringLeft($sH, 2)
    EndFunc ;==>RGB2BGR

    [/autoit]


    Wenn ich dagegen auf die 2 Farben-Lösung umsteigen würde, wie Du es auch oben schon mal vorgeschlagen hast, dann habe ich keine Ruckler und alles geht zügig.

    Hier mal ein Vergleich mit gleicher Anzahl an Reihen und Spalten.

    Spoiler anzeigen
    [autoit]

    #include <GuiListView.au3>
    #include <GUIConstantsEx.au3>
    GUICreate('Test')

    [/autoit] [autoit][/autoit] [autoit]

    ; 18 Spalten
    ; 90 Reihen

    [/autoit] [autoit][/autoit] [autoit]

    ; --- Spalten und Reihen ---
    Global $my_rows = 90
    Global $my_colms = 18
    Global $my_colWidth = 240
    Global $headline = "Col 0"
    Global $line

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; Headline erzeugen
    For $c = 1 To $my_colms - 1
    $headline &= "|Col " & $c
    Next
    ; ListView mit Headline erzeugen
    $ListView1 = GUICtrlCreateListView($headline, 15, 15, 300, 250)
    GUICtrlSetBkColor(-1, 0xFF4400) ; Farbe ungerade Zeilen
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE)
    ; Auf Breite einstellen
    For $c = 0 To $my_colms - 1
    _GUICtrlListView_SetColumnWidth($ListView1, $c, $my_colWidth)
    Next

    [/autoit] [autoit][/autoit] [autoit]

    ; Zeilen hinzufügen
    For $r = 0 To $my_rows - 1
    ; Zeile erzeugen
    $line = "Reihe " & $r
    For $c = 1 To $my_colms - 1
    $line &= "|" & Random(10000, 1000000, 1)
    Next
    ; Zeile hinzufügen
    GUICtrlCreateListViewItem($line, $ListView1)
    GUICtrlSetBkColor(-1, 0xFFFF23) ; Farbe gerade Zeilen
    Next

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    Do
    Until GUIGetMsg() = -3

    [/autoit]


    Ich würde schon gerne Deine Mehrfarbenlösung benutzen. Hast Du noch ne Idee, wie man das beschleunigen kann?

    Besten Dank und viele Grüße!
    R@iner

    PS. Weißt Du warum am Ende meines zweiten Beispiels unten ein Leerzeile sichtbar ist?

    • Offizieller Beitrag

    Ich würde schon gerne Deine Mehrfarbenlösung benutzen. Hast Du noch ne Idee, wie man das beschleunigen kann?

    Ich sehe hier leider kein Potential, das weiter zu beschleunigen. Das Problem liegt dadrin, dass bei jedem Zeichnen des Item die Aufrufe zum Zeichnen neu erfolgen müssen.

    PS. Weißt Du warum am Ende meines zweiten Beispiels unten ein Leerzeile sichtbar ist?

    Seltsam, wenn ich das Bsp. ausführe, ist dort keine Leerzeile. ?(

    P.S. Auf meinem lahmen Schleppi (Intel Celeron; 1,5 GHz; 448 MB RAM) läuft das recht zügig. Ja, es ruckelt - aber nicht so, dass ich Augenkrebs bekomme. :D

    Edit:
    Hatte gar nicht bedacht, dass du ja die Fontfunktionen nicht benötigst. Habe WM_NOTIFY jetzt mal etwas gekürzt. Könnte noch ein bischen Performance bringen.

    Spoiler anzeigen
    [autoit]

    Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR

    [/autoit] [autoit][/autoit] [autoit]

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    [/autoit] [autoit][/autoit] [autoit]

    Switch $hWndFrom
    Case $hListView1, $hListView2
    Switch $iCode
    Case $NM_CUSTOMDRAW
    If Not _GUICtrlListView_GetViewDetails($hWndFrom) Then Return $GUI_RUNDEFMSG
    Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
    Local $iItem
    Switch DllStructGetData($tCustDraw, 'dwDrawStage')
    Case $CDDS_ITEMPREPAINT
    Return $CDRF_NOTIFYSUBITEMDRAW
    Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
    $iItem = DllStructGetData($tCustDraw, 'dwItemSpec')
    DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($aColor[$iItem])) ; Hintergrundfarbe aus Array
    EndSwitch
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

    [/autoit]
    Zitat von skyteddy

    Ich hab Dein Script jetzt mal als Basis genommen um zu verstehen, wie das colorieren funktioniert. So richtig verstanden habe ich es nicht

    Ist gar nicht so schwer, wenn auch nicht unbedingt offensichtlich. ;)
    Passiert alles in WM_NOTIFY:
    $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
    Hier wird die Struktur $tCustDraw befüllt mit den Werten vom Pointer $lParam (für das aktuelle ListViewItem).
    Werden jetzt Werte in dieser Struktur geändert, so sind diese sofort gültig.
    Das passiert für die Hintergrundfarbe in folgendem Befehl:
    DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($aColor[$iItem]))

  • Hallo BugFix,

    danke Dir für deine Beschleunigung. Es ist schon viel besser. Ich werd das heute mal austesten und schauen, ob das flüssig genug ist.

    Mir war dann schon klar, daß die eigentliche Funktion das WM_NOTIFY ist. In dem von mir fälschlich ausgewähltem alten Beispiel von Dir gibt es aber viele Funktionen drumherum. Aber das ist ja nicht mehr notwendig :) Ich kann mir jetzt auch ungefähr zusammenreimen, was die WM_NOTIFY macht.

    Nochmal zu Deinem Beispiel zurück und meiner Leerzeile. In Deinem Original-Beispiel mit der einfachen toogle-Variante ist es bei 10 Zeilen sogar ein großer Leerbereich unten.
    Das verstehe ich ja noch, da das ListView größer ist und die 10 Zeilen den Bereich nicht einnehmen. Erhöhe ich aber die Zeilenanzahl sehe ich trotzdem einen Leerbereich. Leerzeile ist wohl wieder unglücklich ausgedrückt. Besser ist Leerbereich.

    Hier das Beispiel:

    Spoiler anzeigen
    [autoit]

    #include <GuiListView.au3>
    #include <GUIConstantsEx.au3>
    GUICreate('Test')

    [/autoit] [autoit][/autoit] [autoit]

    $ListView1 = GUICtrlCreateListView("Spalte 1|Spalte 2", 15, 15, 300, 250)
    GUICtrlSetBkColor(-1, 0xFF4400) ; Farbe ungerade Zeilen
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_LV_ALTERNATE)
    _GUICtrlListView_SetColumnWidth($ListView1, 0, 148)
    _GUICtrlListView_SetColumnWidth($ListView1, 1, 148)

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 1 To 21
    GUICtrlCreateListViewItem(Random(10000, 1000000, 1) & '|' & Random(10000, 1000000, 1), $ListView1)
    GUICtrlSetBkColor(-1, 0xFFFF23) ; Farbe gerade Zeilen
    Next

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit]

    Do
    Until GUIGetMsg() = -3

    [/autoit]


    Hier mal ein Screenshot:
    autoit.de/wcf/attachment/5414/
    Woher kommt dieser Leerbereich?

    Happy computing!
    R@iner

    • Offizieller Beitrag

    Woher kommt dieser Leerbereich?

    Sieht mir rein optisch aus wie die Hintergrundfarbe des Controls.


    Genauso ist es, die Hintergrundfarbe des Controls ist natürlich sichtbar auch wenn kein weiteres Item folgt. Solange Platz da ist, wird er auch eingefärbt.
    Besonders deutlich wird das, wenn du die Spaltenbreite verringerst. (s. Bild)
    Allerdings habe ich diesen Leerbereich nach unten nur dann, wenn es weniger Item sind, als im LV-Bereich dargestellt werden könnten. Also wenn die vertikale Scrollleiste sichtbar ist, ist bei mir dieser Effekt aufgehoben.

    autoit.de/wcf/attachment/5415/

  • Hallo Zusammen,

    ja, es scheint die Hintergrundfarbe zu sein. Wenn die die Höhe des ListViewControlls verändere, dann paßt es irgendwann.

    Eine abschließende Frage habe ich jetzt noch, bevor ich alles in meinem ursprünglichen Programm ändern muß.

    Derzeit benutze ich
    GUICtrlCreateListView
    _GUICtrlListView_InsertColumn
    _GUICtrlListView_AddItem

    Wenn ich jetzt die abwechselnden Farben benutzen will, muß ich mein Script auf
    GUICtrlCreateListViewItem
    umstellen, oder?

    Ich habe keine vergleichbaren Funktionen gefunden und in meinem Schnelltest ging das colorieren bei den oben genannten Befehlen mit
    GUICtrlSetBkColor(-1, 0xFFFF23) ; Farbe gerade Zeilen
    nicht

    Happy computing!
    R@iner