Example #1
0
        /// <summary>
        /// Sets the focus to taskbar
        /// Recommended to call when context menu canceled
        /// </summary>
        public void SetFocus()
        {
            var data = new NOTIFYICONDATA();

            InitNotifyIconData(ref data);
            Shell_NotifyIcon(NotifyIconMessages.SetFocus, data);
        }
        /// <summary>
        /// Shows a balloon tip over the item with the specified icon,
        /// message and title for the specified timeout interval.  ME/2000 or above only.
        /// </summary>
        /// <param name="message">Balloon tip message to display (max 256 chars)</param>
        /// <param name="icon">Icon to show</param>
        /// <param name="title">Title of balloon tip (max 64 chars)</param>
        /// <param name="timeOut">Timeout in milliseconds.  The system restricts timeouts
        /// to the range 10,000 - 30,000 ms.</param>
        public void ShowBalloonTip(
            string message,
            NotifyIconBalloonIconFlags icon,
            string title,
            int timeOut
            )
        {
            if (this.inSysTray)
            {
                // show the balloon tip:
                NOTIFYICONDATA ids = newNotifyIconData();
                ids.uFlags            = NotifyIconDataFlags.NIF_INFO;
                ids.szInfo            = message;
                ids.szInfoTitle       = title;
                ids.dwInfoFlags       = icon;
                ids.uTimeoutOrVersion = timeOut;

                int ret = Shell_NotifyIcon(
                    NotifyIconMessages.NIM_MODIFY,
                    ref ids);
            }
            else
            {
                // should throw exception?
            }
        }
 /// <summary>
 /// Sets focus to your icon in the SysTray.  Should be called
 /// once you've completed a UI operation such as a menu.
 /// ME/2000 or above only.
 /// </summary>
 public void SetFocus()
 {
     NOTIFYICONDATA ids = newNotifyIconData();
     int            ret = Shell_NotifyIcon(
         NotifyIconMessages.NIM_SETFOCUS,
         ref ids);
 }
Example #4
0
        private void UpdateIcon(bool remove = false)
        {
            var iconData = new NOTIFYICONDATA()
            {
                hWnd             = Win32Platform.Instance.Handle,
                uID              = _uniqueId,
                uFlags           = NIF.TIP | NIF.MESSAGE,
                uCallbackMessage = (int)CustomWindowsMessage.WM_TRAYMOUSE,
                hIcon            = _icon?.HIcon ?? new IconImpl(new System.Drawing.Bitmap(32, 32)).HIcon,
                szTip            = _tooltipText ?? ""
            };

            if (!remove)
            {
                iconData.uFlags |= NIF.ICON;

                if (!_iconAdded)
                {
                    Shell_NotifyIcon(NIM.ADD, iconData);
                    _iconAdded = true;
                }
                else
                {
                    Shell_NotifyIcon(NIM.MODIFY, iconData);
                }
            }
            else
            {
                Shell_NotifyIcon(NIM.DELETE, iconData);
                _iconAdded = false;
            }
        }
Example #5
0
        /// <summary>
        /// addNotifyIcon
        /// </summary>
        /// <param name="tip">message tool tip</param>
        /// <returns>true on success</returns>
        private bool addNotifyIcon(string tip)
        {
            shellRestart = RegisterWindowMessage("TaskbarCreated");
            NOTIFYICONDATA data = getNOTIFYICONDATA(icon.Handle, NIF_MESSAGE | NIF_ICON | NIF_TIP | NIF_INFO, tip, null, null, BalloonType.None);

            return(Shell_NotifyIcon(NIM_ADD, ref data));
        }
