News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

the listview color lost.

Started by six_L, April 12, 2014, 08:11:20 AM

Previous topic - Next topic

ragdog

#15
Hi

I use a Report listview an try to draw the color
I use this exmample from Fearless
http://masm32.com/board/index.php?topic=3106.msg32299#msg32299

but  send not any CDDS_ITEMPREPAINT Messages by add a item


.elseif uMsg == WM_NOTIFY

        mov ecx, lParam
        mov eax, ( [ecx].NMHDR.code)
        mov ebx, ( [ecx].NMHDR.hwndFrom)
        .IF ebx == hList ; in case we have other listview controls, we check which one we are going to modify nmcustomdraw for
       
            .IF eax == NM_CUSTOMDRAW
                mov ecx, lParam
                mov eax, (NMLVCUSTOMDRAW ptr[ecx]).nmcd.dwDrawStage
                .IF eax == CDDS_PREPAINT
               
                    mov eax, CDRF_NOTIFYITEMDRAW
                    ret
                     
                .ELSEIF eax == CDDS_ITEMPREPAINT   ;<<<<<<
                   invoke MessageBox,hWnd,0,0,0
                    mov eax, CDRF_NOTIFYSUBITEMDRAW
                    ret
                   
                .ELSEIF eax == CDDS_ITEMPREPAINT or CDDS_SUBITEM   ;<<<<<<
                   invoke MessageBox,hWnd,0,0,0
                    mov ecx, lParam
                    mov eax, (NMLVCUSTOMDRAW ptr[ecx]).nmcd.dwItemSpec ; listview item
                    mov nItem, eax ; could use a reg instead of a var for this i suppose
                    ...
                    ..



Can you tell me what is wrong?


Solved

but why must a use SetWindowLong

.if [edx].nmcd.dwDrawStage == CDDS_PREPAINT
         mov eax,CDRF_NOTIFYSUBITEMDRAW
@@:
invoke SetWindowLong,hWnd,DWL_MSGRESULT,eax
        ret
.elseIf [edx].nmcd.dwDrawStage == CDDS_ITEMPREPAINT
mov eax,CDRF_NOTIFYSUBITEMDRAW
jmp @B



Other example works without SetWindowLong

Regards,


Tedd

One more example of color listview (previously posted on the old board.)


As for the SetWindowLong requirement, it's necessary within DlgProc because the value returned in eax is to indicate whether the message was processed (whereas WndProc can return the value directly), so it's used as an alternative way to return a value without interfering with DlgProc's return value.
Potato2

six_L

hi,Tedd
there is some the flaw in codes.
.ELSEIF (eax==WM_CREATE)
invoke CenterScreen,hwnd
invoke InitCommonControls
invoke CreateWindowEx, NULL,ADDR LvClass,NULL,WS_CHILD or WS_VISIBLE or LVS_REPORT or LVS_SHOWSELALWAYS,0,0,0,0,hwnd,IDLISTVIEW,hInstance,NULL
mov hListview,eax
invoke SendMessage, hListview,LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_FULLROWSELECT,LVS_EX_FULLROWSELECT
invoke LvAddColumns,hListview,ADDR LvCols
invoke example_data
invoke example_data
invoke example_data

the method of fearless can store the listview color forever.
Say you, Say me, Say the codes together for ever.

ragdog

Hi Tedd

I have read i must use SetWindowlong if i have a resource Dialog and not virtual Dialog

And i put the WM_NOTIFY part from your example   in my project it not works without SetWindowLong why?

Regards,

Tedd

Quote from: six_L on December 22, 2014, 02:36:54 AM
hi,Tedd
there is some the flaw in codes.
.ELSEIF (eax==WM_CREATE)
invoke CenterScreen,hwnd
invoke InitCommonControls
invoke CreateWindowEx, NULL,ADDR LvClass,NULL,WS_CHILD or WS_VISIBLE or LVS_REPORT or LVS_SHOWSELALWAYS,0,0,0,0,hwnd,IDLISTVIEW,hInstance,NULL
mov hListview,eax
invoke SendMessage, hListview,LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_FULLROWSELECT,LVS_EX_FULLROWSELECT
invoke LvAddColumns,hListview,ADDR LvCols
invoke example_data
invoke example_data
invoke example_data

the method of fearless can store the listview color forever.
The flaw is caused by your modification.
As a simple example, the row index is used to look up the color in the palette 'brg_pal', which is only 5 items long. So the colors for the 6th item onwards are essentially undefined (come from junk in memory.)
You could either extend brg_pal to match the number of items so there are enough colors, or wrap the palette index to start from zero again.

It obviously depends on your application, but the aim should be to determine the color for each item according to your own purpose. It may be appropriate to use the item's index to decide its color, or you can assign persistent colors in lParam.
Potato2

Tedd

Quote from: ragdog on December 22, 2014, 05:49:35 AM
I have read i must use SetWindowlong if i have a resource Dialog and not virtual Dialog

And i put the WM_NOTIFY part from your example   in my project it not works without SetWindowLong why?
If you have a DialogProc, you must use SetWindowLong to return values for custom draw.
Potato2


six_L

hi,Tedd
QuoteIt may be appropriate to use the item's index to decide its color, or you can assign persistent colors in lParam.
:t
Thanks.
Say you, Say me, Say the codes together for ever.