Jump to content

Recommended Posts

Posted (edited)

I have a LV with different coloured Cols:

;https://autoit.de/index.php/Thread/84279-Unterschiedliche-Textfarben-innerhalb-einer-ListView/?postID=674195#post674195
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <array.au3>
#include <ListViewConstants.au3>
#include <StructureConstants.au3>
#include <WindowsConstants.au3>

$aColBK = IniReadSection(@ScriptDir & "\lv_format.ini", "ColBKColor")
_ArrayDelete($aColBK, 0)
;_ArrayDisplay($aColBK)
$aRowBK = IniReadSection(@ScriptDir & "\lv_format.ini", "RowBKColor")
_ArrayDelete($aRowBK, 0)
;_ArrayDisplay($aColBK)
$aColText = IniReadSection(@ScriptDir & "\lv_format.ini", "ColTextColor")
_ArrayDelete($aColText, 0)
;_ArrayDisplay($aColBK)
$aRowText = IniReadSection(@ScriptDir & "\lv_format.ini", "RowTextColor")
_ArrayDelete($aRowText, 0)
;_ArrayDisplay($aRowText)

$GUI = GUICreate("Listview Farbig", 1024, 300, 0, 0) ;<==== Breite geändert
$cListView = GUICtrlCreateListView("", 2, 2, 1020, 294, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) ;<==== Breite geändert
$hListView = GUICtrlGetHandle($cListView)
For $i = 1 To 31
    _GUICtrlListView_InsertColumn($hListView, $i - 1, $i, 25)
    _GUICtrlListView_SetColumnWidth($hListView, $i - 1, 32) ;<==== eingefügt für Spaltenbreite
Next
For $i = 0 To 21 ; alle Item/SubItem erstellen
    _GUICtrlListView_AddItem($hListView, "Item: " &$i, $i)
    For $j = 1 To 30
        _GUICtrlListView_AddSubItem($hListView, $i, "Sub: "&$j, $j)
    Next
Next

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

While True
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            ExitLoop
    EndSwitch
WEnd

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
                    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)
                            ; Item/SubItem das aktuell gezeichnet werden soll ermitteln
                            $iItem = DllStructGetData($tCustDraw, 'dwItemSpec')
                            $iSubitem = DllStructGetData($tCustDraw, 'iSubItem')
                            Switch $iItem ; Zeilenwahl
                                Case -1 ;kommt nicht vor ist aber notwendig, damit case else verwendet werden kann
                                Case Else
                                    $iIndex = _ArraySearch($aRowBK, $iItem, 0, 0, 0, 0, 1, 0)
                                    If $iIndex = -1 Then ;nicht im Array für spezielle Zeilen also weiß
                                        DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR(0xFFFFFF))
                                    Else
                                        DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($aRowBK[$iIndex][1]))
                                        ;ConsoleWrite('Item '&$iItem&' BK: '&$aRowBK[$iIndex][1] & @CRLF)
                                    EndIf
                                    $iIndex = _ArraySearch($aRowText, $iItem, 0, 0, 0, 0, 1, 0)
                                    If $iIndex = -1 Then ;nicht im Array für spezielle Zeilen also schwarz
                                        DllStructSetData($tCustDraw, 'clrText', RGB2BGR(0x000000))
                                    Else
                                        DllStructSetData($tCustDraw, 'clrText', RGB2BGR($aRowText[$iIndex][1]))
                                        ;ConsoleWrite('Item '&$iItem&' Text: '&$aRowText[$iIndex][1] & @CRLF)
                                    EndIf
                            EndSwitch
                            Switch $iSubitem
                                Case -1 ;kommt nicht vor ist aber notwendig, damit case else verwendet werden kann
                                Case Else
                                    $iIndex = _ArraySearch($aColBK, $iSubitem, 0, 0, 0, 0, 1, 0)
                                    If $iIndex <> -1 Then
                                        DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($aColBK[$iIndex][1]))
                                        ;ConsoleWrite('SubItem '&$iSubitem&' BK: '&$aColBK[$iIndex][1] & @CRLF)
                                    EndIf
                                    $iIndex = _ArraySearch($aColText, $iSubitem, 0, 0, 0, 0, 1, 0)
                                    If $iIndex <> -1 Then
                                        DllStructSetData($tCustDraw, 'clrText', RGB2BGR($aColText[$iIndex][1]))
                                        ;ConsoleWrite('SubItem '&$iSubitem&' Text: '&$aColText[$iIndex][1] & @CRLF)
                                    EndIf
                            EndSwitch
                            Return $CDRF_NEWFONT
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

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

i use lv_format.ini for defining the cols Background- and Textcolour. Now i want to colour the cols in the LV-Header also, but i can't figure it out.

 

62_Listview Farbig.jpg

Edited by AutoBert
Posted

Maybe this is what you are looking for:

 

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

  • Moderators
Posted

AutoBert,

You can also do it via the WM_NOTIFY message sent when repainting:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>
#include <GuiListView.au3>

Global $iDllGDI = DllOpen("gdi32.dll")

;Three column colours
Global $aCol[3][2] = [[0xFF0000, 0xFFFF00], [0x00FF00, 0x0000FF], [0x0000FF, 0xFFCCCC]]
;Convert RBG to BGR for SetText/BkColor()
For $i = 0 To UBound($aCol) - 1
    $aCol[$i][0] = _BGR2RGB($aCol[$i][0])
    $aCol[$i][1] = _BGR2RGB($aCol[$i][1])
Next

$hGUI = GUICreate("Set Listview Header Colour ", 500, 300)

$cListView = GUICtrlCreateListView("Items List|SubItems1|SubItems2", 10, 10, 480, 280)
_GUICtrlListView_SetExtendedListViewStyle($cListView, $LVS_EX_FULLROWSELECT) ; BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))

;Get header handle
Global $hHeader = HWnd(GUICtrlSendMsg($cListView, $LVM_GETHEADER, 0, 0))
;Turn off theme for header
DllCall("uxtheme.dll", "int", "SetWindowTheme", "hwnd", $hHeader, "wstr", "", "wstr", "")

For $i = 1 To 15
    _GUICtrlListView_AddItem($cListView, "Item" & $i)
    _GUICtrlListView_AddSubItem($cListView, $i - 1, "SubItem" & $i, 1)
    _GUICtrlListView_AddSubItem($cListView, $i - 1, "SubItem" & $i, 2)
Next

_GUICtrlListView_SetColumnWidth($cListView, 0, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($cListView, 1, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($cListView, 2, $LVSCW_AUTOSIZE_USEHEADER)

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW
    Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)
    If @error Then Return

    Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF)
    Switch $iCode

        Case $NM_CUSTOMDRAW

            Local $tNMLVCUSTOMDRAW = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
            Local $dwDrawStage = DllStructGetData($tNMLVCUSTOMDRAW, "dwDrawStage")
            Switch $dwDrawStage ; Holds a value that specifies the drawing stage
                Case $CDDS_PREPAINT
                    ; Before the paint cycle begins
                    Return $CDRF_NOTIFYITEMDRAW ; Notify the parent window of any item-related drawing operations

                Case $CDDS_ITEMPREPAINT
                    Local $hDC = DllStructGetData($tNMLVCUSTOMDRAW, "hDC")
                    Local $iItem = DllStructGetData($tNMLVCUSTOMDRAW, "dwItemSpec")
                    If $iItem < 3 Then
                        DllCall($iDllGDI, "int", "SetTextColor", "handle", $hDC, "dword", $aCol[$iItem][0])
                        DllCall($iDllGDI, "int", "SetBkColor", "handle", $hDC, "dword", $aCol[$iItem][1])
                    EndIf
                    Return $CDRF_NEWFONT; $CDRF_NEWFONT must be returned after changing font or colors
                    Return $CDRF_SKIPDEFAULT

            EndSwitch

    EndSwitch

