Solved

load icon from resource file

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month7 days, 15 hours left to enroll

617 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