dabestprogrammerindauniverse
asked on
load icon from resource file
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!
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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_MODIF Y, @IconNotifyData);
Regards, Geo
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_MODIF
Regards, Geo
Hi
How about simplifying it
var
Icons : TIcon;
begin
Icons := TIcons.Create(Self);
ImageList1.ResourceLoad(rt Icon, 'IconResource' ,clNone);
ImageList1.GetIcon(0, Icons);
end;
How about simplifying it
var
Icons : TIcon;
begin
Icons := TIcons.Create(Self);
ImageList1.ResourceLoad(rt
ImageList1.GetIcon(0, Icons);
end;
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
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
Var
AppIcon : TIcon;
begin
AppIcon := TIcon.Create;
AppIcon.Handle := LoadIcon(HInstance ,'ICON_2');
BitBtn1.Glyph := IconToBitmap(AppIcon);
AppIcon.Free;
end;
GL
Bug
Application.Icon.Handle := LoadIcon(hInstance, 'ICON_2');
Regards, Geo