コード例 #1
0
ファイル: NotifyIcon.cs プロジェクト: dox0/DotNet471RS3
        /// <include file='doc\TrayIcon.uex' path='docs/doc[@for="NotifyIcon.UpdateIcon"]/*' />
        /// <devdoc>
        ///     Updates the icon in the system tray.
        /// </devdoc>
        /// <internalonly/>
        private void UpdateIcon(bool showIconInTray)
        {
            lock (syncObj) {
                // Bail if in design mode...
                //
                if (DesignMode)
                {
                    return;
                }

                IntSecurity.UnrestrictedWindows.Demand();

                window.LockReference(showIconInTray);

                NativeMethods.NOTIFYICONDATA data = new NativeMethods.NOTIFYICONDATA();
                data.uCallbackMessage = WM_TRAYMOUSEMESSAGE;
                data.uFlags           = NativeMethods.NIF_MESSAGE;
                if (showIconInTray)
                {
                    if (window.Handle == IntPtr.Zero)
                    {
                        window.CreateHandle(new CreateParams());
                    }
                }
                data.hWnd  = window.Handle;
                data.uID   = id;
                data.hIcon = IntPtr.Zero;
                data.szTip = null;
                if (icon != null)
                {
                    data.uFlags |= NativeMethods.NIF_ICON;
                    data.hIcon   = icon.Handle;
                }
                data.uFlags |= NativeMethods.NIF_TIP;
                data.szTip   = text;

                if (showIconInTray && icon != null)
                {
                    if (!added)
                    {
                        UnsafeNativeMethods.Shell_NotifyIcon(NativeMethods.NIM_ADD, data);
                        added = true;
                    }
                    else
                    {
                        UnsafeNativeMethods.Shell_NotifyIcon(NativeMethods.NIM_MODIFY, data);
                    }
                }
                else if (added)
                {
                    UnsafeNativeMethods.Shell_NotifyIcon(NativeMethods.NIM_DELETE, data);
                    added = false;
                }
            }
        }
コード例 #2
0
ファイル: NotifyIcon.cs プロジェクト: dox0/DotNet471RS3
        /// <include file='doc\TrayIcon.uex' path='docs/doc[@for="NotifyIcon.ShowBalloonTip"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Displays a balloon tooltip in the taskbar with the specified title,
        ///       text, and icon for a duration of the specified timeout value.
        ///
        ///       The system enforces minimum and maximum timeout values. Timeout
        ///       values that are too large are set to the maximum value and values
        ///       that are too small default to the minimum value. The operating system's
        ///       default minimum and maximum timeout values are 10 seconds and 30 seconds,
        ///       respectively.
        ///
        ///       No more than one balloon ToolTip at at time is displayed for the taskbar.
        ///       If an application attempts to display a ToolTip when one is already being displayed,
        ///       the ToolTip will not appear until the existing balloon ToolTip has been visible for at
        ///       least the system minimum timeout value. For example, a balloon ToolTip with timeout
        ///       set to 30 seconds has been visible for seven seconds when another application attempts
        ///       to display a balloon ToolTip. If the system minimum timeout is ten seconds, the first
        ///       ToolTip displays for an additional three seconds before being replaced by the second ToolTip.
        ///    </para>
        /// </devdoc>
        public void ShowBalloonTip(int timeout, string tipTitle, string tipText, ToolTipIcon tipIcon)
        {
            if (timeout < 0)
            {
                throw new ArgumentOutOfRangeException("timeout", SR.GetString(SR.InvalidArgument, "timeout", (timeout).ToString(CultureInfo.CurrentCulture)));
            }

            if (string.IsNullOrEmpty(tipText))
            {
                throw new ArgumentException(SR.GetString(SR.NotifyIconEmptyOrNullTipText));
            }

            //valid values are 0x0 to 0x3
            if (!ClientUtils.IsEnumValid(tipIcon, (int)tipIcon, (int)ToolTipIcon.None, (int)ToolTipIcon.Error))
            {
                throw new InvalidEnumArgumentException("tipIcon", (int)tipIcon, typeof(ToolTipIcon));
            }


            if (added)
            {
                // Bail if in design mode...
                if (DesignMode)
                {
                    return;
                }
                IntSecurity.UnrestrictedWindows.Demand();

                NativeMethods.NOTIFYICONDATA data = new NativeMethods.NOTIFYICONDATA();
                if (window.Handle == IntPtr.Zero)
                {
                    window.CreateHandle(new CreateParams());
                }
                data.hWnd              = window.Handle;
                data.uID               = id;
                data.uFlags            = NativeMethods.NIF_INFO;
                data.uTimeoutOrVersion = timeout;
                data.szInfoTitle       = tipTitle;
                data.szInfo            = tipText;
                switch (tipIcon)
                {
                case ToolTipIcon.Info: data.dwInfoFlags = NativeMethods.NIIF_INFO; break;

                case ToolTipIcon.Warning: data.dwInfoFlags = NativeMethods.NIIF_WARNING; break;

                case ToolTipIcon.Error: data.dwInfoFlags = NativeMethods.NIIF_ERROR; break;

                case ToolTipIcon.None: data.dwInfoFlags = NativeMethods.NIIF_NONE; break;
                }
                UnsafeNativeMethods.Shell_NotifyIcon(NativeMethods.NIM_MODIFY, data);
            }
        }
