Solved

Using ICON resources at runtime

Posted on 2000-04-24
9
170 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

758 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

20 Experts available now in Live!

Get 1:1 Help Now