I use CoolTrayIcon component,but I can modify it by hand.What I want to accomplish is to update the text in the balloon i just created without actually creating another balloon.Problem is:
function TCoolTrayIcon.ShowBalloonHint(Title: String; Text: String;
IconType: TBalloonHintIcon; TimeoutSecs: TBalloonHintTimeOut): Boolean;
// Show balloon hint. Return false if error.
const
aBalloonIconTypes: array[TBalloonHintIcon] of Byte =
(NIIF_NONE, NIIF_INFO, NIIF_WARNING, NIIF_ERROR);
begin
// Remove old balloon hint
HideBalloonHint;
// Display new balloon hint
with IconData do
begin
uFlags := uFlags or NIF_INFO;
StrLCopy(szInfo, PChar(Text), SizeOf(szInfo)-1);
StrLCopy(szInfoTitle, PChar(Title), SizeOf(szInfoTitle)-1);
TimeoutOrVersion.uTimeout := TimeoutSecs * 1000;
dwInfoFlags := aBalloonIconTypes[IconType];
end;
Result := ModifyIcon;
{ Remove NIF_INFO before next call to ModifyIcon (or the balloon hint will
redisplay itself) }
with IconData do
uFlags := NIF_ICON + NIF_MESSAGE + NIF_TIP;
end;
function TCoolTrayIcon.HideBalloonHint: Boolean;
// Hide balloon hint. Return false if error.
begin
with IconData do
begin
uFlags := uFlags or NIF_INFO;
StrPCopy(szInfo, '');
end;
Result := ModifyIcon;
end;
function TCoolTrayIcon.ModifyIcon: Boolean;
// Change icon or tooltip if icon already placed
begin
Result := False;
if InitIcon then
Result := Shell_NotifyIcon(NIM_MODIFY, @IconData);
end;
I thought the problem is in the function HideBalloonHint,but I was wrong.I commented the call to HideBalloonHint at ShowBalloonHint in other to update the text,but it didn't work.
Question:How to only update the text in the tray balloon without creating another balloon?
It appears that your icon is only set if InitIcon is true. Change your modifyIcon procedure to read:
function TCoolTrayIcon.ModifyIcon: Boolean;
// Change icon or tooltip if icon already placed
begin
Result := Shell_NotifyIcon(NIM_MODIFY, @IconData);
end;
or set InitIcon to true before calling ModifyIcon.
EDIT-- The record format used for @IconData is documented on the MSDN website along with the shell_NotifyIcon call. From what the specifications read, you should be able to pass the same record as originally sent to update, since that is not working you might have to take another approach.
Create your "own" balloon hint form, and position it just over your task icon, and update it directly. This would eliminate the multiple balloon windows.