I am trying to draw each item in listview separately
I am using dialog, and thus I use this for returning value


Otherwise it wont return needed values.

Anyway, here is WM_NOTIFY handler in dialog proc

.elseif eax==WM_NOTIFY
mov edi,lParam
assume edi:ptr NMHDR
mov eax,[edi].hwndFrom
.if eax == hList

.if [edi].code == NM_CUSTOMDRAW
assume edi:ptr NMLVCUSTOMDRAW
.if [edi].nmcd.dwDrawStage == CDDS_PREPAINT
.elseif [edi].nmcd.dwDrawStage == CDDS_ITEMPREPAINT
mov [edi].clrText,000000FFh
mov [edi].clrTextBk,0000FFFFh
invoke DrawText,[edi].nmcd.hdc,CTEXT("test"),-1,addr [edi].nmcd.rc,DT_CENTER or DT_SINGLELINE or DT_END_ELLIPSIS or DT_VCENTER or DT_LEFT


But it doesn't work, there is no text at all. Later I figured out that RECT struct pointed located at .nmcd.rc is always zero... which is confusing since MSDN says

RECT structure that describes the bounding rectangle of the area being drawn. This member is initialized only by the CDDS_ITEMPREPAINT notification. Version 5.80. This member is also initialized by the CDDS_PREPAINT notification.

I am not sure what is the problem actually and how to solve this.

One more question, when painting items in listview, how can I determine which item is painted, where can I get item's index? For example, I'd like to paint item depending on its text or lParam.
Posted on 2003-12-22 15:53:19 by Mikky
Hi, Mikky :)
I think your dialog box handler should return TRUE, or the return value from SetWindowLong will be ignored. But while you're returning a wrong value, it's nonzero so it should work just the same... just in case, try it out and see what happens.

The lParam is there in the NMLVCUSTOMDRAW... Also you can simply send a message to the listview to get the info you need. I'm sure the item number is there in the structure as well.

Here's a sample custom drawn listview code:

Posted on 2003-12-23 16:54:01 by QvasiModo
Hi Quasi,
I tried this

mov eax,1

but still doesnt work.
Problem is that RECT I receve with NMLVCUSTOMDRAW is always zeroed out, all values in it are zero.
DrawText() returns ok, so text is drawn but rectangle height and width are zero.
If I manually do this

mov [edi].nmcd.rc.bottom,20
mov [edi].nmcd.rc.right,50

Then text is drawn and visible, but ofcourse not in the right place.

Maybe I am missing some style from listview/dialog or somthing like that?
Or, is there any way to get rectangle coordinates of specific listview item? This might solve the problem.
Posted on 2003-12-23 18:48:33 by Mikky
Mhm.. it should work... :confused:
I'll try to do it tomorrow (back home), if I get it to work I'll post it here.
Posted on 2003-12-23 18:53:25 by QvasiModo
Thanks Qvasi, I appreciate your help
I will try to figure out too but I am getting out of ideas :sweat:
Posted on 2003-12-23 20:08:47 by Mikky
Hey Quasi,
Any luck?

I found that this macro will get items rectangle - ListView_GetItemRect, so this could solve the problem (except if this macro does not return zeros in rectange like this notify msg do)
I havent had chance to try all this but will do tomorow, the question is how to retrive items index from custom message notification, without complicating things with lParam.
Posted on 2003-12-25 19:25:30 by Mikky
No luck yet... but I didn't have much time either. I'll post whenever I get some results.
I'll take a look at that macro too. :)
Posted on 2003-12-26 11:13:04 by QvasiModo
This is the best I've got so far. I could get the items to be drawn, but not the subitems.
I've also noticed that the NMLVCUSTOMDRAW stucture is most unreliable, some members are not initialized or contain wrong values! :mad:
I could not manage to get subitem notifications, or LVN_ACTIVATE messages either.
Here's the source:
Posted on 2003-12-27 12:40:17 by QvasiModo