Example #6
0
        private void Animate_NextIcon(object sender, EventArgs e)
        {
            if (m_imgList != null && m_imgList.Images.Count > 0)
            {
                int iCount = m_imgList.Images.Count;

                if (m_iImageIndex < iCount - 1)
                {
                    m_iImageIndex++;
                }
                else
                {
                    m_iImageIndex = 0;
                }

                NOTIFYICONDATA data = CreateNotifyStruct(NotifyFlags.NIF_ICON |
                                                         NotifyFlags.NIF_TIP |
                                                         NotifyFlags.NIF_STATE);

                Bitmap bmp = new Bitmap(m_imgList.Images[m_iImageIndex], 16, 16);
                data.hIcon = bmp.GetHicon();

                WindowsAPI.Shell_NotifyIcon(NotifyCommand.NIM_MODIFY, ref data);
            }
        }
        public SafeNotifyIconData(NOTIFYICONDATA nid)
        {
            cbSize           = nid.cbSize;
            hWnd             = (IntPtr)nid.hWnd;
            uID              = nid.uID;
            uFlags           = nid.uFlags;
            uCallbackMessage = nid.uCallbackMessage;

            try
            {
                hIcon = (IntPtr)nid.hIcon;
            }
            catch (Exception e)
            {
                ShellLogger.Error($"SafeNotifyIconData: Unable to convert icon handle: {e.Message}");
            }

            szTip        = nid.szTip;
            dwState      = nid.dwState;
            dwStateMask  = nid.dwStateMask;
            szInfo       = nid.szInfo;
            uVersion     = nid.uVersion;
            szInfoTitle  = nid.szInfoTitle;
            dwInfoFlags  = nid.dwInfoFlags;
            guidItem     = nid.guidItem;
            hBalloonIcon = nid.hBalloonIcon;
        }
 private void setMessage(ref NOTIFYICONDATA ids)
 {
     if (this.toolTip.Length > 0)
     {
         ids.uFlags |= NotifyIconDataFlags.NIF_TIP;
         ids.szTip   = this.toolTip;
     }
 }
Example #9
0
 internal MyNotifyIcon()
 {
     window                    = new MyNativeWindow(this);
     iconData                  = new NOTIFYICONDATA();
     iconData.cbSize           = Marshal.SizeOf(typeof(NOTIFYICONDATA));
     iconData.hWnd             = window.Handle;
     iconData.uID              = 1;
     iconData.uCallbackMessage = WM_NOTIFYICONCALLBACK;
 }
Example #10
0
        /// <summary>
        /// Method update current state of tray icon
        /// </summary>
        private void Update()
        {
            NOTIFYICONDATA data = CreateNotifyStruct(NotifyFlags.NIF_ICON |
                                                     NotifyFlags.NIF_TIP |
                                                     NotifyFlags.NIF_STATE);

            WindowsAPI.Shell_NotifyIcon(NotifyCommand.NIM_MODIFY, ref data);

            RefreshSystemTray();
        }
Example #11
0
        public void ShowBalloon(string title, string text, NotifyInfoFlags type, uint timeoutInMilliSeconds)
        {
            NOTIFYICONDATA data = CreateNotifyStruct(NotifyFlags.NIF_INFO, true);

            data.uTimeoutOrVersion = timeoutInMilliSeconds; // this value does not seem to work - any ideas?
            data.szInfoTitle       = title;
            data.szInfo            = text;
            data.dwInfoFlags       = type;

            WindowsAPI.Shell_NotifyIcon(NotifyCommand.NIM_MODIFY, ref data);
        }
Example #12
0
        private void TrayMessage(IntPtr hwnd, int dwMessage, uint uID, IntPtr hIcon)
        {
            NOTIFYICONDATA notdata = new NOTIFYICONDATA();

            notdata.cbSize = 152;
            notdata.hIcon = hIcon;
            notdata.hWnd = hwnd;
            notdata.uCallbackMessage = WM_NOTIFY_TRAY;
            notdata.uFlags = NIF_MESSAGE | NIF_ICON;
            notdata.uID = uID;

            int ret = Shell_NotifyIcon(dwMessage, ref notdata);
        }
