tags:

views:

778

answers:

4

I want to list the thumbnails of a set of photos in a listctrl. But the only way to achieve this is to use the setImageList method to bind a image list to the CListCtrl object and insert items like this: InsertItem (int nItem, LPCTSTR lpszitem, int nImage). I also must modify the listctrl's style by ModifyStyle(LVS_TYPEMASK, LVS_ICON) to force it to display the icon of each item.

I don't think this approach a good way to achieve my goal. Can I add items of bitmap or other image objects directly in a CListCtrl?

Thank you very much!

+2  A: 

Why do you think it's not a good approach? Your other options are to make it an owner-drawn control and render the images yourself, or use a callback for the images via CListCtrl::SetCallbackMask.

List controls use image lists for a reason; the bitmaps are stored in a way that is most efficient for rendering the list control. You would be pretty hard pressed to do it any better.

Gerald
It's possible OP is wanting to display these images as the *primary content* of the list control, in which case the per-item images may not fit his look and feel and in which case, as you point out, he needs to do custom-draw.
James D
A: 

Thanks! But my situation is rather complicated under which each thumbnail image in my listctrl must provide several features such as changing size accoriding to the slider. Can ImageList realize these user-defined functionalities?

Ah, nope there's probably no way to do that with the stock CListCtrl. You'll have to make it an owner drawn control and do the rendering yourself. It shouldn't be that difficult to do though.
Gerald
Sounds like I have to use owner-draw. Thank you very much!
+1  A: 

Given that you need these sorts of extended features, sounds like you must use owner-draw. A good example is here. It doesn't show how to draw the image, but once you've got the owner-draw procedure set up you should be able to use typical BitBlts to paint the images.

James D
A: 

There's another question arose: Can I changed an item's size (width and height) in the CListCtrl?

You can only change the size of all of the items, not individual ones. You'll need to implement MeasureItem. There's some quirks about how you can use that with CListCtrl, see <a href="http://www.codeproject.com/KB/list/changerowheight.aspx?display=Print">this article</a>
Gerald
oops, guess the links don't work like that in the comments. See http://www.codeproject.com/KB/list/changerowheight.aspx?display=Print
Gerald