CListCtrl本身不支持,
你要非要如此可能需要重写一些东西.
我建议你如果不是要求很严格的话,使用控件MSFLXGRD.OCX, VC中很容易调用,
使起来也很方便.

解决方案 »

  1.   

    Custom Draw With List-View and Tree-View Controls
    Most common controls can be handled in essentially the same way. However, the list-view and tree-view controls have some features that require a somewhat different approach to custom draw.For Version 5.0 of the common controls, these two controls may display clipped text if you change the font by returning CDRF_NEWFONT. This behavior is necessary for backward compatibility with earlier versions of the common controls. If you want to change the font of a list-view or tree-view control, you will get better results if you send a CCM_SETVERSION message with the wParam value set to 5 before adding any items to the control.Custom Draw With List-View Controls
    Because list-view controls have subitems and multiple display modes, you will need to handle the NM_CUSTOMDRAW notification somewhat differently than for the other common controls.For report mode:The first NM_CUSTOMDRAW notification will have the dwDrawStage member of the associated NMCUSTOMDRAW structure set to CDDS_PREPAINT. Return CDRF_NOTIFYITEMDRAW. 
    You will then receive an NM_CUSTOMDRAW notification with dwDrawStage set to CDDS_ITEMPREPAINT. If you specify new fonts or colors and return CDRF_NEWFONT, all subitems of the item will be changed. If you want instead to handle each subitem separately, return CDRF_NOTIFYSUBITEMDRAW. 
    If you returned CDRF_NOTIFYITEMDRAW in the previous step, you will then receive an NM_CUSTOMDRAW notification for each subitem with dwDrawStage set to CDDS_SUBITEM | CDDS_PREPAINT. To change the font or color for that subitem, specify a new font or color and return CDRF_NEWFONT. 
    For the large icon, small icon, and list modes:The first NM_CUSTOMDRAW notification will have the dwDrawStage member of the associated NMCUSTOMDRAW structure set to CDDS_PREPAINT. Return CDRF_NOTIFYITEMDRAW. 
    You will then receive an NM_CUSTOMDRAW notification with dwDrawStage set to CDDS_ITEMPREPAINT. You can change the fonts or colors of an item by specifying new fonts and colors and returning CDRF_NEWFONT. Because these modes do not have subitems, you will not receive any additional NM_CUSTOMDRAW notifications. 
    An example of a list-view NM_CUSTOMDRAW notification handler is given in the next section.Using 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: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;    
        }
    ...
    }The first NM_CUSTOMDRAW notification has the dwDrawStage member of the NMCUSTOMDRAW structure set to CDDS_PREPAINT. The handler returns CDRF_NOTIFYITEMDRAW to indicate that it wishes to modify one or more items individually.If CDRF_NOTIFYITEMDRAW was returned in the previous step, the next NM_CUSTOMDRAW notification has dwDrawStage 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, return CDRF_NEWFONT. If the control is in report mode and you want to handle the subitems individually, return CDRF_NOTIFYSUBITEMDRAW.The final notification is only sent if the control is in report mode and you returned CDRF_NOTIFYSUBITEMDRAW 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. Return CDRF_NEWFONT to notify the control if the color or font was changed.
      

  2.   

    (1)重载CListCtrl的OnCustomdrawList()函数
    (2)afx_msg void OnCustomdrawList(NMHDR*, LRESULT*);
    (3) 消息 ON_NOTIFY(NM_CUSTOMDRAW, IDC_LIST, OnCustomdrawList)
    (4)
    void CToopView::OnCustomdrawList( NMHDR* pNMHDR, LRESULT* pResult )
    {
    CTime t_Time=CTime::GetCurrentTime();
    CString strTime;
    strTime.Format("%4d/%02d/%02d",t_Time.GetYear()
                           ,t_Time.GetMonth()
       ,t_Time.GetDay());
    NMLVCUSTOMDRAW* pLVCD = reinterpret_cast<NMLVCUSTOMDRAW*>( pNMHDR );    // Take the default processing unless we set this to something else below.
        *pResult = 0;    // First thing - check the draw stage. If it's the control's prepaint
        // stage, then tell Windows we want messages for every item.
        if ( CDDS_PREPAINT == pLVCD->nmcd.dwDrawStage )
            {
            *pResult = CDRF_NOTIFYITEMDRAW;
            }
        else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
            {
            // This is the prepaint stage for an item. Here's where we set the
            // item's text color. Our return value will tell Windows to draw the
            // item itself, but it will use the new color we set here.
            // We'll cycle the colors through red, green, and light blue.
            COLORREF crText;
    UINT     nRow;
    nRow=pLVCD->nmcd.dwItemSpec;
            if(m_List.GetItemText(nRow,11)<=strTime)
                crText = RGB(255,0,0);
            else
                crText = RGB(0,0,0);        // Store the color back in the NMLVCUSTOMDRAW struct.
           // pLVCD->clrText = crText;
    pLVCD->clrText=crText;
            // Tell Windows to paint the control itself.
            *pResult = CDRF_DODEFAULT;
            }
    }上面是我程序中的一段代码,仅功参考!
      

  3.   

    请问,在custom draw的listctrl里,能不能画类似treectrl里的那些+ -
    折叠符号?如果可以,怎么画,我会在其他贴子里给分的。
      

  4.   

    好好,[email protected]
    如果可以,我会开个帖子给分
      

  5.   

    好,[email protected]
    如果满足要求,我会开个帖子给分