Example #13
0
        private void TrayMessage(IntPtr hwnd, int dwMessage, uint uID, IntPtr hIcon)
        {
            NOTIFYICONDATA notdata = new NOTIFYICONDATA();

            notdata.cbSize           = 152;
            notdata.hIcon            = hIcon;
            notdata.hWnd             = hwnd;
            notdata.uCallbackMessage = WM_NOTIFY_TRAY;
            notdata.uFlags           = NIF_MESSAGE | NIF_ICON;
            notdata.uID = uID;

            int ret = Shell_NotifyIcon(dwMessage, ref notdata);
        }
        /// <summary>
        /// Private helper function that updates the System Tray Icon.
        /// </summary>
        /// <param name="showIcon">If true the icon is shown in the System Tray based on the
        /// current property values. If false the icon is removed from the System Tray.</param>
        private void UpdateIcon(bool showIcon)
        {
            if (this.DesignMode)
            {
                return;
            }

            //IntSecurity.UnrestrictedWindows.Demand();

            // Initialize the structure
            NOTIFYICONDATA nid = new NOTIFYICONDATA();

            nid.uCallbackMessage = Win32.WM_USER_TRAY;
            nid.uVersion         = Win32.NOTIFYICON_VERSION;
            nid.cbSize           = Marshal.SizeOf(typeof(NOTIFYICONDATA));
            nid.uFlags           = Win32.NIF_MESSAGE;
            nid.hwnd             = this._Messages.Handle;
            nid.uID   = 0;
            nid.hIcon = IntPtr.Zero;
            nid.szTip = null;

            // If we have a valid icon, make sure we send it.
            if (this.Icon != null)
            {
                nid.uFlags = nid.uFlags | Win32.NIF_ICON;
                nid.hIcon  = this.Icon.Handle;
            }

            // Pass our Text property as the tooltip
            nid.uFlags = nid.uFlags | Win32.NIF_TIP;
            nid.szTip  = this.Text;

            if (showIcon && this.Icon != null)
            {                   // Show the icon
                if (!this._Added)
                {               // We don't already have an Icon so we need to creat one.
                    Win32.Shell_NotifyIcon(Win32.NIM_ADD, ref nid);
                    this._Added = true;
                    //return;
                }
                else                    // We already have an Icon so we'll just modify it.
                {
                    Win32.Shell_NotifyIcon(Win32.NIM_MODIFY, ref nid);
                }
            }
            else if (this._Added)
            {                   // The caller wants to remove the icon and we have an existing icon to remove
                Win32.Shell_NotifyIcon(Win32.NIM_DELETE, ref nid);
                this._Added = false;
            }
        }
Example #15
0
        private void ShowBalloonTipLegacy(string caption, string text, NotifyIconIcons balloonIcon, bool noSound = false, bool realTime = false)
        {
            var data = new NOTIFYICONDATA();

            InitNotifyIconData(ref data);
            data.szInfoTitle = caption;
            data.szInfo      = text;
            data.uFlags      = NotifyIconFlags.Info;
            if (realTime)
            {
                data.uFlags |= NotifyIconFlags.RealTime;
            }
            switch (balloonIcon)
            {
            case NotifyIconIcons.None:
                data.dwInfoFlags = NotifyIconInfoFlags.IconNone;
                break;

            case NotifyIconIcons.Error:
                data.dwInfoFlags = NotifyIconInfoFlags.IconError;
                break;

            case NotifyIconIcons.Info:
                data.dwInfoFlags = NotifyIconInfoFlags.IconInfo;
                break;

            case NotifyIconIcons.Warning:
                data.dwInfoFlags = NotifyIconInfoFlags.IconWarning;
                break;

            case NotifyIconIcons.User:
                data.dwInfoFlags = NotifyIconInfoFlags.IconUser;
                break;
            }

            data.dwInfoFlags |= NotifyIconInfoFlags.RespectQuietTime;
            if (UseLargeIcons)
            {
                data.dwInfoFlags |= NotifyIconInfoFlags.LargeIcon;
            }
            if (noSound)
            {
                data.dwInfoFlags |= NotifyIconInfoFlags.NoSound;
            }

            if (!Shell_NotifyIcon(NotifyIconMessages.Modify, data))
            {
                throw new Win32Exception("Shell_NotifyIcon failed");
            }
        }
