ListView自定义绘制项目 [英] ListView custom draw items

查看:169
本文介绍了ListView自定义绘制项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!

我需要按照以下规则自定义绘制物品:



1.每个第一列项目必须执行所有者绘图,例如使用FillRect(),Rectangle()等

2.每个项目的每个第二列必须执行默认的窗口绘图。

3.每个项目的每个第三列必须执行自定义绘图并将其单元格矩形填充到所需的颜色。



我在msdn上找到了这个例子:

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:

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;    
    }
...
}





还有我的问题:

1.我需要在哪里绘制第一栏?这里:





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

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

return CDRF_NOTIFYSUBITEMDRAW;



}



以及哪个结果我需要在这种情况下返回:CDRF_NOTIFYSUBITEMDRAW或CDRF_NOTIFYSUBITEMDRAW | CDRF_SKIPDEFAULT?



或者这里:




}

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

or here:

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

   //do custom drawing operation of first column here

   return CDRF_SKIPDEFAULT;
   }

return CDRF_DODEFAULT;
}





2.如果在这里会发生什么





2. What happens if here

case CDDS_ITEMPREPAINT:





我返回CDRF_NOTIFYSUBITEMDRAW?这是否意味着我现在需要在案例CDDS_SUBITEM中绘制项目的所有列(包括第一列) 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!

推荐答案

1。多年来我没有对这种Listview失败,但我记得第一列(项目)总是与子项目分开处理。



2.不知怎的,你可以返回默认绘图完成。



我建议详细了解文章和代码来自伟大的Michael Dunn的使用自定义绘制的列表控件中的整洁的东西,这将在这个问题的深处让你感到高兴。它在5年多前帮助了我很好。 ;-)



注意不同的Windows版本 - 可能存在细微的差异
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


这篇关于ListView自定义绘制项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