diff --git a/src/NotifyIconWpf/TaskbarIcon.Declarations.cs b/src/NotifyIconWpf/TaskbarIcon.Declarations.cs index 45c8300..39bafb2 100644 --- a/src/NotifyIconWpf/TaskbarIcon.Declarations.cs +++ b/src/NotifyIconWpf/TaskbarIcon.Declarations.cs @@ -189,7 +189,7 @@ public Icon Icon icon = value; iconData.IconHandle = value == null ? IntPtr.Zero : icon.Handle; - Util.WriteIconData(ref iconData, NotifyCommand.Modify, IconDataMembers.Icon); + Util.WriteIconData(ref iconData, NotifyCommand.Modify, WithTrayToolTip(IconDataMembers.Icon)); } } diff --git a/src/NotifyIconWpf/TaskbarIcon.cs b/src/NotifyIconWpf/TaskbarIcon.cs index f07b01d..18b4bc0 100644 --- a/src/NotifyIconWpf/TaskbarIcon.cs +++ b/src/NotifyIconWpf/TaskbarIcon.cs @@ -91,6 +91,11 @@ public partial class TaskbarIcon : FrameworkElement, IDisposable /// public bool SupportsCustomToolTips => messageSink.Version == NotifyIconVersion.Vista; + /// + /// Indicates that ToolTipText should be displayed. + /// + private bool showSystemToolTip = false; + /// /// Checks whether a non-tooltip popup is currently opened. @@ -554,14 +559,6 @@ private void CreateCustomToolTip() Content = TrayToolTip }; } - else if (tt == null && !string.IsNullOrEmpty(ToolTipText)) - { - // create a simple tooltip for the ToolTipText string - tt = new ToolTip - { - Content = ToolTipText - }; - } // the tooltip explicitly gets the DataContext of this instance. // If there is no DataContext, the TaskbarIcon assigns itself @@ -574,6 +571,21 @@ private void CreateCustomToolTip() SetTrayToolTipResolved(tt); } + /// + /// Shell_NotifyIcon requires NIF_SHOWTIP to be specified for every call to Shell_NotifyIcon. + /// This modifies to include this if required. + /// + /// Passed through flags fo Shell_NotifyIcon. + /// Flags amended with NIF_SHOWTIP if required. + private IconDataMembers WithTrayToolTip(IconDataMembers flags) + { + if (showSystemToolTip) + { + flags |= IconDataMembers.UseLegacyToolTips; + } + + return flags; + } /// /// Sets tooltip settings for the class depending on defined @@ -583,6 +595,7 @@ private void WriteToolTipSettings() { const IconDataMembers flags = IconDataMembers.Tip; iconData.ToolTipText = ToolTipText; + showSystemToolTip = TrayToolTip is null; if (messageSink.Version == NotifyIconVersion.Vista) { @@ -597,7 +610,7 @@ private void WriteToolTipSettings() } // update the tooltip text - Util.WriteIconData(ref iconData, NotifyCommand.Modify, flags); + Util.WriteIconData(ref iconData, NotifyCommand.Modify, WithTrayToolTip(flags)); } #endregion @@ -871,7 +884,7 @@ private void ShowBalloonTip(string title, string message, BalloonFlags flags, In iconData.BalloonFlags = flags; iconData.CustomBalloonIconHandle = balloonIconHandle; - Util.WriteIconData(ref iconData, NotifyCommand.Modify, IconDataMembers.Info | IconDataMembers.Icon); + Util.WriteIconData(ref iconData, NotifyCommand.Modify, WithTrayToolTip(IconDataMembers.Info | IconDataMembers.Icon)); } @@ -884,7 +897,7 @@ public void HideBalloonTip() // reset balloon by just setting the info to an empty string iconData.BalloonText = iconData.BalloonTitle = string.Empty; - Util.WriteIconData(ref iconData, NotifyCommand.Modify, IconDataMembers.Info); + Util.WriteIconData(ref iconData, NotifyCommand.Modify, WithTrayToolTip(IconDataMembers.Info)); } #endregion @@ -975,7 +988,7 @@ private void CreateTaskbarIcon() | IconDataMembers.Tip; //write initial configuration - var status = Util.WriteIconData(ref iconData, NotifyCommand.Add, members); + var status = Util.WriteIconData(ref iconData, NotifyCommand.Add, WithTrayToolTip(members)); if (!status) { // couldn't create the icon - we can assume this is because explorer is not running (yet!) @@ -1007,7 +1020,7 @@ private void RemoveTaskbarIcon() return; } - Util.WriteIconData(ref iconData, NotifyCommand.Delete, IconDataMembers.Message); + Util.WriteIconData(ref iconData, NotifyCommand.Delete, WithTrayToolTip(IconDataMembers.Message)); IsTaskbarIconCreated = false; } }