Tray icon balloon

  • Thread starter Thread starter Peter Larsen [CPH]
  • Start date Start date
P

Peter Larsen [CPH]

Hi,

How do i programmatically close a tray icon balloon ?

The balloon is opened through component NotifyIcon.
I'm using VS2008, .Net 3,5.

BR
Peter
 
Hi Peter,

Thank you for posting the question.

Currently the NotifyIcon doesn't provide a direct way to close the balloon.
The ShowBalloonTip method will always check the tipText parameter is not
null or empty. However, in the underlying Win32 API Shell_NotifyIcon, the
only way to close the balloon tip is to set this string to null or removing
the notification icon itself.

So I think we have two choices here:

1. We still stick to the NotifyIcon class, use the following code to close
the balloon:

notifyIcon.Visible = false;
notifyIcon.Visible = true;

The Pro of this approach is easy to implement. Two lines of code.
The Con of this approach is we will get a flash of the icon while the
Visible property changes.

2. We get rid of the NotifyIcon class. Instead, we create our own
equivalent which supports programmatically closing of balloon tips.

The Pro of this approach is we will get fine control over the Notify Icon,
including closing the balloon tips without using the ugly hack.
The Con of this approach is we will have to write hundreds lines of code to
implement such a class just like the NotifyIcon class (the NotifyIcon class
itself is sealed so we cannot inherit from it).

Now the question is, which way do you prefer?

Best regards,

Jie Wang ([email protected], remove 'online.')

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Jie,

Thanks for your input.

The first solution, you mention, is the one i already use:

private void CloseBalloon()
{
if (balloonVisible)
{
notifyIconTray.Visible = false;
notifyIconTray.Visible = true;
}
}

The only difference is, that i only "hide" the balloon if its visible.
A downside is that the tray-icon shift position when change visibility.

A last strange thing is that NotifyIconTray seems to ignore the timeout
value (ShowBalloonTip()). Whatever I set as timeout value, it seems to stay
visible following some other unknown rules.
If the timeout value was working, i wouldn't have to close the balloon
manually.

/Peter
 
Hi Peter,

Yeah, setting the Visible property will cause a icon position change or at
least a flash. That's why I call it an "ugly" hack.

I'll try to feed some input into the product team about adding something
like a "HideBalloonTip" method in the future.

If you really want it badly, you can logon http://connect.microsoft.com/,
where you can get your own voices to the product team directly.

Regarding the timeout value, here is what I found (Shell_NotifyIcon
function & NOTIFYICONDATA structure, the underlying implementation of the
NotifyIcon class):

http://msdn.microsoft.com/en-us/library/bb773352(VS.85).aspx

**** Begin Quote ****

uTimeout

Note This member is deprecated as of Windows Vista. Notification display
times are now based on system settings.

The timeout value, in milliseconds, for a balloon ToolTip. The system
enforces minimum and maximum timeout values. Values specified in uTimeout
that are too large are set to the maximum value. Values that are too small
default to the minimum value. The system minimum and maximum timeout values
are currently set at 10 seconds and 30 seconds, respectively.

No more than one balloon ToolTip at a time can be displayed for the
taskbar. If an application attempts to display a balloon ToolTip when one
is already being displayed, the new ToolTip does not appear until the
existing ToolTip has been visible for at least the system minimum timeout
length. For example, a balloon ToolTip with uTimeout set to 30 seconds has
been visible for 7 seconds when another application attempts to display a
balloon ToolTip. If the system minimum timeout is 10 seconds, the first
ToolTip displays for an additional 3 seconds before being replaced by the
second ToolTip. If the user does not appear to be using the computer, the
system does not count this time towards the timeout.

**** End Quote ****

So basically we can't do much about the timeout value, especially in
Windows Vista. In this way, all applications will have consistent behavior
in the Notification Area, the users won't be confused.

I hope this make things clearer to you. But if you have further questions
regarding this issue, just let me know. I'll be happy to help.

Regards,

Jie Wang ([email protected], remove 'online.')

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Jie,

Thank you for your explanation and I apologies for my late reply.

BR
Peter
 
Hi Peter,

Thanks for the confirmation. :-)

Best Regards,

Jie Wang ([email protected], remove 'online.')

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top