EndFunc   ;==>_WM_NOTIFY

Func _BGR2RGB($iColor)
    Return BitOR(BitShift(BitAND($iColor, 0x0000FF), -16), BitAND($iColor, 0x00FF00), BitShift(BitAND($iColor, 0xFF0000), 16))
EndFunc   ;==>_BGR2RGB

I might look at how I can incorporate that into my GUIListViewEx UDF - although it does affect the visual style of the header quite a bit.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

It works in his script only headercols are coloured, but when i implement to mine:

Spoiler
;https://autoit.de/index.php/Thread/84279-Unterschiedliche-Textfarben-innerhalb-einer-ListView/?postID=674195#post674195
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <array.au3>
#include <ListViewConstants.au3>
#include <StructureConstants.au3>
#include <WindowsConstants.au3>

Global $iDllGDI = DllOpen("gdi32.dll")

$aColBK = IniReadSection(@ScriptDir & "\lv_format.ini", "ColBKColor")
_ArrayDelete($aColBK, 0)
;_ArrayDisplay($aColBK)
$aRowBK = IniReadSection(@ScriptDir & "\lv_format.ini", "RowBKColor")
_ArrayDelete($aRowBK, 0)
;_ArrayDisplay($aColBK)
$aColText = IniReadSection(@ScriptDir & "\lv_format.ini", "ColTextColor")
_ArrayDelete($aColText, 0)
;_ArrayDisplay($aColBK)
$aRowText = IniReadSection(@ScriptDir & "\lv_format.ini", "RowTextColor")
_ArrayDelete($aRowText, 0)
;_ArrayDisplay($aRowText)

$GUI = GUICreate("Listview Farbig", 1024, 300, 0, 0) ;<==== Breite geändert
$cListView = GUICtrlCreateListView("", 2, 2, 1020, 294, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) ;<==== Breite geändert
$hListView = GUICtrlGetHandle($cListView)
For $i = 1 To 31
    _GUICtrlListView_InsertColumn($hListView, $i - 1, $i, 25)
    _GUICtrlListView_SetColumnWidth($hListView, $i - 1, 32) ;<==== eingefügt für Spaltenbreite
Next
;get handle to child SysHeader32 control of ListView
Global $hHeader = HWnd(GUICtrlSendMsg($cListView, $LVM_GETHEADER, 0, 0))
;Turn off theme for header
DllCall("uxtheme.dll", "int", "SetWindowTheme", "hwnd", $hHeader, "wstr", "", "wstr", "")
;subclass ListView to get at NM_CUSTOMDRAW notification sent to ListView
Global $wProcNew = DllCallbackRegister("_LVWndProc", "ptr", "hwnd;uint;wparam;lparam")
Global $wProcOld = _WinAPI_SetWindowLong($hListView, $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))

;Optional: Flat Header - remove header 3D button effect
Global $iStyle = _WinAPI_GetWindowLong($hHeader, $GWL_STYLE)
_WinAPI_SetWindowLong($hHeader, $GWL_STYLE, BitOR($iStyle, $HDS_FLAT))


For $i = 0 To 21 ; alle Item/SubItem erstellen
    _GUICtrlListView_AddItem($hListView, "Item: " & $i, $i)
    For $j = 1 To 30
        _GUICtrlListView_AddSubItem($hListView, $i, "Sub: " & $j, $j)
    Next
Next

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

While True
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            ExitLoop
    EndSwitch
WEnd

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 $hHeader
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
                    Switch DllStructGetData($tCustDraw, "dwDrawStage")
                        Case $CDDS_PREPAINT
                            Return $CDRF_NOTIFYITEMDRAW
                        Case $CDDS_ITEMPREPAINT
                            $hDC = DllStructGetData($tCustDraw, "hDC")
                            $iItem = DllStructGetData($tCustDraw, "dwItemSpec")
                            $iIndex = _ArraySearch($aColText, $iItem, 0, 0, 0, 0, 1, 0)
                            DllCall($iDllGDI, "int", "SetTextColor", "handle", $hDC, "dword", RGB2BGR($aColText[$iIndex][1]))
                            $iIndex = _ArraySearch($aColBK, $iItem, 0, 0, 0, 0, 1, 0)
                            DllCall($iDllGDI, "int", "SetBkColor", "handle", $hDC, "dword", RGB2BGR($aColBK[$iIndex][1]))
                            Return $CDRF_NEWFONT
                            ;Return $CDRF_SKIPDEFAULT
                    EndSwitch
            EndSwitch
        Case $hListView
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
                    Local $iDrawStage, $iItem, $iSubitem, $hDC, $tRect
                    $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage')
                    Switch $iDrawStage
                        Case $CDDS_ITEMPREPAINT
                            ;                           Return $CDRF_NOTIFYSUBITEMDRAW
                        Case $CDDS_ITEMPREPAINT
                            $hDC = DllStructGetData($tCustDraw, "hDC")
                            $iItem = DllStructGetData($tCustDraw, "dwItemSpec")
                            $iIndex = _ArraySearch($aColText, $iSubitem, 0, 0, 0, 0, 1, 0)
                            DllCall($iDllGDI, "int", "SetTextColor", "handle", $hDC, "dword", RGB2BGR($aColText[$iIndex][1]))
                            $iIndex = _ArraySearch($aColBK, $iSubitem, 0, 0, 0, 0, 1, 0)
                            DllCall($iDllGDI, "int", "SetBkColor", "handle", $hDC, "dword", RGB2BGR($aColBK[$iIndex][1]))
                            ;Return $CDRF_NEWFONT
                            ;Return $CDRF_SKIPDEFAULT
                        Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
                            ; Item/SubItem das aktuell gezeichnet werden soll ermitteln
                            $iItem = DllStructGetData($tCustDraw, 'dwItemSpec')
                            $iSubitem = DllStructGetData($tCustDraw, 'iSubItem')
                            Switch $iItem ; Zeilenwahl
                                Case -1 ;kommt nicht vor ist aber notwendig, damit case else verwendet werden kann
                                Case Else
                                    $iIndex = _ArraySearch($aRowBK, $iItem, 0, 0, 0, 0, 1, 0)
                                    If $iIndex = -1 Then ;nicht im Array für spezielle Zeilen also weiß
                                        DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR(0xFFFFFF))
                                    Else
                                        DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($aRowBK[$iIndex][1]))
                                        ;ConsoleWrite('Item '&$iItem&' BK: '&$aRowBK[$iIndex][1] & @CRLF)
                                    EndIf
                                    $iIndex = _ArraySearch($aRowText, $iItem, 0, 0, 0, 0, 1, 0)
                                    If $iIndex = -1 Then ;nicht im Array für spezielle Zeilen also schwarz
                                        DllStructSetData($tCustDraw, 'clrText', RGB2BGR(0x000000))
                                    Else
                                        DllStructSetData($tCustDraw, 'clrText', RGB2BGR($aRowText[$iIndex][1]))
                                        ;ConsoleWrite('Item '&$iItem&' Text: '&$aRowText[$iIndex][1] & @CRLF)
                                    EndIf
                            EndSwitch
                            Switch $iSubitem
                                Case -1 ;kommt nicht vor ist aber notwendig, damit case else verwendet werden kann
                                Case Else
                                    $iIndex = _ArraySearch($aColBK, $iSubitem, 0, 0, 0, 0, 1, 0)
                                    If $iIndex <> -1 Then
                                        DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($aColBK[$iIndex][1]))
                                        ;ConsoleWrite('SubItem '&$iSubitem&' BK: '&$aColBK[$iIndex][1] & @CRLF)
                                    EndIf
                                    $iIndex = _ArraySearch($aColText, $iSubitem, 0, 0, 0, 0, 1, 0)
                                    If $iIndex <> -1 Then
                                        DllStructSetData($tCustDraw, 'clrText', RGB2BGR($aColText[$iIndex][1]))
                                        ;ConsoleWrite('SubItem '&$iSubitem&' Text: '&$aColText[$iIndex][1] & @CRLF)
                                    EndIf
                            EndSwitch
                            Return $CDRF_NEWFONT
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

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

 

