Solved

load icon from resource file

Posted on 2001-06-26
5
1,211 Views
Last Modified: 2010-04-06
this is the code i use and i have an icon named 'icon_2' in my resource file but still it won't work! help!

AppIcon := TIcon.Create;
AppIcon.Handle := LoadIcon( HInstance ,'ICON_2');
TrayIcon1.Icon := AppIcon;
AppIcon.Free;

i want to change my program icon in the system tray when i click on it! help!
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 13

Accepted Solution

by:
Epsylon earned 100 total points
ID: 6230224
Try it with a default icon:

AppIcon := TIcon.Create;
AppIcon.Handle := LoadIcon( HInstance ,'IDI_APPLICATION');
TrayIcon1.Icon := AppIcon;
AppIcon.Free;

or shorter if possible

TrayIcon1.Icon.Handle := LoadIcon( HInstance ,'IDI_APPLICATION');


If these examples work then your icon is not properly stored in the exe...
0
 
LVL 17

Expert Comment

by:geobul
ID: 6231580
Hi,

Application.Icon.Handle := LoadIcon(hInstance, 'ICON_2');

Regards, Geo
0
 
LVL 17

Expert Comment

by:geobul
ID: 6231601
I didn't see that it's about the tray.

you must have a similar declaration in the main form:
  IconNotifyData : TNotifyIconData;

then :

  Application.Icon.Handle := LoadIcon(hInstance, 'ICON_2');
  IconNotifyData.hIcon := Application.Icon.Handle;
  Shell_NotifyIcon(NIM_MODIFY, @IconNotifyData);

Regards, Geo
0
 

Expert Comment

by:manata
ID: 6232516
Hi

How about simplifying it


var
  Icons : TIcon;
begin
  Icons := TIcons.Create(Self);
  ImageList1.ResourceLoad(rtIcon, 'IconResource' ,clNone);
  ImageList1.GetIcon(0, Icons);
end;
0
 
LVL 2

Expert Comment

by:bugroger
ID: 6232855
Hi,

Test if the icon is loaded.
Just add this code and a "BitBtn" to your form and
set "OnClick".
If it does not work it can be that "ICON_2" is not the
right resource name.


Function IconToBitmap(sIcon : TIcon) : TBitmap;
Begin
 Result          := TBitmap.Create;
 Result.Width    := sIcon.Width;
 Result.Height   := sIcon.Height;
 Result.Canvas.Draw(0,0, sIcon);

 //Sets the real width/height of the Icon
 Result.Width    := sIcon.Width;
 Result.Height   := sIcon.Height;
End;


procedure TForm1.BitBtn1Click(Sender: TObject);
Var
 AppIcon :  TIcon;
begin
 AppIcon        := TIcon.Create;
 AppIcon.Handle := LoadIcon(HInstance ,'ICON_2');
 BitBtn1.Glyph := IconToBitmap(AppIcon);
 AppIcon.Free;
end;

GL
Bug
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
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…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

734 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