Solved

load icon from resource file

Posted on 2001-06-26
5
1,069 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
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 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

19 Experts available now in Live!

Get 1:1 Help Now