[Class] LV_Colors - 1.1.05.00 (2024-03-16)

Post your working scripts, libraries and tools for AHK v1.1 and older
just me
Posts: 9541
Joined: 02 Oct 2013, 08:51
Location: Germany

[Class] LV_Colors - 1.1.05.00 (2024-03-16)

20 Dec 2013, 07:09

Primarily released on old forum: /board/topic/88699-class-lv-colors-coloured-rowscells-in-gui-listviews/.

With his last update for AHK 1.1 @lexikos ported a change from v2 which prevents scripts like Class_LV_Colors.ahk from freezing. Many thanks for this change.
Now this is my last update to Class_LV_Colors.ahk. Version 1.1.05.00 is available on GitHub.

For those who are not able to update to AHK v1.1.37.0 version 1.1.04.0 keeps available in this thread.


Change History
This is just another attempt to support individual background and/or text colours for a GUI ListView's cells or rows.

Class_LVColors.ahk (v1.1.04.01) - v1.1.05.00 is available on GitHub:

Code: Select all

; ======================================================================================================================
; Namespace:      LV_Colors
; Function:       Individual row and cell coloring for AHK ListView controls.
; Tested with:    AHK 1.1.23.05 (A32/U32/U64)
; Tested on:      Win 10 (x64)
; Changelog:
;     1.1.04.01/2016-05-03/just me - added change to remove the focus rectangle from focused rows
;     1.1.04.00/2016-05-03/just me - added SelectionColors method
;     1.1.03.00/2015-04-11/just me - bugfix for StaticMode
;     1.1.02.00/2015-04-07/just me - bugfixes for StaticMode, NoSort, and NoSizing
;     1.1.01.00/2015-03-31/just me - removed option OnMessage from __New(), restructured code
;     1.1.00.00/2015-03-27/just me - added AlternateRows and AlternateCols, revised code.
;     1.0.00.00/2015-03-23/just me - new version using new AHK 1.1.20+ features
;     0.5.00.00/2014-08-13/just me - changed 'static mode' handling
;     0.4.01.00/2013-12-30/just me - minor bug fix
;     0.4.00.00/2013-12-30/just me - added static mode
;     0.3.00.00/2013-06-15/just me - added "Critical, 100" to avoid drawing issues
;     0.2.00.00/2013-01-12/just me - bugfixes and minor changes
;     0.1.00.00/2012-10-27/just me - initial release
; ======================================================================================================================
; CLASS LV_Colors
;
; The class provides six public methods to set individual colors for rows and/or cells, to clear all colors, to
; prevent/allow sorting and rezising of columns dynamically, and to deactivate/activate the message handler for
; WM_NOTIFY messages (see below).
;
; The message handler for WM_NOTIFY messages will be activated for the specified ListView whenever a new instance is
; created. If you want to temporarily disable coloring call MyInstance.OnMessage(False). This must be done also before
; you try to destroy the instance. To enable it again, call MyInstance.OnMessage().
;
; To avoid the loss of Gui events and messages the message handler might need to be set 'critical'. This can be
; achieved by setting the instance property 'Critical' ti the required value (e.g. MyInstance.Critical := 100).
; New instances default to 'Critical, Off'. Though sometimes needed, ListViews or the whole Gui may become
; unresponsive under certain circumstances if Critical is set and the ListView has a g-label.
; ======================================================================================================================
Class LV_Colors {
   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ; META FUNCTIONS ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ; ===================================================================================================================
   ; __New()         Create a new LV_Colors instance for the given ListView
   ; Parameters:     HWND        -  ListView's HWND.
   ;                 Optional ------------------------------------------------------------------------------------------
   ;                 StaticMode  -  Static color assignment, i.e. the colors will be assigned permanently to the row
   ;                                contents rather than to the row number.
   ;                                Values:  True/False
   ;                                Default: False
   ;                 NoSort      -  Prevent sorting by click on a header item.
   ;                                Values:  True/False
   ;                                Default: True
   ;                 NoSizing    -  Prevent resizing of columns.
   ;                                Values:  True/False
   ;                                Default: True
   ; ===================================================================================================================
   __New(HWND, StaticMode := False, NoSort := True, NoSizing := True) {
      If (This.Base.Base.__Class) ; do not instantiate instances
         Return False
      If This.Attached[HWND] ; HWND is already attached
         Return False
      If !DllCall("IsWindow", "Ptr", HWND) ; invalid HWND
         Return False
      VarSetCapacity(Class, 512, 0)
      DllCall("GetClassName", "Ptr", HWND, "Str", Class, "Int", 256)
      If (Class <> "SysListView32") ; HWND doesn't belong to a ListView
         Return False
      ; ----------------------------------------------------------------------------------------------------------------
      ; Set LVS_EX_DOUBLEBUFFER (0x010000) style to avoid drawing issues.
      SendMessage, 0x1036, 0x010000, 0x010000, , % "ahk_id " . HWND ; LVM_SETEXTENDEDLISTVIEWSTYLE
      ; Get the default colors
      SendMessage, 0x1025, 0, 0, , % "ahk_id " . HWND ; LVM_GETTEXTBKCOLOR
      This.BkClr := ErrorLevel
      SendMessage, 0x1023, 0, 0, , % "ahk_id " . HWND ; LVM_GETTEXTCOLOR
      This.TxClr := ErrorLevel
      ; Get the header control
      SendMessage, 0x101F, 0, 0, , % "ahk_id " . HWND ; LVM_GETHEADER
      This.Header := ErrorLevel
      ; Set other properties
      This.HWND := HWND
      This.IsStatic := !!StaticMode
      This.AltCols := False
      This.AltRows := False
      This.NoSort(!!NoSort)
      This.NoSizing(!!NoSizing)
      This.OnMessage()
      This.Critical := "Off"
      This.Attached[HWND] := True
   }
   ; ===================================================================================================================
   __Delete() {
      This.Attached.Remove(HWND, "")
      This.OnMessage(False)
      WinSet, Redraw, , % "ahk_id " . This.HWND
   }
   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ; PUBLIC METHODS ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ; ===================================================================================================================
   ; Clear()         Clears all row and cell colors.
   ; Parameters:     AltRows     -  Reset alternate row coloring (True / False)
   ;                                Default: False
   ;                 AltCols     -  Reset alternate column coloring (True / False)
   ;                                Default: False
   ; Return Value:   Always True.
   ; ===================================================================================================================
   Clear(AltRows := False, AltCols := False) {
      If (AltCols)
         This.AltCols := False
      If (AltRows)
         This.AltRows := False
      This.Remove("Rows")
      This.Remove("Cells")
      Return True
   }
   ; ===================================================================================================================
   ; AlternateRows() Sets background and/or text color for even row numbers.
   ; Parameters:     BkColor     -  Background color as RGB color integer (e.g. 0xFF0000 = red) or HTML color name.
   ;                                Default: Empty -> default background color
   ;                 TxColor     -  Text color as RGB color integer (e.g. 0xFF0000 = red) or HTML color name.
   ;                                Default: Empty -> default text color
   ; Return Value:   True on success, otherwise false.
   ; ===================================================================================================================
   AlternateRows(BkColor := "", TxColor := "") {
      If !(This.HWND)
         Return False
      This.AltRows := False
      If (BkColor = "") && (TxColor = "")
         Return True
      BkBGR := This.BGR(BkColor)
      TxBGR := This.BGR(TxColor)
      If (BkBGR = "") && (TxBGR = "")
         Return False
      This["ARB"] := (BkBGR <> "") ? BkBGR : This.BkClr
      This["ART"] := (TxBGR <> "") ? TxBGR : This.TxClr
      This.AltRows := True
      Return True
   }
   ; ===================================================================================================================
   ; AlternateCols() Sets background and/or text color for even column numbers.
   ; Parameters:     BkColor     -  Background color as RGB color integer (e.g. 0xFF0000 = red) or HTML color name.
   ;                                Default: Empty -> default background color
   ;                 TxColor     -  Text color as RGB color integer (e.g. 0xFF0000 = red) or HTML color name.
   ;                                Default: Empty -> default text color
   ; Return Value:   True on success, otherwise false.
   ; ===================================================================================================================
   AlternateCols(BkColor := "", TxColor := "") {
      If !(This.HWND)
         Return False
      This.AltCols := False
      If (BkColor = "") && (TxColor = "")
         Return True
      BkBGR := This.BGR(BkColor)
      TxBGR := This.BGR(TxColor)
      If (BkBGR = "") && (TxBGR = "")
         Return False
      This["ACB"] := (BkBGR <> "") ? BkBGR : This.BkClr
      This["ACT"] := (TxBGR <> "") ? TxBGR : This.TxClr
      This.AltCols := True
      Return True
   }
   ; ===================================================================================================================
   ; SelectionColors() Sets background and/or text color for selected rows.
   ; Parameters:     BkColor     -  Background color as RGB color integer (e.g. 0xFF0000 = red) or HTML color name.
   ;                                Default: Empty -> default selected background color
   ;                 TxColor     -  Text color as RGB color integer (e.g. 0xFF0000 = red) or HTML color name.
   ;                                Default: Empty -> default selected text color
   ; Return Value:   True on success, otherwise false.
   ; ===================================================================================================================
   SelectionColors(BkColor := "", TxColor := "") {
      If !(This.HWND)
         Return False
      This.SelColors := False
      If (BkColor = "") && (TxColor = "")
         Return True
      BkBGR := This.BGR(BkColor)
      TxBGR := This.BGR(TxColor)
      If (BkBGR = "") && (TxBGR = "")
         Return False
      This["SELB"] := BkBGR
      This["SELT"] := TxBGR
      This.SelColors := True
      Return True
   }
   ; ===================================================================================================================
   ; Row()           Sets background and/or text color for the specified row.
   ; Parameters:     Row         -  Row number
   ;                 Optional ------------------------------------------------------------------------------------------
   ;                 BkColor     -  Background color as RGB color integer (e.g. 0xFF0000 = red) or HTML color name.
   ;                                Default: Empty -> default background color
   ;                 TxColor     -  Text color as RGB color integer (e.g. 0xFF0000 = red) or HTML color name.
   ;                                Default: Empty -> default text color
   ; Return Value:   True on success, otherwise false.
   ; ===================================================================================================================
   Row(Row, BkColor := "", TxColor := "") {
      If !(This.HWND)
         Return False
      If This.IsStatic
         Row := This.MapIndexToID(Row)
      This["Rows"].Remove(Row, "")
      If (BkColor = "") && (TxColor = "")
         Return True
      BkBGR := This.BGR(BkColor)
      TxBGR := This.BGR(TxColor)
      If (BkBGR = "") && (TxBGR = "")
         Return False
      This["Rows", Row, "B"] := (BkBGR <> "") ? BkBGR : This.BkClr
      This["Rows", Row, "T"] := (TxBGR <> "") ? TxBGR : This.TxClr
      Return True
   }
   ; ===================================================================================================================
   ; Cell()          Sets background and/or text color for the specified cell.
   ; Parameters:     Row         -  Row number
   ;                 Col         -  Column number
   ;                 Optional ------------------------------------------------------------------------------------------
   ;                 BkColor     -  Background color as RGB color integer (e.g. 0xFF0000 = red) or HTML color name.
   ;                                Default: Empty -> row's background color
   ;                 TxColor     -  Text color as RGB color integer (e.g. 0xFF0000 = red) or HTML color name.
   ;                                Default: Empty -> row's text color
   ; Return Value:   True on success, otherwise false.
   ; ===================================================================================================================
   Cell(Row, Col, BkColor := "", TxColor := "") {
      If !(This.HWND)
         Return False
      If This.IsStatic
         Row := This.MapIndexToID(Row)
      This["Cells", Row].Remove(Col, "")
      If (BkColor = "") && (TxColor = "")
         Return True
      BkBGR := This.BGR(BkColor)
      TxBGR := This.BGR(TxColor)
      If (BkBGR = "") && (TxBGR = "")
         Return False
      If (BkBGR <> "")
         This["Cells", Row, Col, "B"] := BkBGR
      If (TxBGR <> "")
         This["Cells", Row, Col, "T"] := TxBGR
      Return True
   }
   ; ===================================================================================================================
   ; NoSort()        Prevents/allows sorting by click on a header item for this ListView.
   ; Parameters:     Apply       -  True/False
   ;                                Default: True
   ; Return Value:   True on success, otherwise false.
   ; ===================================================================================================================
   NoSort(Apply := True) {
      If !(This.HWND)
         Return False
      If (Apply)
         This.SortColumns := False
      Else
         This.SortColumns := True
      Return True
   }
   ; ===================================================================================================================
   ; NoSizing()      Prevents/allows resizing of columns for this ListView.
   ; Parameters:     Apply       -  True/False
   ;                                Default: True
   ; Return Value:   True on success, otherwise false.
   ; ===================================================================================================================
   NoSizing(Apply := True) {
      Static OSVersion := DllCall("GetVersion", "UChar")
      If !(This.Header)
         Return False
      If (Apply) {
         If (OSVersion > 5)
            Control, Style, +0x0800, , % "ahk_id " . This.Header ; HDS_NOSIZING = 0x0800
         This.ResizeColumns := False
      }
      Else {
         If (OSVersion > 5)
            Control, Style, -0x0800, , % "ahk_id " . This.Header ; HDS_NOSIZING
         This.ResizeColumns := True
      }
      Return True
   }
   ; ===================================================================================================================
   ; OnMessage()     Adds/removes a message handler for WM_NOTIFY messages for this ListView.
   ; Parameters:     Apply       -  True/False
   ;                                Default: True
   ; Return Value:   Always True
   ; ===================================================================================================================
   OnMessage(Apply := True) {
      If (Apply) && !This.HasKey("OnMessageFunc") {
         This.OnMessageFunc := ObjBindMethod(This, "On_WM_Notify")
         OnMessage(0x004E, This.OnMessageFunc) ; add the WM_NOTIFY message handler
      }
      Else If !(Apply) && This.HasKey("OnMessageFunc") {
         OnMessage(0x004E, This.OnMessageFunc, 0) ; remove the WM_NOTIFY message handler
         This.OnMessageFunc := ""
         This.Remove("OnMessageFunc")
      }
      WinSet, Redraw, , % "ahk_id " . This.HWND
      Return True
   }
   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ; PRIVATE PROPERTIES  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   Static Attached := {}
   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ; PRIVATE METHODS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   On_WM_NOTIFY(W, L, M, H) {
      ; Notifications: NM_CUSTOMDRAW = -12, LVN_COLUMNCLICK = -108, HDN_BEGINTRACKA = -306, HDN_BEGINTRACKW = -326
      Critical, % This.Critical
      If ((HCTL := NumGet(L + 0, 0, "UPtr")) = This.HWND) || (HCTL = This.Header) {
         Code := NumGet(L + (A_PtrSize * 2), 0, "Int")
         If (Code = -12)
            Return This.NM_CUSTOMDRAW(This.HWND, L)
         If !This.SortColumns && (Code = -108)
            Return 0
         If !This.ResizeColumns && ((Code = -306) || (Code = -326))
            Return True
      }
   }
   ; -------------------------------------------------------------------------------------------------------------------
   NM_CUSTOMDRAW(H, L) {
      ; Return values: 0x00 (CDRF_DODEFAULT), 0x20 (CDRF_NOTIFYITEMDRAW / CDRF_NOTIFYSUBITEMDRAW)
      Static SizeNMHDR := A_PtrSize * 3                  ; Size of NMHDR structure
      Static SizeNCD := SizeNMHDR + 16 + (A_PtrSize * 5) ; Size of NMCUSTOMDRAW structure
      Static OffItem := SizeNMHDR + 16 + (A_PtrSize * 2) ; Offset of dwItemSpec (NMCUSTOMDRAW)
      Static OffItemState := OffItem + A_PtrSize         ; Offset of uItemState  (NMCUSTOMDRAW)
      Static OffCT :=  SizeNCD                           ; Offset of clrText (NMLVCUSTOMDRAW)
      Static OffCB := OffCT + 4                          ; Offset of clrTextBk (NMLVCUSTOMDRAW)
      Static OffSubItem := OffCB + 4                     ; Offset of iSubItem (NMLVCUSTOMDRAW)
      ; ----------------------------------------------------------------------------------------------------------------
      DrawStage := NumGet(L + SizeNMHDR, 0, "UInt")
      , Row := NumGet(L + OffItem, "UPtr") + 1
      , Col := NumGet(L + OffSubItem, "Int") + 1
      , Item := Row - 1
      If This.IsStatic
         Row := This.MapIndexToID(Row)
      ; CDDS_SUBITEMPREPAINT = 0x030001 --------------------------------------------------------------------------------
      If (DrawStage = 0x030001) {
         UseAltCol := !(Col & 1) && (This.AltCols)
         , ColColors := This["Cells", Row, Col]
         , ColB := (ColColors.B <> "") ? ColColors.B : UseAltCol ? This.ACB : This.RowB
         , ColT := (ColColors.T <> "") ? ColColors.T : UseAltCol ? This.ACT : This.RowT
         , NumPut(ColT, L + OffCT, "UInt"), NumPut(ColB, L + OffCB, "UInt")
         Return (!This.AltCols && !This.HasKey(Row) && (Col > This["Cells", Row].MaxIndex())) ? 0x00 : 0x20
      }
      ; CDDS_ITEMPREPAINT = 0x010001 -----------------------------------------------------------------------------------
      If (DrawStage = 0x010001) {
         ; LVM_GETITEMSTATE = 0x102C, LVIS_SELECTED = 0x0002
         If (This.SelColors) && DllCall("SendMessage", "Ptr", H, "UInt", 0x102C, "Ptr", Item, "Ptr", 0x0002, "UInt") {
            ; Remove the CDIS_SELECTED (0x0001) and CDIS_FOCUS (0x0010) states from uItemState and set the colors.
            NumPut(NumGet(L + OffItemState, "UInt") & ~0x0011, L + OffItemState, "UInt")
            If (This.SELB <> "")
               NumPut(This.SELB, L + OffCB, "UInt")
            If (This.SELT <> "")
               NumPut(This.SELT, L + OffCT, "UInt")
            Return 0x02 ; CDRF_NEWFONT
         }
         UseAltRow := (Item & 1) && (This.AltRows)
         , RowColors := This["Rows", Row]
         , This.RowB := RowColors ? RowColors.B : UseAltRow ? This.ARB : This.BkClr
         , This.RowT := RowColors ? RowColors.T : UseAltRow ? This.ART : This.TxClr
         If (This.AltCols || This["Cells"].HasKey(Row))
            Return 0x20
         NumPut(This.RowT, L + OffCT, "UInt"), NumPut(This.RowB, L + OffCB, "UInt")
         Return 0x00
      }
      ; CDDS_PREPAINT = 0x000001 ---------------------------------------------------------------------------------------
      Return (DrawStage = 0x000001) ? 0x20 : 0x00
   }
   ; -------------------------------------------------------------------------------------------------------------------
   MapIndexToID(Row) { ; provides the unique internal ID of the given row number
      SendMessage, 0x10B4, % (Row - 1), 0, , % "ahk_id " . This.HWND ; LVM_MAPINDEXTOID
      Return ErrorLevel
   }
   ; -------------------------------------------------------------------------------------------------------------------
   BGR(Color, Default := "") { ; converts colors to BGR
      Static Integer := "Integer" ; v2
      ; HTML Colors (BGR)
      Static HTML := {AQUA: 0xFFFF00, BLACK: 0x000000, BLUE: 0xFF0000, FUCHSIA: 0xFF00FF, GRAY: 0x808080, GREEN: 0x008000
                    , LIME: 0x00FF00, MAROON: 0x000080, NAVY: 0x800000, OLIVE: 0x008080, PURPLE: 0x800080, RED: 0x0000FF
                    , SILVER: 0xC0C0C0, TEAL: 0x808000, WHITE: 0xFFFFFF, YELLOW: 0x00FFFF}
      If Color Is Integer
         Return ((Color >> 16) & 0xFF) | (Color & 0x00FF00) | ((Color & 0xFF) << 16)
      Return (HTML.HasKey(Color) ? HTML[Color] : Default)
   }
}
How to use:
  • First create a new instance of LV_Colors with MyInstance := New LV_Colors(HLV) passing the HWND of your ListView.
  • Then call MyInstance.Cell() or MyInstance.Row() to setup colours for individual cells and/or rows.
  • That's all you have to do for colouring.
  • If you finally don't want the colours to be shown any more, use MyInstance := "" to restore the ListView's default behaviour.
  • For more detailed informations look at the inline documentation, please.
