Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help with using CImageList and CListCtrl.

80 views
Skip to first unread message

sul...@netcom.com

unread,
Aug 23, 1996, 3:00:00 AM8/23/96
to

Hi,
I'm having a problem displaying thumbnail images using CListCtrl.

Here's the scenario:
I have a directory in full of thumbnails that are saved as DIB and I'm
trying to display them using CListCtrl. I read in the thumbnails, generate
a CPalette, select the CPalette into a DC, and then generate a HBITMAP
using CreateDIBitmap passing in the DC. Once I've got the HBITMAP, I
create a CBitmap out of it using the CBitmap::FromHandle API and then added
this CBitmap into the CImageList which is set to the CListCtrl.
The CListCtrl did display the thumbnails correctly, but the palette is off.
How do I fix this? I was thinking of painting the thumbnails myself, but I
cannot create a CListCtrl with OWNERDRAW since the OWNERDRAW option is
only available in the REPORT view.

Any suggestion or solution to this?

--dani
sul...@netcom.com

Sandy Mckellar

unread,
Aug 26, 1996, 3:00:00 AM8/26/96
to


sul...@netcom.com wrote in article <sulemanD...@netcom.com>...

> The CListCtrl did display the thumbnails correctly, but the palette is
off.
> How do I fix this? I was thinking of painting the thumbnails myself, but
I
> cannot create a CListCtrl with OWNERDRAW since the OWNERDRAW option is
> only available in the REPORT view.
>
> Any suggestion or solution to this?
>
> --dani
> sul...@netcom.com
>

Just a thought here, but have you thought about Deriving a class from
CListCtrl, overriding the WM_PAINT message and selecting the palette into
the paint DC, and calling RealizePallette() function.

I now it sounds kinda like overkill, but the CImageList class is generally
used for status icons and the like that use the default pallette.

Hope it helps

David Ellis


jsch...@one.net

unread,
Aug 26, 1996, 3:00:00 AM8/26/96
to

I had the exact same problem. However I use Borland C++ instead of
VC++. Borland's response to WM_PAINT messages is to call
DefaultProcessing which passes the message on the the DefWndProc.
This meant that I couldn't just override the ::Paint function to set
the DC with the correct palette and the call the default ::Paint.
This meant overriding EvPaint to capture the message and painting the
entire window myself. That's right, there is no way to handle the
default processing since it will get its own DC without your palette.


Here's what I had to do: First, call BeginPaint. Then, modify the DC
as appropriate including setting the Font to MS Sans Serif 8 pt.
Then, in reverse order, get the bounding rect for each item. Use that
rect in a call to RectVisible to see if any of that rect is in the
invalidated area. If so, repaint the icon using the ImageListDraw
function. Then, put a white rectangle over the area where the text
was. this gets tricky as editing the text name to make it smaller
won't erase the old areas background. So, I had to get the bounding
rect for the item below, left, and right and then make a new rect
based on those to draw a white rect over the text. Also, for the item
below, the text may be larger than where the next icon starts. Make
sure you check for your bottom text rect being > than the top of the
icon rect of the item below. If so, use, the text rect. Then, draw
the text in. If this item is selected, you have to draw the text with
the system highlight color. Also, if the item is focused you'll need
to draw a focus rect around the text.

Sound like fun yet? There are different problems when you are in list
and report mode and even additional differences between list and
report mode. To say that this was the biggest pain in the A** would
be an understatement.

If MS had only allowed you to specify a palette to be used with an
imagelist, this wouldn't have had to happen.

Anyway, I got it all working except under one scenario. I can't make
the first item in the list window draw its highlight or remove its
highlight correctly. The first time I click on it, I get the WM_PAINT
message. however, if I click "NOWHERE", I don't get a WM_PAINT
message to remove the highlight. If I click another item, I get a
WM_PAINT to remove the highlight and draw the new selected item.
Then, if I select the first item again, I get a WM_PAINT to repaint
the old selected item but not the first item. It's very perplexing!

Jonathan Schafer


sul...@netcom.com wrote:

>Hi,
>I'm having a problem displaying thumbnail images using CListCtrl.

>Here's the scenario:
>I have a directory in full of thumbnails that are saved as DIB and I'm
>trying to display them using CListCtrl. I read in the thumbnails, generate
>a CPalette, select the CPalette into a DC, and then generate a HBITMAP
>using CreateDIBitmap passing in the DC. Once I've got the HBITMAP, I
>create a CBitmap out of it using the CBitmap::FromHandle API and then added
>this CBitmap into the CImageList which is set to the CListCtrl.

0 new messages