在不使用CImageList的情况下在CListCtrl(Report View)中显示图像 [英] Show image in CListCtrl(Report View) without using CImageList

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

问题描述

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

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

推荐答案

您可以派生CListCtrl类,将其设置为owner-draw并实现DrawItem()函数.然后,所有绘图都必须由您的代码完成.

如果仅应使用代码绘制包含图像的单元格,并且应照常绘制文本单元格,则可以使用NM_CUSTOMDRAW通知:

You can derive a CListCtrl class, set it to owner-draw and implement the DrawItem() function. Then all drawing must be done by your code.

If only cells containing images should be drawn by your code, and text cells should be drawn as usual, you can use the NM_CUSTOMDRAW notification:

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)中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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