The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: stanks on March 17, 2008, 09:32:17 PM

Title: Coloring text in List View control
Post by: stanks on March 17, 2008, 09:32:17 PM
I have read enough posts here to understand how to color the row in list view control. But i have another problem. Here is what i want to do.
On main window we have 2 list view controls. First have a list of names. Now when i click on a name in this LV, i want to show some info in second control. In DB i have a 2 fields. One is 'Date' and second is  'Locked' . Now if selected name in first LV is locked in DB on choosen date i will show that Date and text 'Locked' in red color. If it is not locked i want to show Date and text 'Not Locked' in green color. It is not problem to show only one row in some color, but one row in red another in green. How to do that? I am fighting with this all day, but still no result :(

Thanks
Title: Re: Coloring text in List View control
Post by: jj2007 on March 18, 2008, 01:14:24 AM
Doesn't sound impossible but without posting the relevant bits of your code you won't get answers. We are all geniuses but still struggling with mind-reading  :wink
Title: Re: Coloring text in List View control
Post by: stanks on March 19, 2008, 01:36:03 PM
This is my code:
...
.elseif eax==WM_NOTIFY
mov eax,wParam
mov edx,lParam
.if eax==IDC_LSV5
.if [edx].NMHDR.code==NM_CUSTOMDRAW
.if [edx].NMLVCUSTOMDRAW.nmcd.dwDrawStage==CDDS_PREPAINT ;NMLVCUSTOMDRAW
mov eax,CDRF_NOTIFYITEMDRAW
ret
.elseif [edx].NMLVCUSTOMDRAW.nmcd.dwDrawStage==CDDS_ITEMPREPAINT
.if zakljucan==0
mov [edx].NMLVCUSTOMDRAW.nmcd.uItemState,CDIS_DEFAULT
mov eax,[edx].NMLVCUSTOMDRAW.nmcd.dwItemSpec
RGB 255,0,0
mov [edx].NMLVCUSTOMDRAW.clrText,eax
.elseif zakljucan==1
mov [edx].NMLVCUSTOMDRAW.nmcd.uItemState,CDIS_DEFAULT
mov eax,[edx].NMLVCUSTOMDRAW.nmcd.dwItemSpec
RGB 0,128,0
mov [edx].NMLVCUSTOMDRAW.clrText,eax
.endif
ret
.else
mov eax,CDRF_DODEFAULT
ret
.endif
.endif
...

I don't know what i am doing wrong :( I checked values for variable zakljucan and this is ok. Row item value is ok too. I don't know what to check else. So simply i want this. User selects item from first listview, then get value of variable zakljucan. if it is 0 then color it red, else if it is 1 color it green. Something is missing or something is wrong  :(

Thanks
Title: Re: Coloring text in List View control
Post by: ragdog on March 19, 2008, 04:41:46 PM
hi

here is a example

http://www.masm32.com/board/index.php?topic=7858.0

greets
Title: Re: Coloring text in List View control
Post by: stanks on March 19, 2008, 08:09:37 PM
Thanks for reply but this is not what i wanted. I give up.
Title: Re: Coloring text in List View control
Post by: ragdog on March 19, 2008, 08:41:51 PM
don´t give up :U

give me a example as screenschot from anything program
what you mean
Title: Re: Coloring text in List View control
Post by: Jimg on March 19, 2008, 09:12:01 PM
I don't know how to do it in a listview, but if you can use a grid instead, it's pretty easy.  Let me know if you want to try a grid and I'll gen something up.
Title: Re: Coloring text in List View control
Post by: drizz on March 20, 2008, 03:56:01 AM
Pozdrav :) Stanks!

Listview is not working as you wan't because you are not setting the message result for dialog. In window proc values are returned in eax but for dialog the return value must be true/false and you must set result via SetWindowLong.

OnNotify proc uses ebx edi hWnd:HWND,idCtrl:dword, pnmh:dword
mov ebx,pnmh
.if idCtrl == IDC_LSV1
assume ebx:ptr NM_LISTVIEW
.if [ebx].hdr.code == NM_CUSTOMDRAW
assume ebx:ptr NMLVCUSTOMDRAW
rezultat equ edi
mov edi,CDRF_DODEFAULT
.if [ebx].nmcd.dwDrawStage == CDDS_PREPAINT
mov edi,CDRF_NOTIFYITEMDRAW
.elseif [ebx].nmcd.dwDrawStage == CDDS_ITEMPREPAINT
mov edi,CDRF_NOTIFYSUBITEMDRAW
.elseif [ebx].nmcd.dwDrawStage == (CDDS_SUBITEM or CDDS_ITEMPREPAINT)
.if [ebx].iSubItem == 0
mov [ebx].clrText,RGB(255,0,0)
.else
mov [ebx].clrText,RGB(0,255,0)
.endif
.endif
invoke SetWindowLong,hWnd,DWL_MSGRESULT,edi
return TRUE
.endif
.endif
assume ebx:nothing
return FALSE
OnNotify endp

...

.elseif eax==WM_NOTIFY
return $invoke(OnNotify,hWnd,wParam,lParam)


let me know if you don't have the macros i used...



Also for checking if value is locked or not i recommend you use LV_ITEM.lParam instead of global variables (zakljucan) or something...

Regards