Credits::
  • dadepp for LVA

View sources on GitHub:
:arrow: https://github.com/AHK-just-me/Class_LV_Colors/
 
Download sources from GitHub:
:arrow: https://github.com/AHK-just-me/Class_LV_Colors/archive/master.zip

Previous releases on GitHub:
:arrow: https://github.com/AHK-just-me/Class_LV_Colors/releases
Last edited by just me on 16 Mar 2024, 05:53, edited 14 times in total.
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: [Class] LV_Colors - individual colors for ListView items

21 Feb 2014, 07:11

The "static mode" is really useful, thanks a lot!
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: [Class] LV_Colors - individual colors for ListView items

13 Aug 2014, 03:26

Code: Select all

#NoEnv
#Include Class_LV_Colors.ahk
SetBatchLines, -1

Gui, Add, ListView, w600 r5 Grid -ReadOnly hwndHLV, Col1
Gui, Show

LV_Colors.Attach(HLV, 1) ; static mode
LV_Colors.OnMessage()

LV_Insert(1, "", "111111111111")
LV_Colors.Row(HLV, 1, 0xFFFFB5)

Sleep, 2000

LV_Insert(1, "", "22222222222")
LV_Colors.Row(HLV, 1, 0x80FF00)
Return

GuiClose:
ExitApp
Is this a bug? row 1 and row 2 changes to same color (0x80FF00).
just me
Posts: 9541
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] LV_Colors - individual colors for ListView items

