private void UpdateIcon(bool showIconInTray) { if (!base.DesignMode && (this._owner != null)) { if (!this._added) { if (!showIconInTray) { return; } if (this._icon == null) { return; } } lock (this) { this.window.LockReference(showIconInTray); Interop.NOTIFYICONDATA pnid = new Interop.NOTIFYICONDATA(); pnid.uFlags = 7; pnid.uCallbackMessage = 0x800; if (showIconInTray && (this.window.Handle == IntPtr.Zero)) { this.window.CreateHandle(new CreateParams()); } pnid.hWnd = this.window.Handle; pnid.uID = this._id; pnid.hIcon = this._icon.Handle; pnid.szTip = this._text; pnid.uTimeout = 3; if (showIconInTray && (this._icon != null)) { if (!this._added) { Interop.Shell_NotifyIcon(0, pnid); this._added = true; Interop.Shell_NotifyIcon(4, pnid); } else { Interop.Shell_NotifyIcon(1, pnid); } } else if (this._added) { Interop.Shell_NotifyIcon(2, pnid); this._added = false; } } } }
public void ShowBalloon(string title, string message, int seconds) { if (!this._added) { throw new ApplicationException("Must set TrayIcon to be visible before showing a balloon"); } if ((title == null) || (title.Length == 0)) { throw new ArgumentNullException("title"); } if (title.Length > 0x3f) { throw new ArgumentOutOfRangeException("Title is limited to 63 characters"); } if (message == null) { message = string.Empty; } else if (title.Length > 0xff) { throw new ArgumentOutOfRangeException("Message is limited to 255 characters"); } if ((seconds < 10) || (seconds > 30)) { throw new ArgumentOutOfRangeException("Seconds must be between 10 and 30"); } Interop.NOTIFYICONDATA pnid = new Interop.NOTIFYICONDATA(); pnid.uFlags = 0x10; pnid.hWnd = this.window.Handle; pnid.uID = this._id; pnid.szTitle = title; pnid.szInfo = message; pnid.uTimeout = seconds * 0x3e8; pnid.dwInfoFlags = 1; Interop.Shell_NotifyIcon(1, pnid); }