Click here to Skip to main content
15,921,793 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
1.create a MFC dialog Project;
2.add a CtrlList control ,then bind it to m_ListCtrl,set it display in ICon;
3.in dialog' List.h, I add a CImageList member. CImageList m_cImageListNormal;4.import a bitmap which is made up of 8 ICons;
5.in dialog OnInitDialog(),i write the following code;

    HIMAGELIST hList = ImageList_Create(32,32, ILC_COLOR8 |ILC_MASK , 8, 1);
m_cImageListNormal.Attach(hList);
CBitmap cBmp;
cBmp.LoadBitmap(IDB_IMAGES_NORMAL);
m_cImageListNormal.Add(&cBmp, RGB(255,255, 255));
cBmp.DeleteObject();
    m_ListCtrl.SetImageList(&m_cImageListNormal, LVSIL_NORMAL);
the result : it never display a icon.
I come from china, my english is poor.
I have not worked it out for 24 hours.

pity...
Posted
Updated 5-Jun-11 21:30pm
v3
Comments
Dalek Dave 6-Jun-11 3:30am    
Edited for Grammar, but your English is very good.

Take a look at this article[^]. It will give you all the details on how to work with an CListCtrl.

Hope this helps! :thumbsup:
 
Share this answer
 
Comments
Dalek Dave 6-Jun-11 3:30am    
Nice Link
Joan M 6-Jun-11 3:37am    
Thank you DD!, I've always found that this article from Matt Weagle is a great help to work with CListCtrl.
You will be able to see the icon only if you add some item to the list control.
Like
HIMAGELIST hList = ImageList_Create(32,32, ILC_COLOR8 |ILC_MASK , 8, 1);
m_cImageListNormal.Attach(hList);
CBitmap cBmp;
cBmp.LoadBitmap(IDB_IMAGES_NORMAL);
m_cImageListNormal.Add(&cBmp, RGB(255,255, 255));
cBmp.DeleteObject();
m_ListCtrl.SetImageList(&m_cImageListNormal, LVSIL_NORMAL);
m_ListCtrl.InsertItem(0,_T( "Test" ), 0 );


if you are not able to see the icon even after this, the problem can be the size of the bitmap IDB_IMAGES_NORMAL. change its size to exactly 32*32 or more than 32.
 
Share this answer
 
Comments
Dalek Dave 6-Jun-11 3:30am    
Good Call.
yes thank you for very much ,after i sleeped for a hour ,I are Preparing to go to bookstore to find solution, i come again ,i tried it again !,it turn out right...thank you very much. why i do't add m_ListCtrl.InsertItem(0,"Test:",0);
haha thank you again ! if you come china ,it 's my treat.
 
Share this answer
 
Comments
Resmi Anna 6-Jun-11 4:07am    
:)pls mark this thread as solved

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900