13 Aug 2014, 07:32

I won't consider this to be a bug. As the name implies, static mode is intended to be used with static ListViews. ;)

But I've already considered to change the internal handling of the 'static mode'. Since you're apparently using this mode, would you please test this version?

Edit: Removed test code, it's available on GitHub now.
Last edited by just me on 13 Aug 2014, 10:58, edited 1 time in total.
tmplinshi
Posts: 1604
Joined: 01 Oct 2013, 14:57

Re: [Class] LV_Colors - individual colors for ListView items

13 Aug 2014, 10:20

Thank you! This is the way I wanted. Tested and worked!
just me
Posts: 9541
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] LV_Colors - individual colors for ListView items

13 Aug 2014, 10:59

Thank you for testing. I've updated the script on GitHub.
User avatar
oldbrother
Posts: 275
Joined: 23 Oct 2013, 05:08

Re: [Class] LV_Colors - individual colors for ListView items

15 Aug 2014, 17:45

Hi Just me,

I have an old script using both your classes Class_LV_Colors and Class_LV_InCellEdit. About 2 years ago, your wrote the Message Handler function MyMessageHandler() for me (please see the code below. Many thanks :) ). It worked perfectly. Recently, I updated Class_LV_InCellEdit to the latest version, everything was fine. Yesterday, I was trying to update Class_LV_Colors to the new version, but it failed. After I replaced the old Class_LV_Colors.php with the new one, the script cannot work properly. The Listview even my computer is frozen everytime when I run the script.

