问题描述
嗨!
我需要按照以下规则自定义绘制物品:
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!
推荐答案
这篇关于ListView自定义绘制项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!