Example #16
0
        public NotifyIcon()
        {
            _dispatcher = new WindowDispatcher(this);

            _notifyIconData                  = NOTIFYICONDATA.Default;
            _notifyIconData.hwnd             = _dispatcher.Handle;
            _notifyIconData.uFlags           = (int)(NIF.TIP | NIF.MESSAGE);
            _notifyIconData.szTip            = string.Empty;
            _notifyIconData.szInfo           = string.Empty;
            _notifyIconData.szInfoTitle      = string.Empty;
            _notifyIconData.dwState          = 2;
            _notifyIconData.uCallbackMessage = WM_NOTIFYICON;

            NativeMethods.Shell_NotifyIcon(NIM.ADD, ref _notifyIconData);
        }
Example #17
0
File: test.cs Project: mono/gert
	private static void test ()
	{
		Form form = new Form ();

		NOTIFYICONDATA nid = new NOTIFYICONDATA ();
		nid.cbSize = (uint) Marshal.SizeOf (nid);
		nid.hWnd = form.Handle;
		nid.uID = 1;
		nid.uCallbackMessage = (uint) 0x0400;
		nid.uFlags = NotifyIconFlags.NIF_MESSAGE;

		string tipText = "hello";
		nid.szTip = tipText;
		nid.uFlags |= NotifyIconFlags.NIF_TIP;

		Win32Shell_NotifyIcon (NotifyIconMessage.NIM_ADD, ref nid);
	}
Example #18
0
        /// <summary>
        /// Method remove/delete icon from tray
        /// </summary>
        private void Remove()
        {
            if (m_id != 0)
            {
                // remove the notify icon
                NOTIFYICONDATA data = new NOTIFYICONDATA();
                data.cbSize = (uint)Marshal.SizeOf(data);

                data.hWnd = m_handle;
                data.uID  = m_id;

                WindowsAPI.Shell_NotifyIcon(NotifyCommand.NIM_DELETE, ref data);
                m_id = 0;

                RefreshSystemTray();
            }
        }
 public SafeNotifyIconData(NOTIFYICONDATA nid)
 {
     cbSize           = nid.cbSize;
     hWnd             = (IntPtr)nid.hWnd;
     uID              = nid.uID;
     uFlags           = nid.uFlags;
     uCallbackMessage = nid.uCallbackMessage;
     hIcon            = (IntPtr)nid.hIcon;
     szTip            = nid.szTip;
     dwState          = nid.dwState;
     dwStateMask      = nid.dwStateMask;
     szInfo           = nid.szInfo;
     uVersion         = nid.uVersion;
     szInfoTitle      = nid.szInfoTitle;
     dwInfoFlags      = nid.dwInfoFlags;
     guidItem         = nid.guidItem;
     hBalloonIcon     = nid.hBalloonIcon;
 }
Example #20
0
        /// <summary>
        /// Function Create a new Tray icon object
        /// </summary>
        /// <param name="id"></param>
        private void Create(uint id)
        {
            m_id     = id;
            m_handle = m_messageSink.Handle;

            NOTIFYICONDATA data = CreateNotifyStruct(NotifyFlags.NIF_MESSAGE |
                                                     NotifyFlags.NIF_ICON |
                                                     NotifyFlags.NIF_TIP);

            WindowsAPI.Shell_NotifyIcon(NotifyCommand.NIM_ADD, ref data);

            // add handlers
            m_messageSink.ClickNotify        += new NotifyIconTarget.NotifyIconHandler(Icon_OnClick);
            m_messageSink.DoubleClickNotify  += new NotifyIconTarget.NotifyIconHandler(Icon_OnDoubleClick);
            m_messageSink.RightClickNotify   += new NotifyIconTarget.NotifyIconHandler(Icon_OnRightClick);
            m_messageSink.ClickBalloonNotify += new NotifyIconTarget.NotifyIconHandler(Ballon_OnClick);
            m_messageSink.TaskbarCreated     += new EventHandler(OnTaskbarCreated);
        }