I'm wondering if you can help me again?

Thanks a lot!!!

Code: Select all

MyMessageHandler(W, L) {
	 Critical, 500
   Static LVN_BEGINLABELEDITA := -105
   Static LVN_BEGINLABELEDITW := -175
   Static LVN_COLUMNCLICK := -108
   Static LVN_ENDLABELEDITA := -106
   Static LVN_ENDLABELEDITW := -176
   Static NM_CLICK := -2
   Static NM_CUSTOMDRAW := -12
   Static NM_DBLCLICK := -3
   H := NumGet(L + 0, 0, "UPtr")
   M := NumGet(L + (A_PtrSize * 2), 0, "Int")
   ; Critical
   If LV_Colors.HasKey(H) {
      ; NM_CUSTOMDRAW --------------------------------------------------------------------------------------------------
      If (M = NM_CUSTOMDRAW)
         Return LV_Colors.On_NM_CUSTOMDRAW(H, L)
      ; LVN_COLUMNCLICK ------------------------------------------------------------------------------------------------
      If (LV_Colors[H].NS && (M = LVN_COLUMNCLICK))
         Return 0
   }
   If (LV_InCellEdit.Attached.HasKey(H)) {
      ; BeginLabelEdit -------------------------------------------------------------------------------------------------
      If (M = LVN_BEGINLABELEDITW) || (M = LVN_BEGINLABELEDITA) {
         Return LV_InCellEdit.On_LVN_BEGINLABELEDIT(H, L)
      }
      ; EndLabelEdit ---------------------------------------------------------------------------------------------------
      If (M = LVN_ENDLABELEDITW) || (M = LVN_ENDLABELEDITA) {
         Return LV_InCellEdit.On_LVN_ENDLABELEDIT(H, L)
      }
      ; Double click ---------------------------------------------------------------------------------------------------
      If (M = NM_DBLCLICK) {
         LV_InCellEdit.On_NM_DBLCLICK(H, L)
      }
   }
}

