Ok, i check some thinks on sp2, i fond the problem....
The tray is modified in windows XP SP2 :
see:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shell_notifyicon.aspPerhaps the function NIM_MODIFY do not work sometimes...
This is a solution (in delphi, ca be traduct without problem) :
(c)ManChesTer.
var Nicon : TnotifyIconData;
Function Put_Icon_On_Tray(IconName:String) : Boolean;
begin
Result:=true;
if not (Nicon.hicon<>0) then // if icon handle is nil
Nicon.hicon:=LoadIcon(HInstance, Pchar(IconName)); // load icon from resource
if Nicon.hicon=0 then // if still not loaded
begin
Nicon.hicon:=LoadIcon(HInstance, Pchar('ERROR_ICON')); // load error icon
Result:=false;
end;
Shell_notifyicon(NIM_delete,@Nicon); // delete old icon if already on the tray...
Application.Processmessages; // process all messages !!! important for some windows versions
If not Shell_notifyicon(NIM_Add,@Nicon) then // put the new icon on the tray
result:=false;
Application.Processmessages; // process all messages !!! important for some windows versions
end;
Function Remove_Icon_on_Tray:Boolean;
begin
Result:=False;
if Shell_notifyicon(NIM_delete,@Nicon) then // delete old icon if already on the tray...
Result:=True;
Application.Processmessages; // process all messages !!! important for some windows versions
end;
App sample:
If my_app_is_running then
if not Put_Icon_On_Tray('My_ICON') then
showmessage('Error Error on resource or notray in this windows');
else
if not Put_Icon_On_Tray('My_NOTWORK_ICON') then
showmessage('Error Error on resource or no valid tray in this windows');
To remove the icons:
if Remove_Icon_on_Tray then
showmessage('Tray Icon removed...')
else
Showmessage('Error when remove Tray icon');
To modify the icon:
if not Put_Icon_On_Tray('New_ICON') then
showmessage('Error Error on resource or no valid tray in this windows');
I hope this is helpfull for you....
In a friendly way,
ManChesTer.