Example #21
0
 public void ShowBalloonTip(string title, string tips, int timeOutMSec)
 {
     if (Visible)
     {
         const uint NIF_INFO  = 0x10;
         const uint NIIF_INFO = 1;
         var        nid       = new NOTIFYICONDATA();
         nid.cbSize            = Marshal.SizeOf(nid);
         nid.hWnd              = hwndDictionary[this].Handle;
         nid.uID               = 1;
         nid.uFlags            = NIF_INFO;
         nid.szTip             = "";
         nid.szInfo            = tips.Length > 255 ? tips.Substring(0, 252) + "..." : tips;
         nid.uTimeoutOrVersion = (uint)timeOutMSec;
         nid.szInfoTitle       = title.Length > 63 ? title.Substring(0, 60) + "..." : title;
         nid.dwInfoFlags       = NIIF_INFO;
         Shell_NotifyIcon(1, ref nid);
     }
 }
Example #22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NotifyIcon"/> class.
        /// </summary>
        public NotifyIcon()
        {
#if !NDOC
            //create new messagewindow
            messageWindow = new NotifyIconMessageWindow(this);
#endif
            //create new array
            data        = new NOTIFYICONDATA();
            data.cbSize = Marshal.SizeOf(data);

            //write standard contents to data
            data.uID = id++;
            //write notification message
            data.uCallbackMessage = (int)WM.NOTIFY;
#if !NDOC
            data.hWnd = messageWindow.Hwnd;
#endif
            data.uFlags = NIF.MESSAGE;
        }
Example #23
0
        /// <summary>
        /// getNOTIFYICONDATA
        /// </summary>
        private NOTIFYICONDATA getNOTIFYICONDATA(IntPtr iconHwnd, int flags, string tip, string infoTitle, string info, BalloonType balloonType)
        {
            NOTIFYICONDATA data = new NOTIFYICONDATA();

            data.cbSize             = Marshal.SizeOf(data);
            data.hwnd               = messageLoopHandle;
            data.uID                = uID;
            data.uFlags             = flags;
            data.uCallbackMessage   = WM_NOTIFY_TRAY;
            data.hIcon              = iconHwnd;
            data.uTimeoutAndVersion = 10 * 1000;
            data.dwInfoFlags        = balloonType;

            data.szTip       = tip;
            data.szInfoTitle = infoTitle;
            data.szInfo      = info;

            return(data);
        }
        private NOTIFYICONDATA newNotifyIconData(bool useLastHandle)
        {
            NOTIFYICONDATA ids = new NOTIFYICONDATA();

            ids.uCallbackMessage = NOTIFYMESSAGE;
            ids.hWnd             = this.Handle;
            ids.uID = 1;

            if (Environment.OSVersion.Version.Major >= 5)
            {
                ids.cbSize            = Marshal.SizeOf(ids);
                ids.uTimeoutOrVersion = NOTIFYICON_VERSION;
            }
            else
            {
                ids.cbSize = NOTIFYICONDATAA_V1_SIZE;
            }
            return(ids);
        }
        private void showInSysTray(bool state)
        {
            NOTIFYICONDATA ids = newNotifyIconData(!state);

            ids.uFlags = NotifyIconDataFlags.NIF_MESSAGE;

            if (state)
            {
                if (!this.inSysTray)
                {
                    setIcon(ref ids);
                    setMessage(ref ids);

                    // add to systray:
                    int ret = Shell_NotifyIcon(
                        NotifyIconMessages.NIM_ADD,
                        ref ids);
                    // set version:
                    if (ids.uTimeoutOrVersion == NOTIFYICON_VERSION)
                    {
                        ret = Shell_NotifyIcon(
                            NotifyIconMessages.NIM_SETVERSION,
                            ref ids);
                    }
                }
            }
            else
            {
                if (this.inSysTray)
                {
                    // remove from systray
                    Shell_NotifyIcon(
                        NotifyIconMessages.NIM_DELETE,
                        ref ids);
                    if (icon != null)
                    {
                        icon.Dispose();
                    }
                }
            }
            this.inSysTray    = state;
            this.wasInSysTray = this.inSysTray;
        }
