【问题标题】:Display bmp image and text in List Control in MFC在 MFC 的列表控件中显示 bmp 图像和文本
【发布时间】:2016-04-24 23:44:18
【问题描述】:

我想在 MFC 的列表控件中显示 bmp 图像和文本, 它应该为不同的项目显示不同的bmp图像,但它为所有项目显示相同的bmp

这是我的代码

CListCtrl m_cParentListContrl;
CImageList m_ImageList[3];

m_ImageList[0].Create(IDB_BMP_LISTCTRL,128,1,RGB(150,150,100));
m_ImageList[1].Create(IDB_BMP_CHECKBOX,128,1,RGB(150,150,100));
m_ImageList[2].Create(IDB_BMP_COMBOBOX,128,1,RGB(150,150,100));

m_cParentListContrl.SetImageList(m_ImageList,LVSIL_NORMAL);

for(int i = 0 ; i < 3 ; i++)
{
    val.Format(_T("List ::%d"),i);
    //third parameter for index of image to be displayed
    // if that replaced by i to 0 then it display single image else not
    m_cParentListContrl.InsertItem(i,val,i);
}

谢谢

【问题讨论】:

  • 为什么要为三个独立的位图使用三个独立的图像列表?我认为您误解了图像列表如何为 CListCtrl 工作。我认为您想要一个包含三张图片的图片列表。
  • 我是 MFC 新手,你能举个小例子吗
  • 您可能认为您已经创建了一个包含 3 个图像的 ImageList,但没有!您确实创建了一个包含三个 ImageList 的数组!我从没想过它可以像你那样解释!

标签: visual-studio-2010 visual-c++ mfc dev-c++


【解决方案1】:

假设您不想将当前的 3 个位图减少为一个连续的带状位图,其中 3 个图像一个接一个:

CImageList m_ImageList;

m_ImageList.Create(128,128, ILC_COLOR24, 3, 1);
m_ImageList.SetImageCount(3);

CBitmap bmpListCtrl;
bmpListCtrl.LoadBitmap(IDB_BMP_LISTCTRL);
m_ImageList.Replace(0, bmpListCtrl, (CBitmap*)NULL);

CBitmap bmpCheckBox;
bmpCheckBox.LoadBitmap(IDB_BMP_CHECKBOX);
m_ImageList.Replace(1, bmpCheckBox, (CBitmap*)NULL);

CBitmap bmpComboBox;
bmpComboBox.LoadBitmap(IDB_BMP_COMBOBOX);
m_ImageList.Replace(2, bmpComboBox, (CBitmap*)NULL);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-20
    • 1970-01-01
    • 1970-01-01
    • 2018-04-23
    • 1970-01-01
    • 1970-01-01
    • 2016-04-05
    • 1970-01-01
    相关资源
    最近更新 更多