just me
Posts: 9541
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] LV_Colors - individual colors for ListView items

16 Aug 2014, 00:20

Hi oldbrother,

ATM I've no idea. Did you update LV_Colors from v0.4 to v0.5? Hopefully, the only changes in v0.5 are related to the 'static mode'. Do you use it?

In most of my tests with ListViews and WM_NOTIFY message handlers I get into troubles with frozen ListViews or whole GUIs. Since I use Critical, 500 in the message handlers like you do, it's more rare, but it still happens. I couldn't recognise any consistent reason as yet. All I know is that the script is consuming a whole processor here. It seems to loop very fast in the background. But my computer is still working in either case, though a bit delayed.
User avatar
oldbrother
Posts: 275
Joined: 23 Oct 2013, 05:08

Re: [Class] LV_Colors - individual colors for ListView items

16 Aug 2014, 07:41

Hi Just Me,

Both V0.4 and V0.5 are not working for me. I'm still using V3.0. Luckily I kept all the versions :) .
just me
Posts: 9541
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] LV_Colors - individual colors for ListView items

17 Aug 2014, 01:32

Hi oldbrother,

I've checked the changes from 0.3 to 0.4 again und found nothing not related to the new 'static mode'. It was realised by implementing a new additional second parameter for LV_Colors.Attach().