Example #26
0
        private void RemoveIconLegacy()
        {
            if (_ownerForm == null)
            {
                return;
            }
            if (!_iconAdded)
            {
                return;
            }
            var data = new NOTIFYICONDATA();

            InitNotifyIconData(ref data);

            if (!Shell_NotifyIcon(NotifyIconMessages.Delete, data))
            {
                throw new Win32Exception("Shell_NotifyIcon failed");
            }
            _iconAdded = false;
        }
Example #27
0
 /// <summary>
 /// Remove the culture notify icon when the designer process exits
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private static void OnDesignerExit(object sender, EventArgs e)
 {
     // By the time the ProcessExit event is called the window associated with the
     // notify icon has been destroyed - and a bug in the NotifyIcon class means that
     // the notify icon is not removed. This works around the issue by saving the
     // window handle when the NotifyIcon is created and then calling the Shell_NotifyIcon
     // method ourselves to remove the icon from the tray
     //
     if (_notifyIconHandle != IntPtr.Zero)
     {
         NOTIFYICONDATA iconData = new NOTIFYICONDATA();
         iconData.uCallbackMessage = 2048;
         iconData.uFlags           = 1;
         iconData.hWnd             = _notifyIconHandle;
         iconData.uID   = 1;
         iconData.hIcon = IntPtr.Zero;
         iconData.szTip = null;
         Shell_NotifyIcon(2, iconData);
     }
 }
Example #28
0
        private void Initialize()
        {
            // init struct
            _NID      = new NOTIFYICONDATA();
            _NID.hWnd = _messages.Handle;

            _NID.szTip            = String.Empty;
            _NID.szInfo           = String.Empty;
            _NID.szInfoTitle      = String.Empty;
            _NID.cbSize           = Marshal.SizeOf(typeof(NOTIFYICONDATA));
            _NID.dwState          = 0;
            _NID.dwStateMask      = 0;
            _NID.uFlags           = NIF_ICON | NIF_TIP | NIF_MESSAGE;
            _NID.uCallbackMessage = WM_NOTIFYICONCALLBACK;
            _NID.uVersion         = NOTIFYICON_VERSION;
            _NID.uID = 1;

            _iconStates = new Hashtable();
            InitAniTimer();
            InitEventHandler();
        }
 private void setIcon(ref NOTIFYICONDATA ids)
 {
     if (this.ilsIcons != null)
     {
         // Let's see if we can get the icon:
         if (icon != null)
         {
             icon.Dispose();
         }
         IntPtr hIcon = ImageList_GetIcon(
             ilsIcons.Handle,
             iconIndex,
             0);
         if (hIcon != IntPtr.Zero)
         {
             icon        = new UnManagedIcon(hIcon);
             ids.uFlags |= NotifyIconDataFlags.NIF_ICON;
             ids.hIcon   = icon.Handle;
         }
     }
 }
Example #30
0
        /// <summary>
        /// Function create struct which used Shell_NotifyIcon API function
        /// </summary>
        /// <param name="flags"></param>
        /// <returns></returns>
        private NOTIFYICONDATA CreateNotifyStruct(NotifyFlags flags, bool bSkip)
        {
            NOTIFYICONDATA data = new NOTIFYICONDATA();

            data.cbSize = (uint)Marshal.SizeOf(data);

            data.hWnd = m_handle;
            data.uID  = m_id;

            data.uCallbackMessage = 0x400;
            data.uFlags          |= flags;

            if (m_icon != null)
            {
                data.hIcon = m_icon.Handle; // this should always be valid
            }
            else
            {
                if (m_imgList != null && m_imgList.Images.Count > 0)
                {
                    Bitmap bmp = new Bitmap(m_imgList.Images[0], 16, 16);
                    data.hIcon = bmp.GetHicon();
                }
            }

            data.szTip = m_text;

            if (!bSkip)
            {
                if (!m_visible)
                {
                    data.dwState = NotifyState.NIS_HIDDEN;
                }
                data.dwStateMask |= NotifyState.NIS_HIDDEN;
            }

            return(data);
        }
