Solved

Using ICON resources at runtime

Posted on 2000-04-24
9
172 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
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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
 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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