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

ImageList_Draw Problem

80 views
Skip to first unread message

Samar Abbas Lotia

unread,
Feb 28, 1997, 3:00:00 AM2/28/97
to

Hi,

I have an imagelist with several icons in it and I am trying to paint it
onto a device context. The sequence of calls is as follows:

// Image list creation and adding of icons
HIMAGELIST handle = ImageList_Create(16,16, ILC_COLOR|ILC_MASK,1,2);

// loading icons
HICON icon = LoadIcon(hInst, MAKEINTRESOURCE(iconID));
ImageList_AddIcon(handle, icon);

I am able to extract the icon and display it, for e.g. on a dialog box so I
know that the icon is correctly loaded.

// test

HICON hIcon = ImageList_GetIcon(handle, 0, ILD_NORMAL);
// ... display icon
DestroyIcon(hIcon);

But when I try to paint the icon onto a device context I always get back
failure from the ImageList_Draw macro:

HDC hdc = CreateCompatibleDC(NULL);
HBITMAP hbm = CreateCompatibleBitmap(hdc, 100, 18);
SelectObject(hdc, hbm);

BOOL ret = ImageList_Draw(handle, 0, hdc, 0, 0, ILD_BLEND);

ASSERT(ret != FALSE); // always fails

I have tried the above call with the following drawing styles: ILD_NORMAL,
ILD_BLEND, ILD_MASK. They all seem to fail.

At this point I am completely stumped.

The other thing I tried was to extract the icon from the image list via
ImageList_GetIcon and then use the DrawIcon API call. But I figured out
that requires the icon to be directly loaded from a resource table (??)

I can write text onto my device context and then create an imagelist from
the bitmap (for drag/drop ops). So I guess that is working OK!

Anyway, any help would be much appreciated.

-Samar Lotia

Jonathan Schafer

unread,
Mar 1, 1997, 3:00:00 AM3/1/97
to

On 28 Feb 1997 19:02:21 GMT, "Samar Abbas Lotia" <slo...@platinum.com>
wrote:

This is all unnecessary. To draw from an imagelist, do

HDC hdc = GetDC(handle);
ImageList_Draw(handle, 0, hdc, 0, 0, xxx); //replace xxx with ILD_
drawing style

Jonathan Schafer

Samar Abbas Lotia

unread,
Mar 4, 1997, 3:00:00 AM3/4/97
to

I'm a little confused. What am I getting the DC for?

>
> This is all unnecessary. To draw from an imagelist, do
>
> HDC hdc = GetDC(handle);

Perhaps you're thinking I should get the DC of the window I wish to paint
on? I need to create a bitmap and paint on that so that I can, in turn,
construct an imagelist from the bitmap I have prepared and use the
imagelist's drag/drop functionality.

> ImageList_Draw(handle, 0, hdc, 0, 0, xxx); //replace xxx with ILD_
> drawing style
>
> Jonathan Schafer

If I'm going about this in a round-about fashion and there is a shortcut
which I am missing I would be grateful for any info.


jsch...@one.net

unread,
Mar 6, 1997, 3:00:00 AM3/6/97
to

"Samar Abbas Lotia" <slo...@platinum.com> wrote:

>I'm a little confused. What am I getting the DC for?
>>
>> This is all unnecessary. To draw from an imagelist, do
>>
>> HDC hdc = GetDC(handle);

>Perhaps you're thinking I should get the DC of the window I wish to paint
>on? I need to create a bitmap and paint on that so that I can, in turn,
>construct an imagelist from the bitmap I have prepared and use the
>imagelist's drag/drop functionality.

To create a bitmap to put into an image list, you first have to create
a window dc. I think your original post stated you were creating a
compatible dc from a hwnd. That will create a monochrome dc. You
need to create a window dc first, create a bitmap for the window, then
select the bitmap into the compatible dc. That will give you a color
bitmap for the compatible dc.

Once you've created the bitmap, you can bitblt into the compatible dc
your image. Then you can add the bitmap to your image list.

All this should be unnecessary if the format of the image you want to
add is already an icon. To add it, just create it with
ImageList_Create. Then add with the ImageList_Add.

If this doesn't answer your question, e-mail me exactly what you are
trying to do and I will try to answer it for you with a code sample.
I will be unavailable for a week but I'll answer it as soon as I get
back.

Jonathan Schafer

0 new messages