Example #31
0
        private void UpdateIconLegacy()
        {
            var data = new NOTIFYICONDATA();

            InitNotifyIconData(ref data);

            if (!_iconAdded)
            {
                if (!Shell_NotifyIcon(NotifyIconMessages.Add, data))
                {
                    throw new Win32Exception("Shell_NotifyIcon failed");
                }
            }

            data.hIcon            = _icon == null ? IntPtr.Zero : _icon.Handle;
            data.szTip            = _hintText;
            data.uCallbackMessage = CALLBACK_MESSAGE;
            data.uFlags           = NotifyIconFlags.Icon | NotifyIconFlags.Message | NotifyIconFlags.Tip | NotifyIconFlags.Guid;

            Shell_NotifyIcon(NotifyIconMessages.Modify, data);

            _iconAdded = true;
        }
Example #32
0
        private void CleanUpOldTrayIconIfAppropriate()
        {
            // If we closed improperly last time, make sure the old tray icon isn't still around.
            try {
                var oldTrayIconID   = LibraryRegistry.GetInt32Value(RegSettingNames.LastTrayID);
                var oldTrayIconHwnd = LibraryRegistry.GetInt32Value(RegSettingNames.LastTrayHwnd);
                if (oldTrayIconID.HasValue && oldTrayIconHwnd.HasValue)
                {
                    try {
                        var oldTrayIconData = new NOTIFYICONDATA();
                        oldTrayIconData.hwnd = new IntPtr(oldTrayIconHwnd.Value);
                        oldTrayIconData.uID  = oldTrayIconID.Value;

                        Shell_NotifyIcon(NIM_DELETE, ref oldTrayIconData);
                    } finally {
                        LibraryRegistry.DeleteValue(RegSettingNames.LastTrayID);
                        LibraryRegistry.DeleteValue(RegSettingNames.LastTrayHwnd);
                    }
                }
            } catch (Exception e) {
                Log.Logger.WarnException("Exception removing last tray icon", e);
            }
        }
Example #33
0
 internal static extern int Shell_NotifyIcon(
     int dwMessage, ref NOTIFYICONDATA pnid);
Example #34
0
		internal override bool SystrayChange(IntPtr hwnd, string tip, Icon icon, ref ToolTip tt) {
			NOTIFYICONDATA	nid;

			nid = new NOTIFYICONDATA();

			nid.cbSize = (uint)Marshal.SizeOf(nid);
			nid.hIcon = icon.Handle;
			nid.hWnd = hwnd;
			nid.uID = 1;
			nid.uCallbackMessage = (uint)Msg.WM_USER;
			nid.uFlags = NotifyIconFlags.NIF_MESSAGE;

			if (tip != null) {
				nid.szTip = tip;
				nid.uFlags |= NotifyIconFlags.NIF_TIP;
			}

			if (icon != null) {
				nid.hIcon = icon.Handle;
				nid.uFlags |= NotifyIconFlags.NIF_ICON;
			}

			return Win32Shell_NotifyIcon(NotifyIconMessage.NIM_MODIFY, ref nid);
		}
Example #35
0
		}
Example #36
0
 public static extern int Shell_NotifyIcon(int message, NOTIFYICONDATA pnid);
