Using Custom Draw

来源:互联网 发布:淘宝旅行客户端 编辑:程序博客网 时间:2024/06/05 08:06

 

This section contains examples that demonstrate how to implement custom draw.

The following code fragment is a portion of a WM_NOTIFY handler that illustrates how to handle custom draw notifications sent to a list-view control.

Copy
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 itemand any subitems and return CDRF_NEWFONT. If the list-view controlis in report mode, you can simply return CDRF_NOTIFYSUBITEMREDRAWto customize the item's subitems individually */        ...        return CDRF_NEWFONT;//  or return CDRF_NOTIFYSUBITEMREDRAW;    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 andreturned CDRF_NOTIFYSUBITEMREDRAW in the previous step. Atthis point, you can change the background colors for thesubitem and return CDRF_NEWFONT.*/        ...        return CDRF_NEWFONT;        }...}

The first NM_CUSTOMDRAW notification has the dwDrawStage member of theNMCUSTOMDRAW structure set to CDDS_PREPAINT. The handler returnsCDRF_NOTIFYITEMDRAW to indicate that it wishes to modify one or more items individually.

第一个NM_CUSTOMDRAW消息通知到来时,绘图状态会被设为CDDS_PREPAINT.。把返回值设为CDRF_NOTIFYITEMDRAW预示着你将要更改一个或者多个单个的ITEM.

If CDRF_NOTIFYITEMDRAW was returned in the previous step, the nextNM_CUSTOMDRAW notification hasdwDrawStage set to CDDS_ITEMPREPAINT. The handler retrieves the current color and font values. At this point, you can specify new values for small icon, large icon, and list modes. If the control is in report mode, you can also specify new values that will apply to all subitems of the item. If you have changed anything, returnCDRF_NEWFONT. If the control is in report mode and you want to handle the subitems individually, return CDRF_NOTIFYSUBITEMREDRAW.

如果上一次绘制的返回值为CDRF_NOTIFYITEMDRAW,那么绘图状态会被设为CDDS_ITEMPREPAINT。那么当运行到这个状态时,你可以更改ITEM 的颜色,图标。如果你的list control是report 模式,并且你想更改每个subitem,那你只需要将本次的返回值设为CDRF_NOTIFYSUBITEMREDRAW。

The final notification is only sent if the control is in report mode and you returned CDRF_NOTIFYSUBITEMREDRAW in the previous step. The procedure for changing fonts and colors is the same as that step, but it only applies to a single subitem. ReturnCDRF_NEWFONT to notify the control if the color or font was changed.

进入CDDS_SUBITEM | CDDS_ITEMPREPAINT状态,你可以更改每个subitem的值。记得返回默认。

原创粉丝点击