it fails. Nothing is drawn.

@Melba23: i will try your (seems to be identic) later.

60_Listview Farbig.jpg

  • Moderators
Posted

AutoBert,

Quote

seems to be identic

Not at all. The actual colouring calls are the same (as you would expect) but rover subclassed the header while I simply intercept the WM_NOTIFY message using GUIRegisterMsg.  In my opinion, subclassing is fraught with danger and should be avoided if at all possible - when developing my NoFocusLines UDF I learnt a lot about it and how you need to clean up carefully afterwards to prevent crashes when the script exits.

I will look to see how my code might be implemented in your script this afternoon - unless you beat me to it!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

I found souluton:

;https://autoit.de/index.php/Thread/84279-Unterschiedliche-Textfarben-innerhalb-einer-ListView/?postID=674195#post674195
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <array.au3>
#include <ListViewConstants.au3>
#include <StructureConstants.au3>
#include <WindowsConstants.au3>

Global $iDllGDI = DllOpen("gdi32.dll")

$aColBK = IniReadSection(@ScriptDir & "\lv_format.ini", "ColBKColor")
_ArrayDelete($aColBK, 0)
;_ArrayDisplay($aColBK)
$aRowBK = IniReadSection(@ScriptDir & "\lv_format.ini", "RowBKColor")
_ArrayDelete($aRowBK, 0)
;_ArrayDisplay($aColBK)
$aColText = IniReadSection(@ScriptDir & "\lv_format.ini", "ColTextColor")
_ArrayDelete($aColText, 0)
;_ArrayDisplay($aColBK)
$aRowText = IniReadSection(@ScriptDir & "\lv_format.ini", "RowTextColor")
_ArrayDelete($aRowText, 0)
;_ArrayDisplay($aRowText)

$GUI = GUICreate("Listview Farbig", 1024, 300, 0, 0) ;<==== Breite geändert
$cListView = GUICtrlCreateListView("", 2, 2, 1020, 294, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) ;<==== Breite geändert
_GUICtrlListView_SetExtendedListViewStyle($cListView, $LVS_EX_FULLROWSELECT) ; BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
$hListView = GUICtrlGetHandle($cListView)
For $i = 1 To 31
    _GUICtrlListView_InsertColumn($hListView, $i - 1, $i, 25)
    _GUICtrlListView_SetColumnWidth($hListView, $i - 1, 32) ;<==== eingefügt für Spaltenbreite
Next
;get handle to child SysHeader32 control of ListView
Global $hHeader = HWnd(GUICtrlSendMsg($cListView, $LVM_GETHEADER, 0, 0))
;Turn off theme for header
DllCall("uxtheme.dll", "int", "SetWindowTheme", "hwnd", $hHeader, "wstr", "", "wstr", "")
;subclass ListView to get at NM_CUSTOMDRAW notification sent to ListView
;Global $wProcNew = DllCallbackRegister("_LVWndProc", "ptr", "hwnd;uint;wparam;lparam")
;Global $wProcOld = _WinAPI_SetWindowLong($hListView, $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))

;Optional: Flat Header - remove header 3D button effect
Global $iStyle = _WinAPI_GetWindowLong($hHeader, $GWL_STYLE)
_WinAPI_SetWindowLong($hHeader, $GWL_STYLE, BitOR($iStyle, $HDS_FLAT))


For $i = 0 To 21 ; alle Item/SubItem erstellen
    _GUICtrlListView_AddItem($hListView, "Item: " & $i, $i)
    For $j = 1 To 30
        _GUICtrlListView_AddSubItem($hListView, $i, "Sub: " & $j, $j)
    Next
Next

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

While True
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            ExitLoop
    EndSwitch
WEnd

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 $hHeader
            ConsoleWrite('Header: ' & $iCode & @CRLF)
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
                    $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage')
                    ConsoleWrite($iDrawStage & @CRLF)
                    Switch $iDrawStage
                        Case $CDDS_PREPAINT
                            ConsoleWrite('$CDDS_PREPAINT' & @CRLF)
                            Return $CDRF_NOTIFYITEMDRAW
                        Case $CDDS_ITEMPREPAINT
                            Local $hDC = DllStructGetData($tCustDraw, "hDC")
                            Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec")
                            ConsoleWrite('Item: ' & $iItem & @CRLF)
                            $iIndex = _ArraySearch($aColText, $iItem, 0, 0, 0, 0, 1, 0)
                            If $iIndex > -1 Then
                                ConsoleWrite('Index: ' & $iIndex & @CRLF)
                                DllCall($iDllGDI, "int", "SetTextColor", "handle", $hDC, "dword", RGB2BGR($aColText[$iIndex][1]))
                            EndIf
                            $iIndex = _ArraySearch($aColBK, $iItem, 0, 0, 0, 0, 1, 0)
                            If $iIndex > -1 Then
                                ConsoleWrite('Index: ' & $iIndex & @CRLF)
                                DllCall($iDllGDI, "int", "SetBkColor", "handle", $hDC, "dword", RGB2BGR($aColBK[$iIndex][1]))
                            EndIf
                            ;Return 1
                            Return $CDRF_NEWFONT
                            Return $CDRF_SKIPDEFAULT
                    EndSwitch
            EndSwitch
        Case $hListView
            ;ConsoleWrite('Listview' & @CRLF)
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    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)
                            ; Item/SubItem das aktuell gezeichnet werden soll ermitteln
                            $iItem = DllStructGetData($tCustDraw, 'dwItemSpec')
                            $iSubitem = DllStructGetData($tCustDraw, 'iSubItem')
                            Switch $iItem ; Zeilenwahl
                                Case -1 ;kommt nicht vor ist aber notwendig, damit case else verwendet werden kann
                                Case Else
                                    $iIndex = _ArraySearch($aRowBK, $iItem, 0, 0, 0, 0, 1, 0)
                                    If $iIndex = -1 Then ;nicht im Array für spezielle Zeilen also weiß
                                        DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR(0xFFFFFF))
                                    Else
                                        DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($aRowBK[$iIndex][1]))
                                        ;ConsoleWrite('Item '&$iItem&' BK: '&$aRowBK[$iIndex][1] & @CRLF)
                                    EndIf
                                    $iIndex = _ArraySearch($aRowText, $iItem, 0, 0, 0, 0, 1, 0)
                                    If $iIndex = -1 Then ;nicht im Array für spezielle Zeilen also schwarz
                                        DllStructSetData($tCustDraw, 'clrText', RGB2BGR(0x000000))
                                    Else
                                        DllStructSetData($tCustDraw, 'clrText', RGB2BGR($aRowText[$iIndex][1]))
                                        ;ConsoleWrite('Item '&$iItem&' Text: '&$aRowText[$iIndex][1] & @CRLF)
                                    EndIf
                            EndSwitch
                            Switch $iSubitem
                                Case -1 ;kommt nicht vor ist aber notwendig, damit case else verwendet werden kann
                                Case Else
                                    $iIndex = _ArraySearch($aColBK, $iSubitem, 0, 0, 0, 0, 1, 0)
                                    If $iIndex <> -1 Then
                                        DllStructSetData($tCustDraw, 'clrTextBk', RGB2BGR($aColBK[$iIndex][1]))
                                        ;ConsoleWrite('SubItem '&$iSubitem&' BK: '&$aColBK[$iIndex][1] & @CRLF)
                                    EndIf
                                    $iIndex = _ArraySearch($aColText, $iSubitem, 0, 0, 0, 0, 1, 0)
                                    If $iIndex <> -1 Then
                                        DllStructSetData($tCustDraw, 'clrText', RGB2BGR($aColText[$iIndex][1]))
                                        ;ConsoleWrite('SubItem '&$iSubitem&' Text: '&$aColText[$iIndex][1] & @CRLF)
                                    EndIf
                            EndSwitch
                            Return $CDRF_NEWFONT
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

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

