mfc Clistctr 单元格嵌入图片(bmp)

示例:http://download.csdn.net/detail/zahxz/4652543

代码:

mfc Clistctr 单元格嵌入图片(bmp)
1 CListCtrl mCtrlist;//列表控件
2 CImageList m_ImageList;//图片列
头文件
mfc Clistctr 单元格嵌入图片(bmp)
m_ImageList.Create(20,20, TRUE|ILC_COLOR24, 3, 1);
    CBitmap bmp;
    bmp.LoadBitmap(IDB_OKOK);
    m_ImageList.Add(&bmp,RGB(255,255,255));
    bmp.DeleteObject();
    CBitmap bmp1;
    bmp1.LoadBitmap(IDB_StatusStop);
    m_ImageList.Add(&bmp1,RGB(255,255,255));
    bmp1.DeleteObject();
    CBitmap bmp2;
    bmp2.LoadBitmap(IDB_REPAIRING);
    m_ImageList.Add(&bmp2,RGB(255,255,255));
    bmp2.DeleteObject();
    CBitmap bmp3;
    bmp3.LoadBitmap(IDB_TOREPAIR);
    m_ImageList.Add(&bmp3,RGB(255,255,255));
    bmp3.DeleteObject();

    mCtrlist.SetImageList(&m_ImageList,   LVSIL_SMALL);

        mCtrlist.InsertColumn(0,"编号",LVCFMT_LEFT,0);
    mCtrlist.InsertColumn(1,"设备名称",LVCFMT_LEFT,100);
    mCtrlist.InsertColumn(2,"设备标签号",LVCFMT_LEFT,0);
    mCtrlist.InsertColumn(3,"当前状态",LVCFMT_LEFT,70);
    //mCtrlist.InsertColumn(4,"设备状态",LVCFMT_LEFT,0);
    mCtrlist.SetExtendedStyle(mCtrlist.GetExtendedStyle() | LVS_EX_FULLROWSELECT |LVS_EX_SUBITEMIMAGES|LVS_EX_GRIDLINES);
mCtrlist.SetItemText(item1,1,strname);
            mCtrlist.SetItemText(item1,2,strID);
mCtrlist.SetItem( item1 , 3,LVIF_TEXT|LVIF_IMAGE,strtext,index,0,0,0); 
View Code

注意:

1、样式为:mCtrlist.SetExtendedStyle(mCtrlist.GetExtendedStyle() | LVS_EX_FULLROWSELECT |LVS_EX_SUBITEMIMAGES|LVS_EX_GRIDLINES);

2、ImageList 创建的图片大小最好与实际图片大小一致,否则 会出现很多问题。比如:实际图片小于Imagelis创建的图片大小 导致图片不能显示,这个问题困扰了挺久。

mfc Clistctr 单元格嵌入图片(bmp)

上一篇:图片预加载技术(练习下)


下一篇:Stars(树状数组)