 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
dadepp
Joined: 12 Jun 2008 Posts: 19
|
Posted: Wed Apr 15, 2009 4:44 pm Post subject: LVA: Color individual cells of a ListView, and more ... |
|
|
Hi, I finally finished (ok only partly, but still it works ) this little project of mine.
ListViewAdvanced lets you color (background and text) individual rows/columns/cells and even implements a progressbar inside a cell.
Since this is realised with CustomDraw an OnNotify event handler is required, which might be the reason why sometimes (well atleast on my system) it doesn't display any coloring at all (but a refresh solves that). If anyone has any insight into that, any help is welcomed.
Features:
- changing background- / textcolor of individual rows/columns/cells
- highlight alternating Rows/Columns with a simple bool
- show a progressbar inside cells (even with a gradient)
- retrieve the row and column number of the item the mouse is currently hovering over
- set icons inside individual cells (requires the +LV0x2 option to be set)
I hope it is usefull to someone.
Important Note:
The color informations are row/column fixed!! Meaning if the order of the cells is changed the color will NOT move with the cells. Exception being if the column order is changed via Drag&Drop, then the color will move. Go CustomDraw Go (hmm would have never guess I'd praise windows for being intellegent).
This means that if a row is inserted/deleted or if the rows are sorted, it will mess up the colors. Solution for this is: use "GuiControl, -Redraw", sort/insert/delete row(s), use LVA_EraseAllCells(), iterate through the listview and set the color again, use "GuiControl, +Redraw".
Library file (save in StdLib folder as "LVA.ahk"):
Download LVA.ahk
An example:
| Code: | #SingleInstance Force
hLVIL := IL_Create(2)
IL_Add(hLVIL, "shell32.dll", 1)
IL_Add(hLVIL, "shell32.dll", 2)
Gui, Add, ListView, w450 h340 vTLV gLVClick AltSubmit +LV0x2, Col 1|Col 2|Col 3|Col 4|Col 5|Col 6|Col 7|Col 8|Col 9|Col 10
LV_SetImageList(hLVIL, 1)
LV_ModifyCol(1, 60)
LV_ModifyCol(2, 200)
LV_Add("Icon9999","test 22")
LV_Add("Icon9999","test 33")
LV_Add("Icon9999","test 59")
LV_Add("Icon9999","test 74")
LV_Add("Icon9999","test 26")
LV_Add("Icon9999","test 05")
LV_Add("","test")
LV_Add("Icon9999","test 15")
LV_Add("Icon9999","test 85")
LV_Add("Icon9999","test 62")
LV_Add("Icon9999","test 05")
LV_Add("Icon9999","test 94")
LV_Add("Icon9999","test 38")
LV_Add("Icon9999","test 55")
LV_Add("Icon9999","test 15")
LV_Add("Icon9999","test 08")
LV_Add("Icon9999","test 99")
LV_Add("Icon9999","test 42")
LV_Add("Icon9999","test 24")
LV_Add("Icon9999","test 88")
Gui, Add, Button, gGoBut vGoBut, test
Gui, Add, Text, w100 vLabel_Row, 0
Gui, Add, Text, w100 vLabel_Col, 0
Gui, Show
LVA_ListViewAdd("TLV", "AR ac cbsilver")
LVA_SetProgressBar("TLV", 1, 2, "s0xD8CB27 e0xFF91FF r200")
LVA_SetProgressBar("TLV", 3, 4, "bmaroon s0xD8CB27 r121")
LVA_SetProgressBar("TLV", 5, 2, "s0xD8CB27 e0xFF91FF Smooth")
LVA_SetCell("TLV", 2, 1, "red")
LVA_SetCell("TLV", 4, 1, "", "0x00F00A")
LVA_SetCell("TLV", 5, 1, "", "0x0000FF")
LVA_SetCell("TLV", 6, 0, "0xFFFFFF")
LVA_SetCell("TLV", 7, 0, "0x56B2C4")
LVA_SetCell("TLV", 0, 4, "0xFF00FF")
LVA_SetSubItemImage("TLV", 1, 2, 1)
LVA_SetSubItemImage("TLV", 2, 0, 2)
LVA_SetSubItemImage("TLV", 2, 1, 2)
LVA_SetCell("TLV", 8, 1, "white")
LVA_SetCell("TLV", 8, 2, "black")
LVA_SetCell("TLV", 8, 3, "silver")
LVA_SetCell("TLV", 9, 1, "gray")
LVA_SetCell("TLV", 9, 2, "maroon")
LVA_SetCell("TLV", 9, 3, "red")
LVA_SetCell("TLV", 10, 1, "purple")
LVA_SetCell("TLV", 10, 2, "fuchsia")
LVA_SetCell("TLV", 10, 3, "green")
LVA_SetCell("TLV", 11, 1, "lime")
LVA_SetCell("TLV", 11, 2, "olive")
LVA_SetCell("TLV", 11, 3, "yellow")
LVA_SetCell("TLV", 12, 1, "navy")
LVA_SetCell("TLV", 12, 2, "blue")
LVA_SetCell("TLV", 12, 3, "teal")
LVA_SetCell("TLV", 13, 1, "aqua")
LVA_SetCell("TLV", 14, 0, "black")
OnMessage("0x4E", "LVA_OnNotify")
return
GoBut:
GuiControl,,Label_Row, % LVA_GetCellNum("GetRows", "TLV")
GuiControl,,Label_Col, % LVA_GetCellNum("GetCols", "TLV")
LVA_SetCell("TLV", 6, 0)
LVA_SetCell("TLV", 7, 0)
LVA_Refresh("TLV")
Loop, 100
{
LVA_Progress("TLV",1,2,A_Index)
LVA_Progress("TLV",3,4,A_Index)
LVA_Progress("TLV",5,2,A_Index)
Sleep, 100
}
MsgBox, Now all colors and Progressbars will disappear !
LVA_EraseAllCells("TLV")
LVA_Refresh("TLV")
MsgBox, Even the alternating row coloring
LVA_ListViewModify("TLV", "-AR")
LVA_Refresh("TLV")
MsgBox, Now we change the alternating column colors
LVA_ListViewModify("TLV", "CBred")
LVA_Refresh("TLV")
sleep, 1000
LVA_ListViewModify("TLV", "CBblack")
LVA_Refresh("TLV")
sleep, 1000
LVA_ListViewModify("TLV", "CBred")
LVA_Refresh("TLV")
sleep, 1000
LVA_Refresh("TLV")
MsgBox, Now we remove the alternating column colors
LVA_ListViewModify("TLV", "-AC")
LVA_Refresh("TLV")
MsgBox, Now we play with the alternating rows
LVA_ListViewModify("TLV", "AR")
LVA_ListViewModify("TLV", "RBblack RFwhite")
LVA_Refresh("TLV")
sleep, 1000
LVA_ListViewModify("TLV", "RBfuchsia RFblack")
LVA_Refresh("TLV")
sleep, 1000
LVA_ListViewModify("TLV", "RBaqua")
LVA_Refresh("TLV")
sleep, 1000
LVA_ListViewModify("TLV", "RB0x27CBD8")
LVA_Refresh("TLV")
sleep, 1000
LVA_ListViewModify("TLV", "RB0xD8CB27 rfred")
LVA_Refresh("TLV")
sleep, 1000
return
LVClick:
if (A_GuiEvent = "Normal")
{
LVA_GetCellNum(0, A_GuiControl)
GuiControl,,Label_Row, % LVA_GetCellNum("Row")
GuiControl,,Label_Col, % LVA_GetCellNum("Col")
}
return
GuiClose:
ExitApp
return
; Uncomment following line if LVA.ahk is not inside the StdLib!
;#Include LVA.ahk
|
Things to Do:
- Implement an editcontrol to be shown to edit individual cells
- same as above, but with a dropdownbox
- Implement showing multiple Icons inside a single cell
- same as above, but inside the dropdownbox
- apply individual fonts for the cells
Well the last item on the ToDo list, is actually easily implemented, but i've hit a BIG roadblock with it. It works like this:
-> create a new font
-> select font into the listviews hdc
-> let windows do the drawing
-> restore original font
The implementation of that is only a few lines, but I'm having the problem with creating the new font. How can i get the metrics out of the listview's hdc and apply the needed changes ? (The only thing that can't be changed is the font size, since a listview does not support individual cell heights, the rest of the font should be changeable)
This code is based on the work by evl, so thanks goes out to him.
If anyone has suggestions and/or bugfixes, please feel free to post them.
I apologize in if my english is not good, because I'm not native english.
Last edited by dadepp on Wed Apr 15, 2009 8:18 pm; edited 1 time in total |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Apr 15, 2009 6:32 pm Post subject: |
|
|
Hey! Looks cool!
A screenshot would be nice, because people would understand right away what this is all about.  |
|
| Back to top |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 4508 Location: Boulder, CO
|
Posted: Wed Apr 15, 2009 7:00 pm Post subject: |
|
|
| Very nice! Thanks for sharing it. |
|
| Back to top |
|
 |
dadepp
Joined: 12 Jun 2008 Posts: 19
|
Posted: Wed Apr 15, 2009 8:20 pm Post subject: |
|
|
| Anonymous wrote: | Hey! Looks cool!
A screenshot would be nice, because people would understand right away what this is all about.  |
Done. Thx for feedback
| Laszlo wrote: | | Very nice! Thanks for sharing it. |
Hope it is usefull for some. |
|
| Back to top |
|
 |
n-l-i-d Guest
|
Posted: Sat Apr 18, 2009 1:01 pm Post subject: |
|
|
Very nice indeed!
 |
|
| Back to top |
|
 |
Mystiq
Joined: 08 Jan 2007 Posts: 41
|
Posted: Wed Jul 22, 2009 6:23 am Post subject: |
|
|
This is great, thanks!
P.s. That multiple icons per cell sounds like a plan.  |
|
| Back to top |
|
 |
Klaus
Joined: 12 May 2005 Posts: 256 Location: Münster, Germany
|
Posted: Wed Jul 22, 2009 10:57 am Post subject: |
|
|
Hi, dadepp,
a real useful lib, your lva, but there a two functions in the lva.ahk
which start with a single "Static" without any variable names. That
causes an error on loading time.
Could you please complete that?
Thanks in advance,
Klaus |
|
| Back to top |
|
 |
Klaus
Joined: 12 May 2005 Posts: 256 Location: Münster, Germany
|
Posted: Wed Jul 22, 2009 10:57 am Post subject: |
|
|
Forgot to mention the function names:
lva_hWndInfo and lva_Info
Regards,
Klaus |
|
| Back to top |
|
 |
hd0202
Joined: 13 Aug 2006 Posts: 175 Location: Germany
|
Posted: Wed Jul 22, 2009 7:21 pm Post subject: |
|
|
Assume-static mode [v1.0.48+]: A function may be defined to assume that all its variables are static (except its parameters) by making its first line the word "static".
Gruß nach Münster
Hubert |
|
| Back to top |
|
 |
Drugwash
Joined: 07 Sep 2008 Posts: 608 Location: Ploiesti, RO
|
Posted: Wed Jul 22, 2009 7:35 pm Post subject: |
|
|
| Just for feedback: works in Win98SE but leaks GDI badly. Got no time to debug it now; maybe... someday... |
|
| Back to top |
|
 |
Klaus, nli Guest
|
Posted: Fri Jul 24, 2009 9:46 am Post subject: |
|
|
Hi, hd0202,
ja, das war's!
Gruß aus Münster,
Klaus |
|
| Back to top |
|
 |
BF2 Player
Joined: 27 Mar 2009 Posts: 68
|
Posted: Fri Jul 24, 2009 4:07 pm Post subject: |
|
|
This works for me, yet there are a few errors like:
- If you are selected on a row then click on a button or deselect from the List View, the color will disapear on the row until clicked on again.
- Sometimes a strange blue color is the listbox as a box, I think it is what Drugwash said, the GDI leaks.
- If you have a continual loop, the last color added will have a "flicker effect."
- TEXT COLORS ARE BGR not RGB! |
|
| Back to top |
|
 |
dadepp
Joined: 12 Jun 2008 Posts: 19
|
Posted: Sun Jul 26, 2009 12:03 am Post subject: |
|
|
| BF2 Player wrote: | This works for me, yet there are a few errors like:
- If you are selected on a row then click on a button or deselect from the List View, the color will disapear on the row until clicked on again. |
That is a standard behaviour of the windows control. Just create a normal listview select a line, tab to a button, and the selected line will have gone grey, to indicate that "something" is selected. And this grey overrides the colors. I don't know of a way to remove this problem, other than disallowing a row to be selected (is afaik possible).
| BF2 Player wrote: |
- Sometimes a strange blue color is the listbox as a box, I think it is what Drugwash said, the GDI leaks.
- If you have a continual loop, the last color added will have a "flicker effect." |
Well this puzzels me, since the only thing that might leak are the progressbars, since I draw them myself in memory and then paint them into the listview. The colors are done BY WINDOWS API. It is the same principle as Evl's code, except the OnMessage fires for every cell instead of every row. I have not encountered such behaviour on my system (XP/SP2)
| BF2 Player wrote: |
- TEXT COLORS ARE BGR not RGB! |
Hmm, my bad, but some color related windows apis differ from what msdn says. So I had them at first as RGB (according to msdn), then i noticed SOME are actually BGR. So after some testing i thought i had everything at RGB. The function "lva_VerifyColor" is supposed to fix all these inconsistencies, since I manually tell it to switch it around, if needed (according to my test).
Seems like I messed up, and a bit more testing is needed.
I hope i can find time to address these problems, and implement the rest of the ToDo-List. |
|
| Back to top |
|
 |
greynite
Joined: 17 May 2008 Posts: 31 Location: Dallas, TX
|
Posted: Mon Jul 27, 2009 1:04 am Post subject: |
|
|
First off, thanks for the awesome library! Per-cell control is very cool.
That said, I've managed to find some issues, generally around locking the interface up (or at least seeming to). What info could I provide to help isolate the issues?
Thanks,
Shawn |
|
| Back to top |
|
 |
ribbs2521
Joined: 28 Sep 2007 Posts: 225 Location: New York
|
Posted: Tue Aug 11, 2009 3:57 am Post subject: |
|
|
I am having a little trouble with this. I am using the mouse over tooltip code provided by Micahs (http://www.autohotkey.com/forum/viewtopic.php?t=33352). So, I already have the OnMessage command in my code. I understand I need to insert the code below into my program but I'm not sure where.
| Code: | if lva_hWndInfo(NumGet(lParam + 0),2)
return lva_OnNotifyProg(wParam, lParam, msg, hwnd) |
Do I put it in the main code or should I put it in the function that actually calls the LVA commands? |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|