but the result is not the best:

 

64_Listview Farbig.jpg

  • Moderators
Posted

AutoBert,

Like you I can only get the text to be coloured, not the entire header section. I will continue to look around.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

  • Moderators
Posted

AutoBert,

As far as I can see you can only colour the text and its background within the header - pity.

But I would be happy to be proved wrong!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

Here is another example:

 

Styles%20fonts%20colors_zpshqabfk8w.png

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

  • Moderators
Posted

mLipok,

Thanks for that - my brain is bleeding already......

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

  • Moderators
Posted

Hi all,

Got it working within a WM_NOTIFY handler:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>
#include <GuiListView.au3>

Global Const $tagNMCUSTOMDRAW = "struct;" & $tagNMHDR & ";dword dwDrawStage;handle hdc;" & $tagRECT & _
                                ";dword_ptr dwItemSpec;uint uItemState;lparam lItemlParam;endstruct"

;                        Title    TextCol   BkCol         - colours in BGR
Global $aHdrData[][] = [["Tom",   0x000000, 0x00FFFF], _
                        ["Dick",  0x00FFFF, 0x0000FF], _
                        ["Harry", 0xFF0000, 0xFFCCCC]]


$hGUI = GUICreate("Set Listview Header Colour ", 500, 300)

$cListView = GUICtrlCreateListView(" | | ", 10, 10, 480, 280)
_GUICtrlListView_SetExtendedListViewStyle($cListView, $LVS_EX_FULLROWSELECT) ; BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))

;Get header handle
Global $hHeader = _GUICtrlListView_GetHeader($cListView)

; Get the font of the Header control (credit KaFu)
Local $hDC = _WinAPI_GetDC($hHeader)
Local $hFont = _SendMessage($hHeader, $WM_GETFONT)
Local $hObject = _WinAPI_SelectObject($hDC, $hFont)
Local $tLogFont = DllStructCreate($tagLOGFONT)

_WinAPI_GetObject($hFont, DllStructGetSize($tLogFont), DllStructGetPtr($tLogFont))
_WinAPI_SelectObject($hDC, $hObject)
_WinAPI_ReleaseDC($hHeader, $hDC)

Local $iWeight = DllStructGetData( $tLogFont, "Weight" )               ; Bold
DllStructSetData( $tLogFont, "Weight", BitOR( $iWeight, $FW_BOLD ) )
$hHdrFont = _WinAPI_CreateFontIndirect( $tLogFont )

For $i = 1 To 15
    _GUICtrlListView_AddItem($cListView, "Item" & $i)
    _GUICtrlListView_AddSubItem($cListView, $i - 1, "SubItem" & $i, 1)
    _GUICtrlListView_AddSubItem($cListView, $i - 1, "SubItem" & $i, 2)
Next

_GUICtrlListView_SetColumnWidth($cListView, 0, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($cListView, 1, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($cListView, 2, $LVSCW_AUTOSIZE_USEHEADER)

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW
    Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)
    If @error Then Return


    If DllStructGetData($tStruct, 1) = $hHeader Then
        Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF)
        Switch $iCode

            Case $NM_CUSTOMDRAW

                Local $tNMCustomDraw = DllStructCreate($tagNMCUSTOMDRAW, $lParam)
                Local $dwDrawStage = DllStructGetData($tNMCustomDraw, "dwDrawStage")
                Switch $dwDrawStage ; Holds a value that specifies the drawing stage
                    Case $CDDS_PREPAINT ; Before the paint cycle begins
                        Return $CDRF_NOTIFYITEMDRAW ; Notify parent window of any item related drawing operations

                    Case $CDDS_ITEMPREPAINT ; Before an item is drawn: Default painting (frames and background)
                        Return $CDRF_NOTIFYPOSTPAINT ; Notify parent window of any post item related drawing operations

                    Case $CDDS_ITEMPOSTPAINT ; After an item is drawn: Custom painting (item texts)
                        Local $tRECT = DllStructCreate($tagRECT)
                        Local $iIndex = DllStructGetData($tNMCustomDraw, "dwItemSpec") ; Item index
                        Local $hDC = DllStructGetData($tNMCustomDraw, "hdc") ; Device context
                        _WinAPI_SelectObject($hDC, $hHdrFont) ; Set text font
                        _WinAPI_SetBkMode($hDC, $TRANSPARENT) ; Transparent background
                        _WinAPI_SetTextColor( $hDC, $aHdrData[$iIndex][1]) ; Set text colour
                        ; Get header section size
                        DllStructSetData($tRECT, 1, DllStructGetData($tNMCustomDraw, 6) + 1)
                        DllStructSetData($tRECT, 2, DllStructGetData($tNMCustomDraw, 7) + 1)
                        DllStructSetData($tRECT, 3, DllStructGetData($tNMCustomDraw, 8) - 2)
                        DllStructSetData($tRECT, 4, DllStructGetData($tNMCustomDraw, 9) - 2)
                        ; Set and draw back colour
                        Local $hBrush = _WinAPI_CreateSolidBrush($aHdrData[$iIndex][2])
                        _WinAPI_FillRect($hDC, $tRECT, $hBrush)
                        ; Write text
                        If $iIndex < _GUICtrlListView_GetColumnCount($cListView) Then
                            _WinAPI_DrawText ( $hDC, $aHdrData[$iIndex][0], $tRECT, $DT_CENTER + $DT_VCENTER )
                        EndIf
                        Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors
                EndSwitch

        EndSwitch
    EndIf

EndFunc   ;==>_WM_NOTIFY

All credit to LarsJ for his code which I have plundered mercilessly.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

  • Moderators
Posted

Hi again,

Now I have it working in my GUIListViewEx UDF - after a bit of a struggle, I must admit. At least I now understand how the code works and does its magic.

Thanks to AutoBert for the question, water and mLipok for the links, and LarsJ for the code - how pleasant when we all work together to produce something really useful.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted (edited)

Well, why not using additionally GDI+ to pimp up the colors?

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>
#include <GuiListView.au3>
#include <GDIPlus.au3>

_GDIPlus_Startup()
Global Const $tagNMCUSTOMDRAW = "struct;" & $tagNMHDR & ";dword dwDrawStage;handle hdc;" & $tagRECT & _
                                ";dword_ptr dwItemSpec;uint uItemState;lparam lItemlParam;endstruct"

;                        Title    TextCol   BkCol         - colours in BGR
Global $aHdrData[][] = [["Tom",   0x000000, 0x00FFFF], _
                        ["Dick",  0x00FFFF, 0x0000FF], _
                        ["Harry", 0xFF0000, 0xFFCCCC]]


$hGUI = GUICreate("Set Listview Header Colour ", 500, 300)

