I am using Delphi 5.
I've add a trayicon in application and need to make the trayicon bright or change colour in different status. Anyone can help?
Thanks and Thanks.:$
Good outcome: ' component-based approach resolved the immediate issue for . That pattern — switching the tray component's TIcon at runtime — is the simplest and most robust solution. For anyone who wants the icon to appear "brighter" or to change colour depending on status, there are two practical, reliable strategies.
First (recommended): supply separate, pre-made icons for each state (normal, bright/active, warning, disabled). Make multi-image .ico files that include 16x16 and 32x32 versions and a 32-bit RGBA image with an alpha channel (and a monochrome mask for older Windows). Ship those icons as resources or files and swap them via the tray component. This avoids runtime pixel fiddling, preserves sharpness at small sizes and different DPI settings, and is the most compatible approach across Windows versions. A small corner badge (green/red dot) is often clearer than recolouring the whole icon at 16x16.
Second (when many dynamic colours or transitions are required): generate icons at runtime. Safe workflow: render the original HICON into a 32-bit bitmap, apply a per-pixel brightness/tint transform (blend RGB toward the desired colour or increase luminance), then create a new HICON from the modified bitmap (CreateIconIndirect/ICONINFO) and assign it to the tray. Important cautions: preserve alpha/mask so edges stay smooth; free any created HICON handles to avoid leaks; Explorer may cache icons, so if an update does not appear try re-adding the icon or toggling visibility to force a refresh.
Compatibility notes: older Windows treat icons differently (mask-based alpha), so include a proper mask for compatibility. For most apps the pre-made-variants approach is simplest and safest; use dynamic generation only when pre-made assets are impractical.
Jump to Post— Duoas 1,025How did you add it? (Did you use some component you got off the web or did you use the Shell_NotifyIcon function?)
Changing the icon is simply a matter of using NIM_MODIFY with a different icon handle in the hIcon field of the same NOTIFYICONDATA record you first used …
Jump to Post— Duoas 1,025No...
How exactly did you get an icon into the system tray to begin with?
Jump to Post— Duoas 1,025OK, I found the component on the web.
All you need is the TIcon you wish to display. You can load it by sticking a TImage component on your form, setting its visible property to false, and accessing the TImage's picture.icon property.
Then just set the icon property …
How did you add it? (Did you use some component you got off the web or did you use the Shell_NotifyIcon function?)
Changing the icon is simply a matter of using NIM_MODIFY with a different icon handle in the hIcon field of the same NOTIFYICONDATA record you first used to put the icon there to begin with.
If it was some component check the documentation...
Hope this helps.
Thanks for reply!
It is write the code as following?
TrayNotifyIcon1.Icon.Handle()
No...
How exactly did you get an icon into the system tray to begin with?
1. I have add a trayicon component into form , TrayNotifyIcon1: TTrayNotifyIcon
2. there is a property 'Icon', click into the 'Icon' property, I able to load icon image for it.
:?:
OK, I found the component on the web.
All you need is the TIcon you wish to display. You can load it by sticking a TImage component on your form, setting its visible property to false, and accessing the TImage's picture.icon property.
Then just set the icon property of the tTrayNotifyIcon component:
TrayNotifyIcon1.icon := Image1.picture.icon; The icon on the taskbar should update automatically. Keep in mind that if you may have to save the old icon if you want to restore it later.
Hope this helps.
BTW, were you able to get that last bit of code I gave you to work (to display the main form's button instead of the application's button on the taskbar)?
OK, I found the component on the web.
All you need is the TIcon you wish to display. You can load it by sticking a TImage component on your form, setting its visible property to false, and accessing the TImage's picture.icon property.
Then just set the icon property of the tTrayNotifyIcon component:
TrayNotifyIcon1.icon := Image1.picture.icon;The icon on the taskbar should update automatically. Keep in mind that if you may have to save the old icon if you want to restore it later.
Hope this helps.
Dear Friend,
Thanks so much! Your solution really help me a lot!!:icon_lol:
BTW, were you able to get that last bit of code I gave you to work (to display the main form's button instead of the application's button on the taskbar)?
This one not yet :(
What the request is totally hide the application (only trayicon but application or mian form whichsoever must nothing in task bar after call the hide function). However I tried and tried , after hide, application ( or main form?) still show in taskbar. :(
Make sure use use the code I gave you here and it will:
hide the application button from the taskbar (ApplicationActivate proc),
prevent it from reappearing (SysCommandMessage message proc), and
display a button for your main form (CreateParams proc) [but only when the main form is visible].
Good luck.
OH YEAAH!! IT WORK ! IT WORK!!
THANK you~~ ^O^
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.