AutoHotkey Community

It is currently May 26th, 2012, 4:17 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 34 posts ]  Go to page 1, 2, 3  Next
Author Message
PostPosted: April 15th, 2009, 5:44 pm 
Offline

Joined: June 12th, 2008, 1:48 am
Posts: 27
Hi, I finally finished (ok only partly, but still it works 8) ) 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 :wink: (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:

Image

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 April 15th, 2009, 9:18 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 15th, 2009, 7:32 pm 
Hey! Looks cool! 8)
A screenshot would be nice, because people would understand right away what this is all about. :wink:


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: April 15th, 2009, 8:00 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Very nice! Thanks for sharing it.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 15th, 2009, 9:20 pm 
Offline

Joined: June 12th, 2008, 1:48 am
Posts: 27
Anonymous wrote:
Hey! Looks cool! 8)
A screenshot would be nice, because people would understand right away what this is all about. :wink:


Done. Thx for feedback

Laszlo wrote:
Very nice! Thanks for sharing it.


Hope it is usefull for some.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 18th, 2009, 2:01 pm 
Very nice indeed!

8)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2009, 7:23 am 
Offline

Joined: January 8th, 2007, 1:14 pm
Posts: 83
This is great, thanks!

P.s. That multiple icons per cell sounds like a plan. ;)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2009, 11:57 am 
Offline

Joined: May 12th, 2005, 8:20 am
Posts: 331
Location: Münster, Germany
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2009, 11:57 am 
Offline

Joined: May 12th, 2005, 8:20 am
Posts: 331
Location: Münster, Germany
Forgot to mention the function names:
lva_hWndInfo and lva_Info
Regards,
Klaus


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2009, 8:21 pm 
Offline

Joined: August 13th, 2006, 6:45 am
Posts: 354
Location: Germany
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 22nd, 2009, 8:35 pm 
Offline
User avatar

Joined: September 8th, 2008, 12:26 am
Posts: 1048
Location: Ploieşti, RO
Just for feedback: works in Win98SE but leaks GDI badly. Got no time to debug it now; maybe... someday...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 24th, 2009, 10:46 am 
Hi, hd0202,
ja, das war's!
Gruß aus Münster,
Klaus


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 24th, 2009, 5:07 pm 
Offline

Joined: March 27th, 2009, 10:48 pm
Posts: 71
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!


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 26th, 2009, 1:03 am 
Offline

Joined: June 12th, 2008, 1:48 am
Posts: 27
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 27th, 2009, 2:04 am 
Offline

Joined: May 17th, 2008, 5:00 am
Posts: 39
Location: Dallas, TX
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 11th, 2009, 4:57 am 
Offline

Joined: September 28th, 2007, 3:56 am
Posts: 279
Location: New York
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?


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 34 posts ]  Go to page 1, 2, 3  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: G. Sperotto, Yahoo [Bot] and 14 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group