$cListView = GUICtrlCreateListView(" | | ", 10, 10, 480, 280)
_GUICtrlListView_SetExtendedListViewStyle($cListView, $LVS_EX_FULLROWSELECT) ; BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))

;Get header handle
Global $hHeader = _GUICtrlListView_GetHeader($cListView)

; Get the font of the Header control (credit KaFu)
Local $hDC = _WinAPI_GetDC($hHeader)
Local $hFont = _SendMessage($hHeader, $WM_GETFONT)
Local $hObject = _WinAPI_SelectObject($hDC, $hFont)
Local $tLogFont = DllStructCreate($tagLOGFONT)

_WinAPI_GetObject($hFont, DllStructGetSize($tLogFont), DllStructGetPtr($tLogFont))
_WinAPI_SelectObject($hDC, $hObject)
_WinAPI_ReleaseDC($hHeader, $hDC)

Local $iWeight = DllStructGetData( $tLogFont, "Weight" )               ; Bold
DllStructSetData( $tLogFont, "Weight", BitOR( $iWeight, $FW_BOLD ) )
$hHdrFont = _WinAPI_CreateFontIndirect( $tLogFont )

For $i = 1 To 15
    _GUICtrlListView_AddItem($cListView, "Item" & $i)
    _GUICtrlListView_AddSubItem($cListView, $i - 1, "SubItem" & $i, 1)
    _GUICtrlListView_AddSubItem($cListView, $i - 1, "SubItem" & $i, 2)
Next

_GUICtrlListView_SetColumnWidth($cListView, 0, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($cListView, 1, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($cListView, 2, $LVSCW_AUTOSIZE_USEHEADER)

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_GDIPlus_Shutdown()

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW
    Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)
    If @error Then Return


    If DllStructGetData($tStruct, 1) = $hHeader Then
        Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF)
        Switch $iCode

            Case $NM_CUSTOMDRAW

                Local $tNMCustomDraw = DllStructCreate($tagNMCUSTOMDRAW, $lParam)
                Local $dwDrawStage = DllStructGetData($tNMCustomDraw, "dwDrawStage")
                Switch $dwDrawStage ; Holds a value that specifies the drawing stage
                    Case $CDDS_PREPAINT ; Before the paint cycle begins
                        Return $CDRF_NOTIFYITEMDRAW ; Notify parent window of any item related drawing operations

                    Case $CDDS_ITEMPREPAINT ; Before an item is drawn: Default painting (frames and background)
                        Return $CDRF_NOTIFYPOSTPAINT ; Notify parent window of any post item related drawing operations

                    Case $CDDS_ITEMPOSTPAINT ; After an item is drawn: Custom painting (item texts)
                        Local $tRECT = DllStructCreate($tagRECT)
                        Local $iIndex = DllStructGetData($tNMCustomDraw, "dwItemSpec") ; Item index
                        Local $hDC = DllStructGetData($tNMCustomDraw, "hdc") ; Device context
                        _WinAPI_SelectObject($hDC, $hHdrFont) ; Set text font
                        _WinAPI_SetBkMode($hDC, $TRANSPARENT) ; Transparent background
                        _WinAPI_SetTextColor( $hDC, $aHdrData[$iIndex][1]) ; Set text colour
                        ; Get header section size
                        DllStructSetData($tRECT, 1, DllStructGetData($tNMCustomDraw, 6) + 1)
                        DllStructSetData($tRECT, 2, DllStructGetData($tNMCustomDraw, 7) + 1)
                        DllStructSetData($tRECT, 3, DllStructGetData($tNMCustomDraw, 8) - 2)
                        DllStructSetData($tRECT, 4, DllStructGetData($tNMCustomDraw, 9) - 2)

                        ; Set and draw back colour
;~                         Local $hBrush = _WinAPI_CreateSolidBrush($aHdrData[$iIndex][2])
;~                         _WinAPI_FillRect($hDC, $tRECT, $hBrush)

                        Local Const $hGfx = _GDIPlus_GraphicsCreateFromHDC($hDC)
                        Local Const $hBrush = _GDIPlus_LineBrushCreate($tRECT.Left, $tRECT.Top, $tRECT.Right, $tRECT.Bottom, 0xFF000000 + $aHdrData[$iIndex][1], 0xFFFFFFFF, 1)
                        _GDIPlus_GraphicsFillRect($hGfx, $tRECT.Left, $tRECT.Top, $tRECT.Right, $tRECT.Bottom, $hBrush)
                        _GDIPlus_BrushDispose($hBrush)
                        _GDIPlus_GraphicsDispose($hGfx)

                        ; Write text
                        If $iIndex < _GUICtrlListView_GetColumnCount($cListView) Then
                            _WinAPI_DrawText ( $hDC, $aHdrData[$iIndex][0], $tRECT, $DT_CENTER + $DT_VCENTER )
                        EndIf
                        Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors
                EndSwitch

        EndSwitch
    EndIf

EndFunc   ;==>_WM_NOTIFY

 

I used a very simple color gradient but you can extend this example by using more GDI+ functions (plenty of variations)! 

Edited by UEZ
Changed the code to use the $aHdrData array for colors

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

@UEZ This is awesome modyfication.

Can you do it for LV elements ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted
Just now, mLipok said:

Can you do it for LV elements ?

I'm not sure but I would say yes. Let me check this out.

 

Btw, you can add crazy things like an animation made with GDI+ to the drawn headers...

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted
Just now, UEZ said:

Btw, you can add crazy things like an animation made with GDI+ to the drawn headers...

Example please :)

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted

The triggering of_WM_NOTIFY is not permanentely:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>
#include <GuiListView.au3>
#include <GDIPlus.au3>

_GDIPlus_Startup()
Global Const $tagNMCUSTOMDRAW = "struct;" & $tagNMHDR & ";dword dwDrawStage;handle hdc;" & $tagRECT & _
                                ";dword_ptr dwItemSpec;uint uItemState;lparam lItemlParam;endstruct"

;                        Title    TextCol   BkCol         - colours in BGR
Global $aHdrData[][] = [["Tom",   0x000000, 0x00FFFF], _
                        ["Dick",  0x00FFFF, 0x0000FF], _
                        ["Harry", 0xFF0000, 0xFFCCCC]]

$hGUI = GUICreate("Set Listview Header Colour ", 500, 300)

$cListView = GUICtrlCreateListView(" | | ", 10, 10, 480, 280)
_GUICtrlListView_SetExtendedListViewStyle($cListView, $LVS_EX_FULLROWSELECT) ; BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))

;Get header handle
Global $hHeader = _GUICtrlListView_GetHeader($cListView)

; Get the font of the Header control (credit KaFu)
Local $hDC = _WinAPI_GetDC($hHeader)
Local $hFont = _SendMessage($hHeader, $WM_GETFONT)
Local $hObject = _WinAPI_SelectObject($hDC, $hFont)
Local $tLogFont = DllStructCreate($tagLOGFONT)

_WinAPI_GetObject($hFont, DllStructGetSize($tLogFont), DllStructGetPtr($tLogFont))
_WinAPI_SelectObject($hDC, $hObject)
_WinAPI_ReleaseDC($hHeader, $hDC)

Local $iWeight = DllStructGetData( $tLogFont, "Weight" )               ; Bold
DllStructSetData( $tLogFont, "Weight", BitOR( $iWeight, $FW_BOLD ) )
$hHdrFont = _WinAPI_CreateFontIndirect( $tLogFont )