Example #37
0
 private void ShowBalloon(string title, string text, ToolTipIcon icon)
 {
     try
     {
         NOTIFYICONDATA clsNID = default(NOTIFYICONDATA);
         FieldInfo windowField = NotifyIcon.GetType().GetField("window", BindingFlags.NonPublic | BindingFlags.Instance);
         FieldInfo idField = NotifyIcon.GetType().GetField("id", BindingFlags.NonPublic | BindingFlags.Instance);
         IntPtr ptrWindow = ((NativeWindow)windowField.GetValue(NotifyIcon)).Handle;
         int id = (int)idField.GetValue(NotifyIcon);
         clsNID = new NOTIFYICONDATA
         {
             szTip = "",
             dwState = 0,
             dwStateMask = 0,
             hIcon = IntPtr.Zero,
             uCallbackMessage = new IntPtr(0x200),
             uID = id,
             hwnd = ptrWindow,
             szInfo = text,
             szInfoTitle = title,
             uFlags = 0x10,
             cbSize = Marshal.SizeOf(clsNID),
             dwInfoFlags = (int)icon,
             uTimeout = 5
         };
         Shell_NotifyIconA(1, ref clsNID);
     }
     catch (NullReferenceException)
     {
     }
     catch (Exception ex)
     {
         Logger.Log.Error(string.Format("Error showing balloon (title={0},text={1},icon={2})", title, text, icon), ex);
     }
 }
Example #38
0
 internal MyNotifyIcon()
 {
     window = new MyNativeWindow(this);
     iconData = new NOTIFYICONDATA();
     iconData.cbSize = Marshal.SizeOf(typeof(NOTIFYICONDATA));
     iconData.hWnd = window.Handle;
     iconData.uID = 1;
     iconData.uCallbackMessage = WM_NOTIFYICONCALLBACK;
 }
Example #39
0
 private static extern int Shell_NotifyIconA(int dwMessage, ref NOTIFYICONDATA pnid);
Example #40
0
		internal override void SystrayBalloon(IntPtr hwnd, int timeout, string title, string text, ToolTipIcon icon)
		{
			NOTIFYICONDATA	nid;

			nid = new NOTIFYICONDATA();

			nid.cbSize = (uint)Marshal.SizeOf(nid);
			nid.hWnd = hwnd;
			nid.uID = 1;
			nid.uFlags = NotifyIconFlags.NIF_INFO;
			nid.uTimeoutOrVersion = timeout;
			nid.szInfoTitle = title;
			nid.szInfo = text;
			nid.dwInfoFlags = icon;
			
			Win32Shell_NotifyIcon(NotifyIconMessage.NIM_MODIFY, ref nid);
		}
Example #41
0
		internal override void SystrayRemove(IntPtr hwnd, ref ToolTip tt) {
			NOTIFYICONDATA	nid;

			nid = new NOTIFYICONDATA();

			nid.cbSize = (uint)Marshal.SizeOf(nid);
			nid.hWnd = hwnd;
			nid.uID = 1;
			nid.uFlags = 0;

			Win32Shell_NotifyIcon(NotifyIconMessage.NIM_DELETE, ref nid);
		}
Example #42
0
 public static extern bool Shell_NotifyIcon(int dwMessage, ref NOTIFYICONDATA lpData);
Example #43
0
		private extern static bool Win32Shell_NotifyIcon(NotifyIconMessage dwMessage, ref NOTIFYICONDATA lpData);
 /// <summary>
 /// Remove the culture notify icon when the designer process exits
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private static void OnDesignerExit(object sender, EventArgs e)
 {
     // By the time the ProcessExit event is called the window associated with the
     // notify icon has been destroyed - and a bug in the NotifyIcon class means that
     // the notify icon is not removed. This works around the issue by saving the
     // window handle when the NotifyIcon is created and then calling the Shell_NotifyIcon
     // method ourselves to remove the icon from the tray
     //
     if (_notifyIconHandle != IntPtr.Zero)
     {
         NOTIFYICONDATA iconData = new NOTIFYICONDATA();
         iconData.uCallbackMessage = 2048;
         iconData.uFlags = 1;
         iconData.hWnd = _notifyIconHandle;
         iconData.uID = 1;
         iconData.hIcon = IntPtr.Zero;
         iconData.szTip = null;
         Shell_NotifyIcon(2, iconData);
     }
 }