Click to See Complete Forum and Search --> : A question about displaying image


shiyuwei
April 7th, 1999, 03:56 AM
I created an image list named m_imageList.after that,I add one bitmap and one icon to it.When I add items with the images to a list control,I met a problem. I found I can add icon successfully,but can't for bitmap.
I list the codes in the follow:

1. Create the image list with 100*100 icons and 32 bpp color depth
HIMAGELIST hImageList=ImageList_Create(100, 100, ILC_COLOR32, 0, 10);
m_imageList.Attach(hImageList);

// load the starting bitmap ("Loading..." and "Corrupt file")
CBitmap dummy;
dummy.LoadBitmap(IDB_NAILS100);
m_imageList.Add(&dummy, RGB(0, 0, 0));
m_imageList.Add(AfxGetApp()->LoadIcon(IDR_MAINFRAME));

// Use the image list in the list view
GetListCtrl().SetImageList(&m_imageList, LVSIL_NORMAL);
GetListCtrl().SetImageList(&m_imageList, LVSIL_SMALL);


2. Adding items to the list control
GetListCtrl().InsertColumn(0,"goodhead",LVCFMT_LEFT,-1,0);
int imgPos=0;
GetListCtrl().InsertItem(LVIF_IMAGE|LVIF_TEXT,0,"bitmap",0,0,imgPos,0);
imgPos=1;
GetListCtrl().InsertItem(LVIF_IMAGE|LVIF_TEXT,1,"icon",0,0,imgPos,0);

3. Result
I can see the icon image in the list,but where is the bitmap image? I don't know.

Thank you for your help!

Karl
April 7th, 1999, 07:35 AM
1) I don't understand why you use ImageList_Create, instead of MFC member functions, like this:

// if previouly created, use m_Imagelist.Detach()
m_Imagelist.Create(IDB_NAILS100, 100, ILC_COLOR32, RGB(0, 0, 0));

2) Following the documentation:
"An "image list" is a collection of same-sized images, each of which can be referred to by its zero-based index. "; So you can't have in the same ImageList a bitmap of 100x100 and an icon, which is probably 32x32;

3) you may check the number of images in your image list when you add one (return value of Add = previous image count)

HTH.

K.

Ash to ash and clay to clay, if the enemy doesn't get you, your own folk may.