For $i = 1 To 15
    _GUICtrlListView_AddItem($cListView, "Item" & $i)
    _GUICtrlListView_AddSubItem($cListView, $i - 1, "SubItem" & $i, 1)
    _GUICtrlListView_AddSubItem($cListView, $i - 1, "SubItem" & $i, 2)
Next

_GUICtrlListView_SetColumnWidth($cListView, 0, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($cListView, 1, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($cListView, 2, $LVSCW_AUTOSIZE_USEHEADER)

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

_GDIPlus_Shutdown()

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW
    Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)
    If @error Then Return


    If DllStructGetData($tStruct, 1) = $hHeader Then
        Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF)
        Switch $iCode

            Case $NM_CUSTOMDRAW

                Local $tNMCustomDraw = DllStructCreate($tagNMCUSTOMDRAW, $lParam)
                Local $dwDrawStage = DllStructGetData($tNMCustomDraw, "dwDrawStage")
                Switch $dwDrawStage ; Holds a value that specifies the drawing stage
                    Case $CDDS_PREPAINT ; Before the paint cycle begins
                        Return $CDRF_NOTIFYITEMDRAW ; Notify parent window of any item related drawing operations

                    Case $CDDS_ITEMPREPAINT ; Before an item is drawn: Default painting (frames and background)
                        Return $CDRF_NOTIFYPOSTPAINT ; Notify parent window of any post item related drawing operations

                    Case $CDDS_ITEMPOSTPAINT ; After an item is drawn: Custom painting (item texts)
                        Local $tRECT = DllStructCreate($tagRECT)
                        Local $iIndex = DllStructGetData($tNMCustomDraw, "dwItemSpec") ; Item index
                        Local $hDC = DllStructGetData($tNMCustomDraw, "hdc") ; Device context
                        _WinAPI_SelectObject($hDC, $hHdrFont) ; Set text font
                        _WinAPI_SetBkMode($hDC, $TRANSPARENT) ; Transparent background
                        _WinAPI_SetTextColor( $hDC, $aHdrData[$iIndex][1]) ; Set text colour
                        ; Get header section size
                        DllStructSetData($tRECT, 1, DllStructGetData($tNMCustomDraw, 6) + 1)
                        DllStructSetData($tRECT, 2, DllStructGetData($tNMCustomDraw, 7) + 1)
                        DllStructSetData($tRECT, 3, DllStructGetData($tNMCustomDraw, 8) - 2)
                        DllStructSetData($tRECT, 4, DllStructGetData($tNMCustomDraw, 9) - 2)

                        ; Set and draw back colour
;~                         Local $hBrush = _WinAPI_CreateSolidBrush($aHdrData[$iIndex][2])
;~                         _WinAPI_FillRect($hDC, $tRECT, $hBrush)

                        Switch $iIndex
                            Case 2
                                Anim($hDC, $tRECT)
                            Case Else
                                Local Const $hGfx = _GDIPlus_GraphicsCreateFromHDC($hDC)
                                Local Const $hBrush = _GDIPlus_LineBrushCreate($tRECT.Left, $tRECT.Top, $tRECT.Right, $tRECT.Bottom, 0xFF000000 + $aHdrData[$iIndex][1], 0xFFFFFFFF, 1)
                                _GDIPlus_GraphicsFillRect($hGfx, $tRECT.Left, $tRECT.Top, $tRECT.Right, $tRECT.Bottom, $hBrush)
                                _GDIPlus_BrushDispose($hBrush)
                                _GDIPlus_GraphicsDispose($hGfx)
                        EndSwitch

                        ; Write text
                        If $iIndex < _GUICtrlListView_GetColumnCount($cListView) Then
                            _WinAPI_DrawText ( $hDC, $aHdrData[$iIndex][0], $tRECT, $DT_CENTER + $DT_VCENTER )
                        EndIf
                        Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors
                EndSwitch

        EndSwitch
    EndIf

EndFunc   ;==>_WM_NOTIFY

Func Anim($hDC, $tRECT)
    Local Const $hGfx = _GDIPlus_GraphicsCreateFromHDC($hDC)
    _GDIPlus_GraphicsSetSmoothingMode($hGfx, 4)
    Local Const $hBrush = _GDIPlus_BrushCreateSolid(0xFF000000), $fSize = 4
    Local Static $fX = 10, $fY = 10, $bSet = False, $fVX, $fVY
    If Not $bSet Then
        $fVX = Random(0, 1, 1) ? Random(-1.5, -0.5) : Random(0.5, 1.5)
        $fVY = Random(0, 1, 1) ? Random(-1.5, -0.5) : Random(0.5, 1.5)
        $bSet = True
    EndIf
    $fX += $fVX
    $fY += $fVY
    If BitOR($tRECT.Left + $fX <= $tRECT.Left, $tRECT.Left + $fX - $fSize - 2 >= $tRECT.Right - $fSize - 2) Then $fVX *= -1
    If BitOR($tRECT.Top + $fY <= $tRECT.Top, $tRECT.Top + $fY - $fSize - 2 >= $tRECT.Bottom - $tRECT.Top - $fSize - 2) Then $fVY *= -1
    $fX = ($fX > $tRECT.Right) ? $tRECT.Right - $fSize : $fX
    _GDIPlus_GraphicsFillEllipse($hGfx, $tRECT.Left + $fX, $tRECT.Top + $fY, $fSize, $fSize, $hBrush)
    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_GraphicsDispose($hGfx)
EndFunc

Either hover your mouse over the 3rd header or resize any column to move background dot.

 

Any idea how to trigger the animation permanentely?

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

Again very handy code.

Now I'm sure it is possible to do simple anim with rolling Up or Down Arrowhead to show reverting sort order.
btw. I do not challange you, I just give a description of example how this can be used, to describe what it might be useful.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted (edited)

Thanks to all, i will try to implement:

The solution of UEZ is amazing, but i want to build a small UDF _ArrayDisplayEX and coloring some LV-Columns (incl. LV-Headercols) is just enough.

 

Solved: here is the quick and dirty C&P and S&R solution:

;https://autoit.de/index.php/Thread/84279-Unterschiedliche-Textfarben-innerhalb-einer-ListView/?postID=674195#post674195
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <array.au3>
#include <ListViewConstants.au3>
#include <StructureConstants.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>

Global $iDllGDI = DllOpen("gdi32.dll")

$aColBK = IniReadSection(@ScriptDir & "\lv_format.ini", "ColBKColor")
_ArrayDelete($aColBK, 0)
;_ArrayDisplay($aColBK)
$aRowBK = IniReadSection(@ScriptDir & "\lv_format.ini", "RowBKColor")
_ArrayDelete($aRowBK, 0)
;_ArrayDisplay($aColBK)
$aColText = IniReadSection(@ScriptDir & "\lv_format.ini", "ColTextColor")
_ArrayDelete($aColText, 0)
;_ArrayDisplay($aColBK)
$aRowText = IniReadSection(@ScriptDir & "\lv_format.ini", "RowTextColor")
_ArrayDelete($aRowText, 0)
;_ArrayDisplay($aRowText)

$GUI = GUICreate("Listview Farbig", 1024, 300, 0, 0) ;<==== Breite geändert
$cListView = GUICtrlCreateListView("", 2, 2, 1020, 294, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) ;<==== Breite geändert
;_GUICtrlListView_SetExtendedListViewStyle($cListView, $LVS_EX_FULLROWSELECT) ; BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
$hListView = GUICtrlGetHandle($cListView)
For $i = 1 To 31
    _GUICtrlListView_InsertColumn($hListView, $i - 1, $i, 25)
    _GUICtrlListView_SetColumnWidth($hListView, $i - 1, 32) ;<==== eingefügt für Spaltenbreite
