本文介绍了在不使用CImageList的情况下在CListCtrl(Report View)中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能找到不使用CImageList而不在CListCtrl(Report View)中显示图像的解决方案????

Can anyone find a solution to show image in CListCtrl(Report View) without using CImageList????

推荐答案

ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)

void CMyListCtrl::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
    *pResult = CDRF_DODEFAULT;
    // NMLVCUSTOMDRAW is for list views and list controls
    LPNMLVCUSTOMDRAW lplvcd = reinterpret_cast<lpnmlvcustomdraw>(pNMHDR);
    switch (lplvcd->nmcd.dwDrawStage)
    {
    // first message at begin of each paint cycle
    case CDDS_PREPAINT : 
        // notify of item specific paint operations
        *pResult = CDRF_NOTIFYITEMDRAW; 
        break;
    // triggered by returning CDRF_NOTIFYITEMDRAW from CDDS_PREPAINT
    case CDDS_ITEMPREPAINT : 
        *pResult = CDRF_NOTIFYSUBITEMDRAW; // handle each subitem separately
        break;
    // triggered by returning CDRF_NOTIFYSUBITEMDRAW from CDDS_ITEMPREPAINT
    case CDDS_ITEMPREPAINT | CDDS_SUBITEM :
        // check if cell at column/row contains an image
        if (HasImage(lplvcd->iSubItem, lplvcd->nmcd.dwItemSpec))
        {
            DrawImage(lplvcd); 
            *pResult = CDRF_SKIPDEFAULT; // skip it, has just been drawn
        }
    }
}

void CMyListCtrl::DrawImage(LPNMLVCUSTOMDRAW lplvcd)
{
    int nRow = static_cast<int>(lplvcd->nmcd.dwItemSpec);
    int nCol = lplvcd->iSubItem;
    // Can't use the rect from NMLVCUSTOMDRAW struct passed in OnCustomDraw.
    // That rect does not contain valid y-positions.
    // Additionally, the x-position may be clipped resulting
    //  in garbage on the screen when scrolling.
    CRect rc;
    GetSubItemRect(nRow, nCol, LVIR_LABEL, rc);
    // Draw your image here
}

</int></lpnmlvcustomdraw>


这篇关于在不使用CImageList的情况下在CListCtrl(Report View)中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 19:35