├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md └── Sources ├── Class_LV_Colors.ahk └── LV_Colors_sample.ahk /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ################# 2 | ## Eclipse 3 | ################# 4 | 5 | *.pydevproject 6 | .project 7 | .metadata 8 | bin/ 9 | tmp/ 10 | *.tmp 11 | *.bak 12 | *.swp 13 | *~.nib 14 | local.properties 15 | .classpath 16 | .settings/ 17 | .loadpath 18 | 19 | # External tool builders 20 | .externalToolBuilders/ 21 | 22 | # Locally stored "Eclipse launch configurations" 23 | *.launch 24 | 25 | # CDT-specific 26 | .cproject 27 | 28 | # PDT-specific 29 | .buildpath 30 | 31 | 32 | ################# 33 | ## Visual Studio 34 | ################# 35 | 36 | ## Ignore Visual Studio temporary files, build results, and 37 | ## files generated by popular Visual Studio add-ons. 38 | 39 | # User-specific files 40 | *.suo 41 | *.user 42 | *.sln.docstates 43 | 44 | # Build results 45 | 46 | [Dd]ebug/ 47 | [Rr]elease/ 48 | x64/ 49 | build/ 50 | [Bb]in/ 51 | [Oo]bj/ 52 | 53 | # MSTest test Results 54 | [Tt]est[Rr]esult*/ 55 | [Bb]uild[Ll]og.* 56 | 57 | *_i.c 58 | *_p.c 59 | *.ilk 60 | *.meta 61 | *.obj 62 | *.pch 63 | *.pdb 64 | *.pgc 65 | *.pgd 66 | *.rsp 67 | *.sbr 68 | *.tlb 69 | *.tli 70 | *.tlh 71 | *.tmp 72 | *.tmp_proj 73 | *.log 74 | *.vspscc 75 | *.vssscc 76 | .builds 77 | *.pidb 78 | *.log 79 | *.scc 80 | 81 | # Visual C++ cache files 82 | ipch/ 83 | *.aps 84 | *.ncb 85 | *.opensdf 86 | *.sdf 87 | *.cachefile 88 | 89 | # Visual Studio profiler 90 | *.psess 91 | *.vsp 92 | *.vspx 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | 101 | # TeamCity is a build add-in 102 | _TeamCity* 103 | 104 | # DotCover is a Code Coverage Tool 105 | *.dotCover 106 | 107 | # NCrunch 108 | *.ncrunch* 109 | .*crunch*.local.xml 110 | 111 | # Installshield output folder 112 | [Ee]xpress/ 113 | 114 | # DocProject is a documentation generator add-in 115 | DocProject/buildhelp/ 116 | DocProject/Help/*.HxT 117 | DocProject/Help/*.HxC 118 | DocProject/Help/*.hhc 119 | DocProject/Help/*.hhk 120 | DocProject/Help/*.hhp 121 | DocProject/Help/Html2 122 | DocProject/Help/html 123 | 124 | # Click-Once directory 125 | publish/ 126 | 127 | # Publish Web Output 128 | *.Publish.xml 129 | *.pubxml 130 | 131 | # NuGet Packages Directory 132 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 133 | #packages/ 134 | 135 | # Windows Azure Build Output 136 | csx 137 | *.build.csdef 138 | 139 | # Windows Store app package directory 140 | AppPackages/ 141 | 142 | # Others 143 | sql/ 144 | *.Cache 145 | ClientBin/ 146 | [Ss]tyle[Cc]op.* 147 | ~$* 148 | *~ 149 | *.dbmdl 150 | *.[Pp]ublish.xml 151 | *.pfx 152 | *.publishsettings 153 | 154 | # RIA/Silverlight projects 155 | Generated_Code/ 156 | 157 | # Backup & report files from converting an old project file to a newer 158 | # Visual Studio version. Backup files are not needed, because we have git ;-) 159 | _UpgradeReport_Files/ 160 | Backup*/ 161 | UpgradeLog*.XML 162 | UpgradeLog*.htm 163 | 164 | # SQL Server files 165 | App_Data/*.mdf 166 | App_Data/*.ldf 167 | 168 | ############# 169 | ## Windows detritus 170 | ############# 171 | 172 | # Windows image file caches 173 | Thumbs.db 174 | ehthumbs.db 175 | 176 | # Folder config file 177 | Desktop.ini 178 | 179 | # Recycle Bin used on file shares 180 | $RECYCLE.BIN/ 181 | 182 | # Mac crap 183 | .DS_Store 184 | 185 | 186 | ############# 187 | ## Python 188 | ############# 189 | 190 | *.py[co] 191 | 192 | # Packages 193 | *.egg 194 | *.egg-info 195 | dist/ 196 | build/ 197 | eggs/ 198 | parts/ 199 | var/ 200 | sdist/ 201 | develop-eggs/ 202 | .installed.cfg 203 | 204 | # Installer logs 205 | pip-log.txt 206 | 207 | # Unit test / coverage reports 208 | .coverage 209 | .tox 210 | 211 | #Translations 212 | *.mo 213 | 214 | #Mr Developer 215 | .mr.developer.cfg 216 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Class_LV_Colors # 2 | 3 | The class supports individually colored rows and cells for AHK ListView controls. 4 | 5 | ### How to use: ### 6 | - Create a new instance with `MyInstance := New LV_Colors(HLV)` passing the HWND of your ListView. 7 | - Then call `MyInstance.Cell()` or `MyInstance.Row()` to setup colors for individual cells and/or rows. 8 | - That's all you have to do for coloring. 9 | - If you finally don't want the colors to be shown any more, use `MyInstance := ""` to restore the ListView's default behaviour. 10 | 11 | For more detailed informations look at the inline documentation, please. 12 | -------------------------------------------------------------------------------- /Sources/Class_LV_Colors.ahk: -------------------------------------------------------------------------------- 1 | #Requires AutoHotkey v1.1.37.02 2 | ; ====================================================================================================================== 3 | ; Namespace: LV_Colors 4 | ; Function: Individual row and cell coloring for AHK ListView controls. 5 | ; Tested with: AHK 1.1.37.02 (A32/U32/U64) 6 | ; Tested on: Win 10 (x64) 7 | ; Changelog: 8 | ; 1.1.05.00/2024-03-16/just me - adjusted to AHK 1.1.37.02 preventing freezing of the control and/or the GUI 9 | ; 1.1.04.01/2016-05-03/just me - added change to remove the focus rectangle from focused rows 10 | ; 1.1.04.00/2016-05-03/just me - added SelectionColors method 11 | ; 1.1.03.00/2015-04-11/just me - bugfix for StaticMode 12 | ; 1.1.02.00/2015-04-07/just me - bugfixes for StaticMode, NoSort, and NoSizing 13 | ; 1.1.01.00/2015-03-31/just me - removed option OnMessage from __New(), restructured code 14 | ; 1.1.00.00/2015-03-27/just me - added AlternateRows and AlternateCols, revised code. 15 | ; 1.0.00.00/2015-03-23/just me - new version using new AHK 1.1.20+ features 16 | ; 0.5.00.00/2014-08-13/just me - changed 'static mode' handling 17 | ; 0.4.01.00/2013-12-30/just me - minor bug fix 18 | ; 0.4.00.00/2013-12-30/just me - added static mode 19 | ; 0.3.00.00/2013-06-15/just me - added "Critical, 100" to avoid drawing issues 20 | ; 0.2.00.00/2013-01-12/just me - bugfixes and minor changes 21 | ; 0.1.00.00/2012-10-27/just me - initial release 22 | ; ====================================================================================================================== 23 | ; CLASS LV_Colors 24 | ; 25 | ; The class provides six public methods to set individual colors for rows and/or cells, to clear all colors, to 26 | ; prevent/allow sorting and rezising of columns dynamically, and to deactivate/activate the message handler for 27 | ; WM_NOTIFY messages (see below). 28 | ; 29 | ; The message handler for WM_NOTIFY messages will be activated for the specified ListView whenever a new instance is 30 | ; created. If you want to temporarily disable coloring call MyInstance.OnMessage(False). This must be done also before 31 | ; you try to destroy the instance. To enable it again, call MyInstance.OnMessage(). 32 | ; ====================================================================================================================== 33 | Class LV_Colors { 34 | ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 35 | ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 36 | ; META FUNCTIONS ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 37 | ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 38 | ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 39 | ; =================================================================================================================== 40 | ; __New() Create a new LV_Colors instance for the given ListView 41 | ; Parameters: HWND - ListView's HWND. 42 | ; Optional ------------------------------------------------------------------------------------------ 43 | ; StaticMode - Static color assignment, i.e. the colors will be assigned permanently to the row 44 | ; contents rather than to the row number. 45 | ; Values: True/False 46 | ; Default: False 47 | ; NoSort - Prevent sorting by click on a header item. 48 | ; Values: True/False 49 | ; Default: False 50 | ; NoSizing - Prevent resizing of columns. 51 | ; Values: True/False 52 | ; Default: False 53 | ; =================================================================================================================== 54 | __New(HWND, StaticMode := False, NoSort := False, NoSizing := False) { 55 | If (This.Base.Base.__Class) ; do not instantiate instances 56 | Return False 57 | If This.Attached[HWND] ; HWND is already attached 58 | Return False 59 | If !DllCall("IsWindow", "Ptr", HWND) ; invalid HWND 60 | Return False 61 | VarSetCapacity(Class, 512, 0) 62 | DllCall("GetClassName", "Ptr", HWND, "Str", Class, "Int", 256) 63 | If (Class <> "SysListView32") ; HWND doesn't belong to a ListView 64 | Return False 65 | ; ---------------------------------------------------------------------------------------------------------------- 66 | ; Set LVS_EX_DOUBLEBUFFER (0x010000) style to avoid drawing issues. 67 | SendMessage, 0x1036, 0x010000, 0x010000, , % "ahk_id " . HWND ; LVM_SETEXTENDEDLISTVIEWSTYLE 68 | ; Get the default colors 69 | SendMessage, 0x1025, 0, 0, , % "ahk_id " . HWND ; LVM_GETTEXTBKCOLOR 70 | This.BkClr := ErrorLevel 71 | SendMessage, 0x1023, 0, 0, , % "ahk_id " . HWND ; LVM_GETTEXTCOLOR 72 | This.TxClr := ErrorLevel 73 | ; Get the header control 74 | SendMessage, 0x101F, 0, 0, , % "ahk_id " . HWND ; LVM_GETHEADER 75 | This.Header := ErrorLevel 76 | ; Set other properties 77 | This.HWND := HWND 78 | This.IsStatic := !!StaticMode 79 | This.AltCols := False 80 | This.AltRows := False 81 | This.NoSort(!!NoSort) 82 | This.NoSizing(!!NoSizing) 83 | This.OnMessage() 84 | This.Critical := "Off" ; <<<<< no effects with 1.1.05.00 + 85 | This.Attached[HWND] := True 86 | } 87 | ; =================================================================================================================== 88 | __Delete() { 89 | This.Attached.Remove(HWND, "") 90 | This.OnMessage(False) 91 | WinSet, Redraw, , % "ahk_id " . This.HWND 92 | } 93 | ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 94 | ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 95 | ; PUBLIC METHODS ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 96 | ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 97 | ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 98 | ; =================================================================================================================== 99 | ; Clear() Clears all row and cell colors. 100 | ; Parameters: AltRows - Reset alternate row coloring (True / False) 101 | ; Default: False 102 | ; AltCols - Reset alternate column coloring (True / False) 103 | ; Default: False 104 | ; Return Value: Always True. 105 | ; =================================================================================================================== 106 | Clear(AltRows := False, AltCols := False) { 107 | If (AltCols) 108 | This.AltCols := False 109 | If (AltRows) 110 | This.AltRows := False 111 | This.Remove("Rows") 112 | This.Remove("Cells") 113 | Return True 114 | } 115 | ; =================================================================================================================== 116 | ; AlternateRows() Sets background and/or text color for even row numbers. 117 | ; Parameters: BkColor - Background color as RGB color integer (e.g. 0xFF0000 = red) or HTML color name. 118 | ; Default: Empty -> default background color 119 | ; TxColor - Text color as RGB color integer (e.g. 0xFF0000 = red) or HTML color name. 120 | ; Default: Empty -> default text color 121 | ; Return Value: True on success, otherwise false. 122 | ; =================================================================================================================== 123 | AlternateRows(BkColor := "", TxColor := "") { 124 | If !(This.HWND) 125 | Return False 126 | This.AltRows := False 127 | If (BkColor = "") && (TxColor = "") 128 | Return True 129 | BkBGR := This.BGR(BkColor) 130 | TxBGR := This.BGR(TxColor) 131 | If (BkBGR = "") && (TxBGR = "") 132 | Return False 133 | This["ARB"] := (BkBGR <> "") ? BkBGR : This.BkClr 134 | This["ART"] := (TxBGR <> "") ? TxBGR : This.TxClr 135 | This.AltRows := True 136 | Return True 137 | } 138 | ; =================================================================================================================== 139 | ; AlternateCols() Sets background and/or text color for even column numbers. 140 | ; Parameters: BkColor - Background color as RGB color integer (e.g. 0xFF0000 = red) or HTML color name. 141 | ; Default: Empty -> default background color 142 | ; TxColor - Text color as RGB color integer (e.g. 0xFF0000 = red) or HTML color name. 143 | ; Default: Empty -> default text color 144 | ; Return Value: True on success, otherwise false. 145 | ; =================================================================================================================== 146 | AlternateCols(BkColor := "", TxColor := "") { 147 | If !(This.HWND) 148 | Return False 149 | This.AltCols := False 150 | If (BkColor = "") && (TxColor = "") 151 | Return True 152 | BkBGR := This.BGR(BkColor) 153 | TxBGR := This.BGR(TxColor) 154 | If (BkBGR = "") && (TxBGR = "") 155 | Return False 156 | This["ACB"] := (BkBGR <> "") ? BkBGR : This.BkClr 157 | This["ACT"] := (TxBGR <> "") ? TxBGR : This.TxClr 158 | This.AltCols := True 159 | Return True 160 | } 161 | ; =================================================================================================================== 162 | ; SelectionColors() Sets background and/or text color for selected rows. 163 | ; Parameters: BkColor - Background color as RGB color integer (e.g. 0xFF0000 = red) or HTML color name. 164 | ; Default: Empty -> default selected background color 165 | ; TxColor - Text color as RGB color integer (e.g. 0xFF0000 = red) or HTML color name. 166 | ; Default: Empty -> default selected text color 167 | ; Return Value: True on success, otherwise false. 168 | ; =================================================================================================================== 169 | SelectionColors(BkColor := "", TxColor := "") { 170 | If !(This.HWND) 171 | Return False 172 | This.SelColors := False 173 | If (BkColor = "") && (TxColor = "") 174 | Return True 175 | BkBGR := This.BGR(BkColor) 176 | TxBGR := This.BGR(TxColor) 177 | If (BkBGR = "") && (TxBGR = "") 178 | Return False 179 | This["SELB"] := BkBGR 180 | This["SELT"] := TxBGR 181 | This.SelColors := True 182 | Return True 183 | } 184 | ; =================================================================================================================== 185 | ; Row() Sets background and/or text color for the specified row. 186 | ; Parameters: Row - Row number 187 | ; Optional ------------------------------------------------------------------------------------------ 188 | ; BkColor - Background color as RGB color integer (e.g. 0xFF0000 = red) or HTML color name. 189 | ; Default: Empty -> default background color 190 | ; TxColor - Text color as RGB color integer (e.g. 0xFF0000 = red) or HTML color name. 191 | ; Default: Empty -> default text color 192 | ; Return Value: True on success, otherwise false. 193 | ; =================================================================================================================== 194 | Row(Row, BkColor := "", TxColor := "") { 195 | If !(This.HWND) 196 | Return False 197 | If This.IsStatic 198 | Row := This.MapIndexToID(Row) 199 | This["Rows"].Remove(Row, "") 200 | If (BkColor = "") && (TxColor = "") 201 | Return True 202 | BkBGR := This.BGR(BkColor) 203 | TxBGR := This.BGR(TxColor) 204 | If (BkBGR = "") && (TxBGR = "") 205 | Return False 206 | This["Rows", Row, "B"] := (BkBGR <> "") ? BkBGR : This.BkClr 207 | This["Rows", Row, "T"] := (TxBGR <> "") ? TxBGR : This.TxClr 208 | Return True 209 | } 210 | ; =================================================================================================================== 211 | ; Cell() Sets background and/or text color for the specified cell. 212 | ; Parameters: Row - Row number 213 | ; Col - Column number 214 | ; Optional ------------------------------------------------------------------------------------------ 215 | ; BkColor - Background color as RGB color integer (e.g. 0xFF0000 = red) or HTML color name. 216 | ; Default: Empty -> row's background color 217 | ; TxColor - Text color as RGB color integer (e.g. 0xFF0000 = red) or HTML color name. 218 | ; Default: Empty -> row's text color 219 | ; Return Value: True on success, otherwise false. 220 | ; =================================================================================================================== 221 | Cell(Row, Col, BkColor := "", TxColor := "") { 222 | If !(This.HWND) 223 | Return False 224 | If This.IsStatic 225 | Row := This.MapIndexToID(Row) 226 | This["Cells", Row].Remove(Col, "") 227 | If (BkColor = "") && (TxColor = "") 228 | Return True 229 | BkBGR := This.BGR(BkColor) 230 | TxBGR := This.BGR(TxColor) 231 | If (BkBGR = "") && (TxBGR = "") 232 | Return False 233 | If (BkBGR <> "") 234 | This["Cells", Row, Col, "B"] := BkBGR 235 | If (TxBGR <> "") 236 | This["Cells", Row, Col, "T"] := TxBGR 237 | Return True 238 | } 239 | ; =================================================================================================================== 240 | ; NoSort() Prevents/allows sorting by click on a header item for this ListView. 241 | ; Parameters: Apply - True/False 242 | ; Default: True 243 | ; Return Value: True on success, otherwise false. 244 | ; =================================================================================================================== 245 | NoSort(Apply := True) { 246 | If !(This.HWND) 247 | Return False 248 | If (Apply) 249 | This.SortColumns := False 250 | Else 251 | This.SortColumns := True 252 | Return True 253 | } 254 | ; =================================================================================================================== 255 | ; NoSizing() Prevents/allows resizing of columns for this ListView. 256 | ; Parameters: Apply - True/False 257 | ; Default: True 258 | ; Return Value: True on success, otherwise false. 259 | ; =================================================================================================================== 260 | NoSizing(Apply := True) { 261 | Static OSVersion := DllCall("GetVersion", "UChar") 262 | If !(This.Header) 263 | Return False 264 | If (Apply) { 265 | If (OSVersion > 5) 266 | Control, Style, +0x0800, , % "ahk_id " . This.Header ; HDS_NOSIZING = 0x0800 267 | This.ResizeColumns := False 268 | } 269 | Else { 270 | If (OSVersion > 5) 271 | Control, Style, -0x0800, , % "ahk_id " . This.Header ; HDS_NOSIZING 272 | This.ResizeColumns := True 273 | } 274 | Return True 275 | } 276 | ; =================================================================================================================== 277 | ; OnMessage() Adds/removes a message handler for WM_NOTIFY messages for this ListView. 278 | ; Parameters: Apply - True/False 279 | ; Default: True 280 | ; Return Value: Always True 281 | ; =================================================================================================================== 282 | OnMessage(Apply := True) { 283 | If (Apply) && !This.HasKey("OnMessageFunc") { 284 | This.OnMessageFunc := ObjBindMethod(This, "On_WM_Notify") 285 | OnMessage(0x004E, This.OnMessageFunc) ; add the WM_NOTIFY message handler 286 | } 287 | Else If !(Apply) && This.HasKey("OnMessageFunc") { 288 | OnMessage(0x004E, This.OnMessageFunc, 0) ; remove the WM_NOTIFY message handler 289 | This.OnMessageFunc := "" 290 | This.Remove("OnMessageFunc") 291 | } 292 | WinSet, Redraw, , % "ahk_id " . This.HWND 293 | Return True 294 | } 295 | ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 296 | ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 297 | ; PRIVATE PROPERTIES +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 298 | ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 299 | ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 300 | Static Attached := {} 301 | ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 302 | ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 303 | ; PRIVATE METHODS +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 304 | ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 305 | ; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 306 | On_WM_NOTIFY(W, L, M, H) { 307 | ; Notifications: NM_CUSTOMDRAW = -12, LVN_COLUMNCLICK = -108, HDN_BEGINTRACKA = -306, HDN_BEGINTRACKW = -326 308 | Critical, -1 309 | HCTL := NumGet(L + 0, 0, "UPtr"), 310 | Code := NumGet(L + (A_PtrSize * 2), 0, "Int") 311 | Switch HCTL { 312 | Case This.HWND: 313 | If (Code = -12) 314 | Return This.NM_CUSTOMDRAW(This.HWND, L) 315 | If !This.SortColumns && (Code = -108) 316 | Return 0 317 | Case This.Header: 318 | If !This.ResizeColumns && ((Code = -306) || (Code = -326)) 319 | Return True 320 | } 321 | } 322 | ; ------------------------------------------------------------------------------------------------------------------- 323 | NM_CUSTOMDRAW(H, L) { 324 | ; Return values: 0x00 (CDRF_DODEFAULT), 0x20 (CDRF_NOTIFYITEMDRAW / CDRF_NOTIFYSUBITEMDRAW) 325 | Static SizeNMHDR := A_PtrSize * 3 ; Size of NMHDR structure 326 | Static SizeNCD := SizeNMHDR + 16 + (A_PtrSize * 5) ; Size of NMCUSTOMDRAW structure 327 | Static OffItem := SizeNMHDR + 16 + (A_PtrSize * 2) ; Offset of dwItemSpec (NMCUSTOMDRAW) 328 | Static OffItemState := OffItem + A_PtrSize ; Offset of uItemState (NMCUSTOMDRAW) 329 | Static OffCT := SizeNCD ; Offset of clrText (NMLVCUSTOMDRAW) 330 | Static OffCB := OffCT + 4 ; Offset of clrTextBk (NMLVCUSTOMDRAW) 331 | Static OffSubItem := OffCB + 4 ; Offset of iSubItem (NMLVCUSTOMDRAW) 332 | ; ---------------------------------------------------------------------------------------------------------------- 333 | DrawStage := NumGet(L + SizeNMHDR, 0, "UInt") 334 | , Row := NumGet(L + OffItem, "UPtr") + 1 335 | , Col := NumGet(L + OffSubItem, "Int") + 1 336 | , Item := Row - 1 337 | If This.IsStatic 338 | Row := This.MapIndexToID(Row) 339 | ; CDDS_SUBITEMPREPAINT = 0x030001 -------------------------------------------------------------------------------- 340 | If (DrawStage = 0x030001) { 341 | UseAltCol := !(Col & 1) && (This.AltCols) 342 | , ColColors := This["Cells", Row, Col] 343 | , ColB := (ColColors.B <> "") ? ColColors.B : UseAltCol ? This.ACB : This.RowB 344 | , ColT := (ColColors.T <> "") ? ColColors.T : UseAltCol ? This.ACT : This.RowT 345 | , NumPut(ColT, L + OffCT, "UInt"), NumPut(ColB, L + OffCB, "UInt") 346 | Return (!This.AltCols && !This.HasKey(Row) && (Col > This["Cells", Row].MaxIndex())) ? 0x00 : 0x20 347 | } 348 | ; CDDS_ITEMPREPAINT = 0x010001 ----------------------------------------------------------------------------------- 349 | If (DrawStage = 0x010001) { 350 | ; LVM_GETITEMSTATE = 0x102C, LVIS_SELECTED = 0x0002 351 | If (This.SelColors) && DllCall("SendMessage", "Ptr", H, "UInt", 0x102C, "Ptr", Item, "Ptr", 0x0002, "UInt") { 352 | ; Remove the CDIS_SELECTED (0x0001) and CDIS_FOCUS (0x0010) states from uItemState and set the colors. 353 | NumPut(NumGet(L + OffItemState, "UInt") & ~0x0011, L + OffItemState, "UInt") 354 | If (This.SELB <> "") 355 | NumPut(This.SELB, L + OffCB, "UInt") 356 | If (This.SELT <> "") 357 | NumPut(This.SELT, L + OffCT, "UInt") 358 | Return 0x02 ; CDRF_NEWFONT 359 | } 360 | UseAltRow := (Item & 1) && (This.AltRows) 361 | , RowColors := This["Rows", Row] 362 | , This.RowB := RowColors ? RowColors.B : UseAltRow ? This.ARB : This.BkClr 363 | , This.RowT := RowColors ? RowColors.T : UseAltRow ? This.ART : This.TxClr 364 | If (This.AltCols || This["Cells"].HasKey(Row)) 365 | Return 0x20 366 | NumPut(This.RowT, L + OffCT, "UInt"), NumPut(This.RowB, L + OffCB, "UInt") 367 | Return 0x00 368 | } 369 | ; CDDS_PREPAINT = 0x000001 --------------------------------------------------------------------------------------- 370 | Return (DrawStage = 0x000001) ? 0x20 : 0x00 371 | } 372 | ; ------------------------------------------------------------------------------------------------------------------- 373 | MapIndexToID(Row) { ; provides the unique internal ID of the given row number 374 | SendMessage, 0x10B4, % (Row - 1), 0, , % "ahk_id " . This.HWND ; LVM_MAPINDEXTOID 375 | Return ErrorLevel 376 | } 377 | ; ------------------------------------------------------------------------------------------------------------------- 378 | BGR(Color, Default := "") { ; converts colors to BGR 379 | Static Integer := "Integer" ; v2 380 | ; HTML Colors (BGR) 381 | Static HTML := {AQUA: 0xFFFF00, BLACK: 0x000000, BLUE: 0xFF0000, FUCHSIA: 0xFF00FF, GRAY: 0x808080, GREEN: 0x008000 382 | , LIME: 0x00FF00, MAROON: 0x000080, NAVY: 0x800000, OLIVE: 0x008080, PURPLE: 0x800080, RED: 0x0000FF 383 | , SILVER: 0xC0C0C0, TEAL: 0x808000, WHITE: 0xFFFFFF, YELLOW: 0x00FFFF} 384 | If Color Is Integer 385 | Return ((Color >> 16) & 0xFF) | (Color & 0x00FF00) | ((Color & 0xFF) << 16) 386 | Return (HTML.HasKey(Color) ? HTML[Color] : Default) 387 | } 388 | } 389 | -------------------------------------------------------------------------------- /Sources/LV_Colors_sample.ahk: -------------------------------------------------------------------------------- 1 | #NoEnv 2 | #Include Class_LV_Colors.ahk 3 | SetBatchLines, -1 4 | Gui, Margin, 20, 20 5 | Gui, Add, ListView, w600 r15 Grid -ReadOnly vVLV hwndHLV 6 | , Column 1|Column 2|Column 3|Column 4|Column 5|Column6 7 | Loop, 256 8 | LV_Add("", "Value " . A_Index, "Value " . A_Index, "Value " . A_Index, "Value " . A_Index, "Value " 9 | . A_Index, "Value " . A_Index) 10 | Loop, % LV_GetCount("Column") 11 | LV_ModifyCol(A_Index, 95) 12 | ; Create a new instance of LV_Colors 13 | CLV := New LV_Colors(HLV) 14 | ; Set the colors for selected rows 15 | CLV.SelectionColors(0xF0F0F0) 16 | If !IsObject(CLV) { 17 | MsgBox, 0, ERROR, Couldn't create a new LV_Colors object! 18 | ExitApp 19 | } 20 | Gui, Add, CheckBox, w120 vColorsOn gSubShowColors Checked, Colors On 21 | Gui, Add, Radio, x+120 yp wp vColors gSubColors, Colors 22 | Gui, Add, Radio, x+0 yp wp vAltRows gSubColors, Alternate Rows 23 | Gui, Add, Radio, x+0 yp wp vAltCols gSubColors, Alternate Columns 24 | Gui, Show, , ListView & Colors 25 | ; Redraw the ListView after the first Gui, Show command to show the colors, if any. 26 | WinSet, Redraw, , ahk_id %HLV% 27 | Return 28 | ; ---------------------------------------------------------------------------------------------------------------------- 29 | GuiClose: 30 | GuiEscape: 31 | ExitApp 32 | ; ---------------------------------------------------------------------------------------------------------------------- 33 | SubShowColors: 34 | Gui, Submit, NoHide 35 | If (ColorsOn) 36 | CLV.OnMessage() 37 | Else 38 | CLV.OnMessage(False) 39 | GuiControl, Focus, %HLV% 40 | Return 41 | ; ---------------------------------------------------------------------------------------------------------------------- 42 | SubColors: 43 | Gui, Submit, NoHide 44 | GuiControl, -Redraw, %HLV% 45 | CLV.Clear(1, 1) 46 | If (Colors) 47 | GoSub, SetColors 48 | If (AltRows) 49 | CLV.AlternateRows(0x808080, 0xFFFFFF) 50 | If (AltCols) 51 | CLV.AlternateCols(0x808080, 0xFFFFFF) 52 | GuiControl, +Redraw, %HLV% 53 | Return 54 | ; ---------------------------------------------------------------------------------------------------------------------- 55 | SetColors: 56 | Loop, % LV_GetCount() { 57 | If (A_Index & 1) { 58 | CLV.Cell(A_Index, 1, 0x808080, 0xFFFFFF) 59 | CLV.Cell(A_Index, 3, 0x808080, 0xFFFFFF) 60 | CLV.Cell(A_Index, 5, 0x808080, 0xFFFFFF) 61 | } 62 | Else { 63 | CLV.Cell(A_Index, 2, 0x808080, 0xFFFFFF) 64 | CLV.Cell(A_Index, 4, 0x808080, 0xFFFFFF) 65 | CLV.Cell(A_Index, 6, 0x808080, 0xFFFFFF) 66 | } 67 | } 68 | Return --------------------------------------------------------------------------------