I've never used the combination of LV_InCellEdit and LV_Colors, so I have to ask you:

Which OS version are you running?
Did you adjust the LV_Colors.Attach() call?
User avatar
oldbrother
Posts: 275
Joined: 23 Oct 2013, 05:08

Re: [Class] LV_Colors - individual colors for ListView items

17 Aug 2014, 08:02

I just adjusted LV_Colors.Attach() to LV_Colors.Attach(MyLV,1,0,0). The script works now. I didn't read your update notice carefully. How stupid I am!

The only thing now is I feel the program is a little bit sluggish. My OS is XP SP3, and my laptop is 4 year old. Probably I need a new computer.

Thanks a lot!!!
list
Posts: 222
Joined: 26 Mar 2014, 14:03
Contact:

Re: [Class] LV_Colors - individual colors for ListView items

16 Mar 2015, 15:34

Edit: fixed it I think with the GuiControl, +Redraw...

Hi just me,

I'm thinking about adding color to my listview and in principle it works, but when I scroll through my listview the color is gone - perhaps I'm doing something wrong? I use a trick to scroll using up & down arrow keys while remaining in an edit control - I've prepared a short example to illustrate the problem. I've tested this on Windows 7 (32bit, unicode) and Windows 8 (64bit). Is there a solution?

Code: Select all