コード例 #3
0
        /// <include file='doc\TrayIcon.uex' path='docs/doc[@for="NotifyIcon.UpdateIcon"]/*' />
        /// <devdoc>
        ///     Updates the icon in the system tray.
        /// </devdoc>
        /// <internalonly/>
        private void UpdateIcon(bool showIconInTray) {
            lock(syncObj) {

                // Bail if in design mode...
                //
                if (DesignMode) {
                    return;
                }

                IntSecurity.UnrestrictedWindows.Demand();

                window.LockReference(showIconInTray);

                NativeMethods.NOTIFYICONDATA data = new NativeMethods.NOTIFYICONDATA();
                data.uCallbackMessage = WM_TRAYMOUSEMESSAGE;
                data.uFlags = NativeMethods.NIF_MESSAGE;
                if (showIconInTray) {
                    if (window.Handle == IntPtr.Zero) {
                        window.CreateHandle(new CreateParams());
                    }
                }
                data.hWnd = window.Handle;
                data.uID = id;
                data.hIcon = IntPtr.Zero;
                data.szTip = null;
                if (icon != null) {
                    data.uFlags |= NativeMethods.NIF_ICON;
                    data.hIcon = icon.Handle;
                }
                data.uFlags |= NativeMethods.NIF_TIP;
                data.szTip = text;

                if (showIconInTray && icon != null) {
                    if (!added) {
                        UnsafeNativeMethods.Shell_NotifyIcon(NativeMethods.NIM_ADD, data);
                        added = true;
                    }
                    else {
                        UnsafeNativeMethods.Shell_NotifyIcon(NativeMethods.NIM_MODIFY, data);
                    }
                }
                else if (added) {
                    UnsafeNativeMethods.Shell_NotifyIcon(NativeMethods.NIM_DELETE, data);
                    added = false;
                }
            }
        }
コード例 #4
0
        /// <include file='doc\TrayIcon.uex' path='docs/doc[@for="NotifyIcon.ShowBalloonTip"]/*' />
        /// <devdoc>
        ///    <para>
        ///       Displays a balloon tooltip in the taskbar with the specified title,
        ///       text, and icon for a duration of the specified timeout value.
        /// 
        ///       The system enforces minimum and maximum timeout values. Timeout 
        ///       values that are too large are set to the maximum value and values 
        ///       that are too small default to the minimum value. The operating system's 
        ///       default minimum and maximum timeout values are 10 seconds and 30 seconds, 
        ///       respectively.
        ///       
        ///       No more than one balloon ToolTip at at time is displayed for the taskbar. 
        ///       If an application attempts to display a ToolTip when one is already being displayed, 
        ///       the ToolTip will not appear until the existing balloon ToolTip has been visible for at 
        ///       least the system minimum timeout value. For example, a balloon ToolTip with timeout 
        ///       set to 30 seconds has been visible for seven seconds when another application attempts 
        ///       to display a balloon ToolTip. If the system minimum timeout is ten seconds, the first 
        ///       ToolTip displays for an additional three seconds before being replaced by the second ToolTip.
        ///    </para>
        /// </devdoc>
        public void ShowBalloonTip(int timeout, string tipTitle, string tipText, ToolTipIcon tipIcon) {

            if (timeout < 0) {
               throw new ArgumentOutOfRangeException("timeout", SR.GetString(SR.InvalidArgument, "timeout", (timeout).ToString(CultureInfo.CurrentCulture)));
            }

            if (string.IsNullOrEmpty(tipText))
            {
                throw new ArgumentException(SR.GetString(SR.NotifyIconEmptyOrNullTipText));
            }

            //valid values are 0x0 to 0x3
            if (!ClientUtils.IsEnumValid(tipIcon, (int)tipIcon, (int)ToolTipIcon.None, (int)ToolTipIcon.Error)){
                throw new InvalidEnumArgumentException("tipIcon", (int)tipIcon, typeof(ToolTipIcon));
            }
            
            
           if (added ) {
                // Bail if in design mode...
                if (DesignMode) {
                   return;
                }
                IntSecurity.UnrestrictedWindows.Demand();

                NativeMethods.NOTIFYICONDATA data = new NativeMethods.NOTIFYICONDATA();
                if (window.Handle == IntPtr.Zero) {
                   window.CreateHandle(new CreateParams());
                }
                data.hWnd = window.Handle;
                data.uID = id;
                data.uFlags = NativeMethods.NIF_INFO;
                data.uTimeoutOrVersion = timeout;
                data.szInfoTitle = tipTitle;
                data.szInfo = tipText;
                switch (tipIcon) {
                   case ToolTipIcon.Info: data.dwInfoFlags = NativeMethods.NIIF_INFO; break;
                   case ToolTipIcon.Warning: data.dwInfoFlags = NativeMethods.NIIF_WARNING; break;
                   case ToolTipIcon.Error: data.dwInfoFlags = NativeMethods.NIIF_ERROR; break;
                   case ToolTipIcon.None: data.dwInfoFlags = NativeMethods.NIIF_NONE; break;
                }
                UnsafeNativeMethods.Shell_NotifyIcon(NativeMethods.NIM_MODIFY, data);
           }
        }
コード例 #5
0
 public static extern int Shell_NotifyIcon(NIM dwMessage, NativeMethods.NOTIFYICONDATA lpData);
コード例 #6
0
 public static extern int Shell_NotifyIcon(int message, NativeMethods.NOTIFYICONDATA pnid);