Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

load icon from resource file

Posted on 2001-06-26
5
Medium Priority
?
1,352 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 300 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Integration Management Part 2
Suggested Courses

971 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