public override void Show() { lock (SyncRoot) { if (this.IsVisible) { return; } this.EnsureMessageSink(); for (var a = 0; a < 10; a++) { var data = NotifyIconData.Create(ID, this.MessageSink.Handle, this.Icon); if (ShellNotifyIcon(NotifyCommand.Add, ref data)) { Logger.Write(this, LogLevel.Debug, "Successfully created notify icon."); this.IsVisible = true; return; } else { ID++; } } Logger.Write(this, LogLevel.Error, "Failed to create notify icon, Shell_NotifyIcon reports failure."); } }
public override void Hide() { lock (SyncRoot) { if (!this.IsVisible) { return; } var data = NotifyIconData.Create(ID, this.MessageSink.Handle, this.Icon); if (ShellNotifyIcon(NotifyCommand.Delete, ref data)) { Logger.Write(this, LogLevel.Debug, "Successfully destroyed notify icon."); } else { Logger.Write(this, LogLevel.Error, "Failed to destroy notify icon, Shell_NotifyIcon reports failure."); } this.IsVisible = false; } }
public override bool Update() { lock (SyncRoot) { if (!this.IsVisible) { return(false); } var data = NotifyIconData.Create(ID, this.MessageSink.Handle, this.Icon); if (ShellNotifyIcon(NotifyCommand.Modify, ref data)) { Logger.Write(this, LogLevel.Debug, "Successfully updated notify icon."); return(true); } else { Logger.Write(this, LogLevel.Error, "Failed to update notify icon, Shell_NotifyIcon reports failure."); return(false); } } }