Solved

Using ICON resources at runtime

Posted on 2000-04-24
9
171 Views
Last Modified: 2012-05-04
Hello...
I have  Icons.rc with content:
a ICON "tools2.ICO"
b ICON "keys.ICO"
c ICON "movie.ICO"

I have compiled and added it to the  project... as norma resource file... I can see all icons in exe file using icon extractor...

So, tell me please, how to extract the resource at runtime and adsign, for sample, to  TImage.picture

Thank you for your help.
Sandis Viksna.
0
Comment
Question by:sviksna
  • 5
  • 4
9 Comments
 
LVL 15

Expert Comment

by:simonet
ID: 2743653
Here's an example of how to do it:

var
  ResDLLMod : Thandle;
begin

  ResDLLMod := LoadLibrary('resonly.dll');
  try
  // Always check if the module is loaded before
  // Trying to access it.
     if ResDLLMod=0 then
        raise Exception.Create('Cannont load resource library. Please check if RESONLY.DLL is in the application''s folder');
  image1.Picture.Icon.Handle := LoadIcon(ResDLLMod, 'RESEXPICON');
  finally  
    if ResDLLMod<>0 then
      FreeLibrary(ResDLLMod);
  end;
end;

RESEXPICON is the name of the icon resource as in the executable. If you're not accesing this in an external file, you can have everything in a single line (if the resources are in your executable):

  image1.Picture.Icon.Handle := LoadIcon(hInstance, 'a');

Yours,

Alex

0
 
LVL 15

Expert Comment

by:simonet
ID: 2743663
I meant my previous comment as an answer.

Yours,

Alex

0
 
LVL 1

Author Comment

by:sviksna
ID: 2743664
Yhanks, but i am using RES file... compiled in the same exe file...
all i need, i wna just get it out from there.. not from DLL file...

so, can u ansver for .res files?
0
 
LVL 15

Accepted Solution

by:
simonet earned 50 total points
ID: 2743674
Sure. It's just like I said in the last paragraph: if the resources are in the local exe (as opposed to an DLL or another EXE), you can simply use the line below to retrieve the icon resource:

image1.Picture.Icon.Handle := LoadIcon(hInstance, 'a');

Yours,

Alex
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:sviksna
ID: 2743678
I had heard about things like
TResourceStream and TFileStream;

there was some specification on create
but at runtime they shows some errors...

btw, it is in D4.. so everything should work...

help please

0
 
LVL 15

Expert Comment

by:simonet
ID: 2743692
You don't need to work with TResourceStream or TFileStream for that. Forget about them. LoadIcon works great.

What problems are you having? I've answered your question.

I can't tell what the problem is if I can't see your code or you give a detailed description of what you're doing.

Alex
0
 
LVL 1

Author Comment

by:sviksna
ID: 2743699
Well... thank you for so operative help:))) i were trying to solve this problem my own way very long time... thank you...

Sandis.
0
 
LVL 1

Author Comment

by:sviksna
ID: 2743701
What's about another type of images, like bitmap?
0
 
LVL 15

Expert Comment

by:simonet
ID: 2744011
Use LoadImage for that. LoadImage is documented in the Win32.hlp help file.

Alex
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now