Next
;get handle to child SysHeader32 control of ListView
Global $hHeader = HWnd(GUICtrlSendMsg($cListView, $LVM_GETHEADER, 0, 0))
;Turn off theme for header
DllCall("uxtheme.dll", "int", "SetWindowTheme", "hwnd", $hHeader, "wstr", "", "wstr", "")
;subclass ListView to get at NM_CUSTOMDRAW notification sent to ListView
;Global $wProcNew = DllCallbackRegister("_LVWndProc", "ptr", "hwnd;uint;wparam;lparam")
;Global $wProcOld = _WinAPI_SetWindowLong($hListView, $GWL_WNDPROC, DllCallbackGetPtr($wProcNew))

;Optional: Flat Header - remove header 3D button effect
Global $iStyle = _WinAPI_GetWindowLong($hHeader, $GWL_STYLE)
_WinAPI_SetWindowLong($hHeader, $GWL_STYLE, BitOR($iStyle, $HDS_FLAT))

; Get the font of the Header control (credit KaFu)
Local $hDC = _WinAPI_GetDC($hHeader)
Local $hFont = _SendMessage($hHeader, $WM_GETFONT)
Local $hObject = _WinAPI_SelectObject($hDC, $hFont)
Local $tLogFont = DllStructCreate($tagLOGFONT)

_WinAPI_GetObject($hFont, DllStructGetSize($tLogFont), DllStructGetPtr($tLogFont))
_WinAPI_SelectObject($hDC, $hObject)
_WinAPI_ReleaseDC($hHeader, $hDC)

Local $iWeight = DllStructGetData($tLogFont, "Weight") ; Bold
DllStructSetData($tLogFont, "Weight", BitOR($iWeight, $FW_BOLD))
$hHdrFont = _WinAPI_CreateFontIndirect($tLogFont)


For $i = 0 To 21 ; alle Item/SubItem erstellen
    _GUICtrlListView_AddItem($hListView, "Item: " & $i, $i)
    For $j = 1 To 30
        _GUICtrlListView_AddSubItem($hListView, $i, "Sub: " & $j, $j)
    Next
Next
$iCols = _GUICtrlListView_GetColumnCount($hListView)
Global Const $tagNMCUSTOMDRAW = "struct;" & $tagNMHDR & ";dword dwDrawStage;handle hdc;" & $tagRECT & _
        ";dword_ptr dwItemSpec;uint uItemState;lparam lItemlParam;endstruct"

Global $aHdrData[$iCols][3]
For $i=0 To $iCols -1
    $aHdrData[$i][0]=_GUICtrlListView_GetColumn($hListView,$i)[5]
    $iIndex=_ArraySearch($aColText, $i, 0, 0, 0, 0, 1, 0)
    If $iIndex <>-1 Then
        $aHdrData[$i][1]=RGB2BGR($aColText[$iIndex][1])
    Else
        $aHdrData[$i][1]=0x000000
    EndIf
    $iIndex=_ArraySearch($aColBK, $i, 0, 0, 0, 0, 1, 0)
    If $iIndex <>-1 Then
        $aHdrData[$i][2]=RGB2BGR($aColBK[$iIndex][1])
    Else
        $aHdrData[$i][2]=0xFFFFFF
    EndIf
Next
#cs
    [][] = [["Tom",   0x000000, 0x00FFFF], _
    ["Dick",  0x00FFFF, 0x0000FF], _
    ["Harry", 0xFF0000, 0xFFCCCC]]
#ce
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState()

While True
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            ExitLoop
    EndSwitch
WEnd

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 $hHeader
            ;ConsoleWrite('Header: ' & $iCode & @CRLF)
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    Local $tNMCustomDraw = DllStructCreate($tagNMCUSTOMDRAW, $lParam)
                    Local $dwDrawStage = DllStructGetData($tNMCustomDraw, "dwDrawStage")
                    Switch $dwDrawStage ; Holds a value that specifies the drawing stage
                        Case $CDDS_PREPAINT ; Before the paint cycle begins
                            Return $CDRF_NOTIFYITEMDRAW ; Notify parent window of any item related drawing operations

                        Case $CDDS_ITEMPREPAINT ; Before an item is drawn: Default painting (frames and background)
                            Return $CDRF_NOTIFYPOSTPAINT ; Notify parent window of any post item related drawing operations

                        Case $CDDS_ITEMPOSTPAINT ; After an item is drawn: Custom painting (item texts)
                            Local $tRECT = DllStructCreate($tagRECT)
                            Local $iIndex = DllStructGetData($tNMCustomDraw, "dwItemSpec") ; Item index
                            Local $hDC = DllStructGetData($tNMCustomDraw, "hdc") ; Device context
                            _WinAPI_SelectObject($hDC, $hHdrFont) ; Set text font
                            _WinAPI_SetBkMode($hDC, $TRANSPARENT) ; Transparent background
                            _WinAPI_SetTextColor($hDC, $aHdrData[$iIndex][1]) ; Set text colour
                            ; Get header section size
                            DllStructSetData($tRECT, 1, DllStructGetData($tNMCustomDraw, 6) + 1)
                            DllStructSetData($tRECT, 2, DllStructGetData($tNMCustomDraw, 7) + 1)
                            DllStructSetData($tRECT, 3, DllStructGetData($tNMCustomDraw, 8) - 2)
                            DllStructSetData($tRECT, 4, DllStructGetData($tNMCustomDraw, 9) - 2)
                            ; Set and draw back colour
                            Local $hBrush = _WinAPI_CreateSolidBrush($aHdrData[$iIndex][2])
                            _WinAPI_FillRect($hDC, $tRECT, $hBrush)
                            ; Write text
                            If $iIndex < _GUICtrlListView_GetColumnCount($cListView) Then
                                _WinAPI_DrawText($hDC, $aHdrData[$iIndex][0], $tRECT, $DT_CENTER + $DT_VCENTER)
                            EndIf
                            Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors
                    EndSwitch
            EndSwitch
        Case $hListView
            ;ConsoleWrite('Listview' & @CRLF)
            Switch $iCode
                Case $NM_CUSTOMDRAW
                    Local $tNMCustomDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam)
                    Local $iDrawStage, $iItem, $iSubitem, $hDC, $tRECT
                    $iDrawStage = DllStructGetData($tNMCustomDraw, 'dwDrawStage')
                    Switch $iDrawStage
                        Case $CDDS_ITEMPREPAINT
                            Return $CDRF_NOTIFYSUBITEMDRAW
                        Case BitOR($CDDS_ITEMPREPAINT, $CDDS_SUBITEM)
                            ; Item/SubItem das aktuell gezeichnet werden soll ermitteln
                            $iItem = DllStructGetData($tNMCustomDraw, 'dwItemSpec')
                            $iSubitem = DllStructGetData($tNMCustomDraw, 'iSubItem')
                            Switch $iItem ; Zeilenwahl
                                Case -1 ;kommt nicht vor ist aber notwendig, damit case else verwendet werden kann
                                Case Else
                                    $iIndex = _ArraySearch($aRowBK, $iItem, 0, 0, 0, 0, 1, 0)
                                    If $iIndex = -1 Then ;nicht im Array für spezielle Zeilen also weiß
                                        DllStructSetData($tNMCustomDraw, 'clrTextBk', RGB2BGR(0xFFFFFF))
                                    Else
                                        DllStructSetData($tNMCustomDraw, 'clrTextBk', RGB2BGR($aRowBK[$iIndex][1]))
                                        ;ConsoleWrite('Item '&$iItem&' BK: '&$aRowBK[$iIndex][1] & @CRLF)
                                    EndIf
                                    $iIndex = _ArraySearch($aRowText, $iItem, 0, 0, 0, 0, 1, 0)
                                    If $iIndex = -1 Then ;nicht im Array für spezielle Zeilen also schwarz
                                        DllStructSetData($tNMCustomDraw, 'clrText', RGB2BGR(0x000000))
                                    Else
                                        DllStructSetData($tNMCustomDraw, 'clrText', RGB2BGR($aRowText[$iIndex][1]))
                                        ;ConsoleWrite('Item '&$iItem&' Text: '&$aRowText[$iIndex][1] & @CRLF)
                                    EndIf
                            EndSwitch
                            Switch $iSubitem
                                Case -1 ;kommt nicht vor ist aber notwendig, damit case else verwendet werden kann
                                Case Else
                                    $iIndex = _ArraySearch($aColBK, $iSubitem, 0, 0, 0, 0, 1, 0)
                                    If $iIndex <> -1 Then
                                        DllStructSetData($tNMCustomDraw, 'clrTextBk', RGB2BGR($aColBK[$iIndex][1]))
                                        ;ConsoleWrite('SubItem '&$iSubitem&' BK: '&$aColBK[$iIndex][1] & @CRLF)
                                    EndIf
                                    $iIndex = _ArraySearch($aColText, $iSubitem, 0, 0, 0, 0, 1, 0)
                                    If $iIndex <> -1 Then
                                        DllStructSetData($tNMCustomDraw, 'clrText', RGB2BGR($aColText[$iIndex][1]))
                                        ;ConsoleWrite('SubItem '&$iSubitem&' Text: '&$aColText[$iIndex][1] & @CRLF)
                                    EndIf
                            EndSwitch
                            Return $CDRF_NEWFONT
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

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

