Board index » delphi » Loading an Icon from resource file

Loading an Icon from resource file

I have problems reading an icon from the .Res file of my project. I always
get the same exception 'can't find resource ****** ', where ******* is the
name of my icon as given in the Borland Image Editor.

Raphael Coeffic,
Itdesign.

 

Re:Loading an Icon from resource file


Sorry, i forgot to tell want i tried.
I tried to following :

1:
=
var
    bitmap: TBimap;
begin
    bitmap := TBitmap.Create;
    bitmap.LoadFromResourceName(HInstance,'MAINICON');
end;

2:
=
var
    bitmapS: TResourceStream;
begin
    bitmapS := TResourceStream.Create(HInstance,'MAINICON',PCHAR(RT_ICON));
end;

Every time i get an error. What did i wrong ????

Thanks,
Raphael Coeffic.

Re:Loading an Icon from resource file


"itd: Raphael Coeffic" <coef...@informatik.uni-tuebingen.de> wrote in
message news:8ar0vq$1j45@bornews.borland.com...

Quote
> Sorry, i forgot to tell want i tried.
> I tried to following :
> var
>     bitmap: TBimap;
...
> var
>     bitmapS: TResourceStream;

You say you're trying to load an icon but you didn't define a TIcon
anywhere.
Do you have an icon or a bitmap?

There are several links about using Resource Files with graphics at
http://www.efg2.com/Lab/Library/Delphi/Graphics/Algorithms.htm

In particular, look for the link to the Borland FAQ 2767D
"Storing icons in your application for use at runtime?"

--
efg

Earl F. Glynn     E-Mail:  EarlGl...@att.net
Overland Park, KS  USA

efg's Computer Lab:  http://www.efg2.com/Lab

Re:Loading an Icon from resource file


Earl F. Glynn <EarlGl...@att.net> schrieb in im Newsbeitrag:
8ar1eb$1...@bornews.borland.com...

Quote
> "itd: Raphael Coeffic" <coef...@informatik.uni-tuebingen.de> wrote in
> message news:8ar0vq$1j45@bornews.borland.com...
> > Sorry, i forgot to tell want i tried.
> > I tried to following :

> > var
> >     bitmap: TBimap;
> ...
> > var
> >     bitmapS: TResourceStream;

> You say you're trying to load an icon but you didn't define a TIcon
> anywhere.
> Do you have an icon or a bitmap?

The trouble is that i want to use an Icon but there no method concerning
resource files in the TIcon Interface .... that's why i only use bitmap
objects !

Raphael Coeffic,
Itdesign.

Re:Loading an Icon from resource file


Why not use this API call?

HICON LoadIcon(
    HINSTANCE hInstance, // handle of application instance
    LPCTSTR lpIconName  // icon-name string or icon resource
identifier
   );

itd: Raphael Coeffic <coef...@informatik.uni-tuebingen.de> wrote in
message news:8aqpap$1b411@bornews.borland.com...

Quote
> I have problems reading an icon from the .Res file of my project. I
always
> get the same exception 'can't find resource ****** ', where *******
is the
> name of my icon as given in the Borland Image Editor.

> Raphael Coeffic,
> Itdesign.

Re:Loading an Icon from resource file


Like Andy mentioned you can use a WinAPI call.
e.g.

procedure TForm1.FormPaint(Sender: TObject);
var
  Icon: TIcon;
begin
  Icon := TIcon.Create;
  try
    Icon.Handle := LoadIcon(HINSTANCE, 'MAINICON');
    Canvas.Draw(100,100, Icon);
  finally
    Icon.Free;
  end;
end;

HTH
Kerstin

itd: Raphael Coeffic schrieb:

Quote

> The trouble is that i want to use an Icon but there no method concerning
> resource files in the TIcon Interface .... that's why i only use bitmap
> objects !

> Raphael Coeffic,
> Itdesign.

Other Threads