Board index » delphi » How to load icon resources from resource file?

How to load icon resources from resource file?

Hello!

Using the imagine editor I've created a ButtonBar.res file containing 11
icons.
Inside my source, I've added this resource file by using:

{$R ButtonBar.res}

Now I've got an imagelist MyImages and want to load the icons from the
resource into the list. I tried:

   MyImages.ResInstLoad(HInstance,rtIcon,'ICON_WINDOWCLOSE',clWhite);
   MyImages.ResourceLoad(rtIcon,'ICON_WINDOWCLOSE',clWhite);

MyImages.GetResource(rtIcon,'ICON_WINDOWCLOSE',32,[lrDefaultColor],clWhite);

But non of these loaded the icon named ICON_WINDOWCLOSE.

Does anyone know what I am doing wrong? Have never worked with Icon
resources before, I'm afraid.

Thanks, Patrick

 

Re:How to load icon resources from resource file?


Hello Patrick,

Try as the following, not tested.
MyBitmap.LoadFromResourceName(HInstance, MyResourceName);
MyImageList.AddMasked(MyBitmap, MyMaskColor);

--
Andrei Fomine.
DbAltGrid - multi-line layout, RTF and graphics of any kind in DBGrid.
Transfer@once - full-blown clipboard and drag-and-drop transfer in native
MS Office formats to/from any control.
www.quasidata.com

"Patrick M. Kolla" <patr...@kolla.de> wrote in message
news:3D01FB5C.FA42B70F@kolla.de...

Quote
> Hello!

> Using the imagine editor I've created a ButtonBar.res file containing 11
> icons.
> Inside my source, I've added this resource file by using:

> {$R ButtonBar.res}

> Now I've got an imagelist MyImages and want to load the icons from the
> resource into the list. I tried:

>    MyImages.ResInstLoad(HInstance,rtIcon,'ICON_WINDOWCLOSE',clWhite);
>    MyImages.ResourceLoad(rtIcon,'ICON_WINDOWCLOSE',clWhite);

MyImages.GetResource(rtIcon,'ICON_WINDOWCLOSE',32,[lrDefaultColor],clWhite
);
Quote

> But non of these loaded the icon named ICON_WINDOWCLOSE.

> Does anyone know what I am doing wrong? Have never worked with Icon
> resources before, I'm afraid.

> Thanks, Patrick

Re:How to load icon resources from resource file?


Hello Andrei,

Quote
> Try as the following, not tested.
> MyBitmap.LoadFromResourceName(HInstance, MyResourceName);
> MyImageList.AddMasked(MyBitmap, MyMaskColor);

Thanks a lot, that helped!
As I was using Icons, I had to create new resources as bitmaps (TIcon
doesn't have a LoadFromResourceName), and had to get
MyBitmap.Canvas.Pixels[0,0] as transparency color, but it was worth it
as it is now working :)

Patrick

Other Threads