Click here to Skip to main content
15,881,856 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi!
I need to perform custom drawing of the items according to this rules:

1. Each first column of each item must perform owner drawing, e.g. use FillRect(), Rectangle() e.t.c.
2. Each second column of each item must perform default windows drawing.
3. And each third column of each item must perform custom drawing and fill its cell rectangle to desired color.

I found this example at msdn:
C++
LPNMLISTVIEW  pnm  = (LPNMLISTVIEW)lParam;

switch (pnm->hdr.code){
...
case NM_CUSTOMDRAW:

    LPNMLVCUSTOMDRAW  lplvcd = (LPNMLVCUSTOMDRAW)lParam;

    switch(lplvcd->nmcd.dwDrawStage) {

    case CDDS_PREPAINT :
        return CDRF_NOTIFYITEMDRAW;

    case CDDS_ITEMPREPAINT:
        SelectObject(lplvcd->nmcd.hdc,
                     GetFontForItem(lplvcd->nmcd.dwItemSpec,
                                    lplvcd->nmcd.lItemlParam) );
        lplvcd->clrText = GetColorForItem(lplvcd->nmcd.dwItemSpec,
                                          lplvcd->nmcd.lItemlParam);
        lplvcd->clrTextBk = GetBkColorForItem(lplvcd->nmcd.dwItemSpec,
                                              lplvcd->nmcd.lItemlParam);

/* At this point, you can change the background colors for the item
and any subitems and return CDRF_NEWFONT. If the list-view control
is in report mode, you can simply return CDRF_NOTIFYSUBITEMDRAW
to customize the item's subitems individually */
        ...

        return CDRF_NEWFONT;
	//  or return CDRF_NOTIFYSUBITEMDRAW;

    case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
        SelectObject(lplvcd->nmcd.hdc,
                     GetFontForSubItem(lplvcd->nmcd.dwItemSpec,
                                       lplvcd->nmcd.lItemlParam,
                                       lplvcd->iSubItem));
        lplvcd->clrText = GetColorForSubItem(lplvcd->nmcd.dwItemSpec,
                                             lplvcd->nmcd.lItemlParam,
                                             lplvcd->iSubItem));
        lplvcd->clrTextBk = GetBkColorForSubItem(lplvcd->nmcd.dwItemSpec,
                                                 lplvcd->nmcd.lItemlParam,
                                                 lplvcd->iSubItem));

/* This notification is received only if you are in report mode and
returned CDRF_NOTIFYSUBITEMDRAW in the previous step. At
this point, you can change the background colors for the
subitem and return CDRF_NEWFONT.*/
        ...
        return CDRF_NEWFONT;    
    }
...
}


And there are my questions:
1. Where I need to do owner drawing of first column? Here:

C++
case CDDS_ITEMPREPAINT:
{
//do custom drawing operation of first column here

return CDRF_NOTIFYSUBITEMDRAW;

}

and which result I need to return in this case: CDRF_NOTIFYSUBITEMDRAW or CDRF_NOTIFYSUBITEMDRAW | CDRF_SKIPDEFAULT?

or here:

C++
case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
{
   if(lplvcd->iSubItem == 0)
   {

   //do custom drawing operation of first column here

   return CDRF_SKIPDEFAULT;
   }

return CDRF_DODEFAULT;
}


2. What happens if here

case CDDS_ITEMPREPAINT:


I return the CDRF_NOTIFYSUBITEMDRAW? Does it mean that now I need to do drawing of all columns (including first column) of the item in case CDDS_SUBITEM | CDDS_ITEMPREPAINT handler?
Or I should draw first column in one case and subitems in another case? I do not understand.

Please explain me! Thanks!
Posted

1 solution

1. I didnt fizzle with this kind of Listview for some years, but I remember the first column (the item) is always handled separatly from the subitems.

2. somehow you can return that default drawing is done.

I recommand for details the article and code Neat Stuff to Do in List Controls Using Custom Draw from the great Michael Dunn, which will enlight you in the depths of this issue. It had helped me more than 5 years ago very well. ;-)

Pay attention to different Windows version - there maybe small differences
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900