no i have to understand and to polish the code.

66_Listview Farbig.jpg

Edited by AutoBert
  • 1 year later...
Posted
On 10.5.2016 at 4:50 PM, Melba23 said:

Hi all,

Got it working within a WM_NOTIFY handler:

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <FontConstants.au3>
#include <GuiListView.au3>

Global Const $tagNMCUSTOMDRAW = "struct;" & $tagNMHDR & ";dword dwDrawStage;handle hdc;" & $tagRECT & _
                                ";dword_ptr dwItemSpec;uint uItemState;lparam lItemlParam;endstruct"

;                        Title    TextCol   BkCol         - colours in BGR
Global $aHdrData[][] = [["Tom",   0x000000, 0x00FFFF], _
                        ["Dick",  0x00FFFF, 0x0000FF], _
                        ["Harry", 0xFF0000, 0xFFCCCC]]


$hGUI = GUICreate("Set Listview Header Colour ", 500, 300)

$cListView = GUICtrlCreateListView(" | | ", 10, 10, 480, 280)
_GUICtrlListView_SetExtendedListViewStyle($cListView, $LVS_EX_FULLROWSELECT) ; BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))

;Get header handle
Global $hHeader = _GUICtrlListView_GetHeader($cListView)

; Get the font of the Header control (credit KaFu)
Local $hDC = _WinAPI_GetDC($hHeader)
Local $hFont = _SendMessage($hHeader, $WM_GETFONT)
Local $hObject = _WinAPI_SelectObject($hDC, $hFont)
Local $tLogFont = DllStructCreate($tagLOGFONT)

_WinAPI_GetObject($hFont, DllStructGetSize($tLogFont), DllStructGetPtr($tLogFont))
_WinAPI_SelectObject($hDC, $hObject)
_WinAPI_ReleaseDC($hHeader, $hDC)

Local $iWeight = DllStructGetData( $tLogFont, "Weight" )               ; Bold
DllStructSetData( $tLogFont, "Weight", BitOR( $iWeight, $FW_BOLD ) )
$hHdrFont = _WinAPI_CreateFontIndirect( $tLogFont )

For $i = 1 To 15
    _GUICtrlListView_AddItem($cListView, "Item" & $i)
    _GUICtrlListView_AddSubItem($cListView, $i - 1, "SubItem" & $i, 1)
    _GUICtrlListView_AddSubItem($cListView, $i - 1, "SubItem" & $i, 2)
Next

_GUICtrlListView_SetColumnWidth($cListView, 0, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($cListView, 1, $LVSCW_AUTOSIZE_USEHEADER)
_GUICtrlListView_SetColumnWidth($cListView, 2, $LVSCW_AUTOSIZE_USEHEADER)

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    ; Struct = $tagNMHDR and "int Item;int SubItem" from $tagNMLISTVIEW
    Local $tStruct = DllStructCreate("hwnd;uint_ptr;int_ptr;int;int", $lParam)
    If @error Then Return


    If DllStructGetData($tStruct, 1) = $hHeader Then
        Local $iCode = BitAND(DllStructGetData($tStruct, 3), 0xFFFFFFFF)
        Switch $iCode

            Case $NM_CUSTOMDRAW

                Local $tNMCustomDraw = DllStructCreate($tagNMCUSTOMDRAW, $lParam)
                Local $dwDrawStage = DllStructGetData($tNMCustomDraw, "dwDrawStage")
                Switch $dwDrawStage ; Holds a value that specifies the drawing stage
                    Case $CDDS_PREPAINT ; Before the paint cycle begins
                        Return $CDRF_NOTIFYITEMDRAW ; Notify parent window of any item related drawing operations

                    Case $CDDS_ITEMPREPAINT ; Before an item is drawn: Default painting (frames and background)
                        Return $CDRF_NOTIFYPOSTPAINT ; Notify parent window of any post item related drawing operations

                    Case $CDDS_ITEMPOSTPAINT ; After an item is drawn: Custom painting (item texts)
                        Local $tRECT = DllStructCreate($tagRECT)
                        Local $iIndex = DllStructGetData($tNMCustomDraw, "dwItemSpec") ; Item index
                        Local $hDC = DllStructGetData($tNMCustomDraw, "hdc") ; Device context
                        _WinAPI_SelectObject($hDC, $hHdrFont) ; Set text font
                        _WinAPI_SetBkMode($hDC, $TRANSPARENT) ; Transparent background
                        _WinAPI_SetTextColor( $hDC, $aHdrData[$iIndex][1]) ; Set text colour
                        ; Get header section size
                        DllStructSetData($tRECT, 1, DllStructGetData($tNMCustomDraw, 6) + 1)
                        DllStructSetData($tRECT, 2, DllStructGetData($tNMCustomDraw, 7) + 1)
                        DllStructSetData($tRECT, 3, DllStructGetData($tNMCustomDraw, 8) - 2)
                        DllStructSetData($tRECT, 4, DllStructGetData($tNMCustomDraw, 9) - 2)
                        ; Set and draw back colour
                        Local $hBrush = _WinAPI_CreateSolidBrush($aHdrData[$iIndex][2])
                        _WinAPI_FillRect($hDC, $tRECT, $hBrush)
                        ; Write text
                        If $iIndex < _GUICtrlListView_GetColumnCount($cListView) Then
                            _WinAPI_DrawText ( $hDC, $aHdrData[$iIndex][0], $tRECT, $DT_CENTER + $DT_VCENTER )
                        EndIf
                        Return $CDRF_NEWFONT ; $CDRF_NEWFONT must be returned after changing font or colors
                EndSwitch

        EndSwitch
    EndIf

EndFunc   ;==>_WM_NOTIFY

All credit to LarsJ for his code which I have plundered mercilessly.

M23

Hi Melba, do you also know a way to color the background that is behind the headers? If I resize the headers, the background of the main ListView seems to be white :(

 

LV.PNG

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
×
×
  • Create New...