Gui, Add, Edit, w100
Gui, Add, Listview, hwndHLV vVLV h200 w200,A|B|C
Loop, 30
	LV_Add("",A_Index,A_Index,A_Index)
Gui, Show
LV_Colors.OnMessage()
LV_Colors.Attach(HLV, 1, 0, 0)
Loop, 30
	LV_Colors.Row(HLV, A_Index, 0xFFECB0, 0x000000)
Return	

~Down::
GuiControl, -Redraw, VLV ; added this line
ControlSend, SysListview321, {Down}, A
GuiControl, +Redraw, VLV ; added this line
Return

#include include\Class_LV_Colors.ahk

Esc::ExitApp
list
Posts: 222
Joined: 26 Mar 2014, 14:03
Contact:

Re: [Class] LV_Colors - individual colors for ListView items

17 Mar 2015, 12:32

The GuiControl, +Redraw does seem to have done the trick, tested on both systems again and the colours remain.
just me
Posts: 9541
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] LV_Colors - new version on 2015-03-24

24 Mar 2015, 07:15

*new version*
User avatar
empardopo
Posts: 336
Joined: 06 Oct 2013, 12:50
Location: Spain
Contact:

Re: [Class] LV_Colors - new version on 2015-03-24

25 Mar 2015, 03:42

just me wrote:*new version*
Is it necesary update to the last version of AKH. Now, I am using the 1.1.19.03 version and I get this error

Greetings.
Attachments
error.png
Everything is possible!
list
Posts: 222
Joined: 26 Mar 2014, 14:03
Contact:

Re: [Class] LV_Colors - new version on 2015-03-24

25 Mar 2015, 15:39

@empardopo - Yes. In the first post it says about the latest update "New version using the new features of AHK 1.1.12+:" but I think that is a typo, as in the source code of Class_LV_Colors.ahk it says "new version using new AHK 1.1.20+ features"

Using 1.1.20.03 I can confirm it works, but you have to modify your code as indicated in the readme here https://github.com/AHK-just-me/Class_LV_Colors and study the new example script as well.
just me
Posts: 9541
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] LV_Colors - new version on 2015-03-24

25 Mar 2015, 16:00

list is right, it was a typo and should be 1.1.20+.
just me
Posts: 9541
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: [Class] LV_Colors - update on 2015-03-27

27 Mar 2015, 04:25

*update*

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: Spikea and 93 guests