如何手动更新托盘图标气球中的文本?
我使用 CoolTrayIcon 组件,但我可以手动修改它。我想要完成的是更新我刚刚创建的气球中的文本,而不实际创建另一个气球。问题是:
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;
我认为问题出在函数 HideBalloonHint 中,但我错了。我在 ShowBalloonHint 中评论了对 HideBalloonHint 的调用以更新文本,但它不起作用。
问题:如何只更新托盘气球中的文本而不创建另一个气球?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来只有当 InitIcon 为 true 时才会设置您的图标。将您的modifyIcon 过程更改为:
或在调用ModifyIcon 之前将InitIcon 设置为true。
编辑--
@IconData 使用的记录格式已记录在 MSDN 网站上以及 shell_NotifyIcon 调用。根据规范的内容,您应该能够传递与最初发送更新相同的记录,因为这不起作用,您可能必须采取另一种方法。
创建您的“自己的”气球提示表单,并将其放置在任务图标上方,然后直接更新。这将消除多个气球窗口。
It appears that your icon is only set if InitIcon is true. Change your modifyIcon procedure to read:
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.