Beispiel #1
1
 public NotifyIcon(Window parent, System.Drawing.Icon icon)
 {
     _data = new NotifyIconData();
     _data.cbSize = Marshal.SizeOf(typeof(NotifyIconData));
     _data.uID = _id++;
     _data.uFlags = 0x8 | 0x2 | 0x1;
     _data.dwState = 0x0;
     _data.hIcon = icon.Handle;
     _data.hWnd = new WindowInteropHelper(parent).Handle;
     _data.uCallbackMessage = 0x5700;
     _src = HwndSource.FromHwnd(_data.hWnd);
     _src.AddHook(new HwndSourceHook(WndProc));
     Shell_NotifyIcon(0x0, ref _data);
 }
Beispiel #2
0
        // update an existing icon
        private void Update()
        {
            NotifyIconData data = new NotifyIconData();

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

            data.hWnd = m_messageSink.Handle;
            data.uID  = m_id;

            // this null check has been introduced by Drew... I don't know why it's needed
            // but the app was crashing sometimes -- especially when ccnet is calling through
            // to a nant task that's crashed, for example.
            // this can cause the icon to disappear until the remoting starts to work again,
            // but this is preferable to having the app crash
            if (m_icon != null)
            {
                data.hIcon = m_icon.Handle;                 // this should always be valid
            }
            data.uFlags |= NotifyFlags.Icon;

            data.szTip   = m_text;
            data.uFlags |= NotifyFlags.Tip;
            data.uFlags |= NotifyFlags.State;

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

            Shell_NotifyIcon(NotifyCommand.Modify, ref data);
        }
Beispiel #3
0
        // update an existing icon
        private void Update()
        {
            NotifyIconData data = new NotifyIconData();

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

            data.hWnd = m_messageSink.Handle;
            data.uID  = m_id;

            data.hIcon   = m_icon.Handle; // this should always be valid
            data.uFlags |= NotifyFlags.Icon;

            data.szTip       = m_text;
            data.szInfoTitle = m_balloonTitle;

            data.uFlags |= NotifyFlags.Tip;
            data.uFlags |= NotifyFlags.State;

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

            Shell_NotifyIcon(NotifyCommand.Modify, ref data);
        }
Beispiel #4
0
        /// <summary>
        /// Inits the taskbar icon and registers a message listener
        /// in order to receive events from the taskbar area.
        /// </summary>
        public TaskbarIcon()
        {
            //using dummy sink in design mode
            this.messageSink = Util.IsDesignMode
                ? WindowMessageSink.CreateEmpty()
                : new WindowMessageSink(NotifyIconVersion.Vista);

            //init icon data structure
            this.iconData = NotifyIconData.CreateDefault(this.messageSink.MessageWindowHandle);

            //create the taskbar icon
            this.CreateTaskbarIcon();

            // register event listeners
            this.messageSink.MouseEventReceived        += this.OnMouseEvent;
            this.messageSink.TaskbarCreated            += this.OnTaskbarCreated;
            this.messageSink.ChangeToolTipStateRequest += this.OnToolTipChange;
            this.messageSink.BalloonToolTipChanged     += this.OnBalloonToolTipChanged;

            //init single click / balloon timers
            this.singleClickTimer  = new Timer(DoSingleClickAction);
            this.balloonCloseTimer = new Timer(CloseBalloonCallback);

            // register listener in order to get notified when the application closes
            if (Application.Current != null)
            {
                Application.Current.Exit += this.OnExit;
            }
        }
        public void ShowBalloon(string title, string text, NotifyInfoFlags type, int timeoutInMilliSeconds)
        {
            if (timeoutInMilliSeconds < 0)
            {
                throw new ArgumentException("The parameter must be positive", "timeoutInMilliseconds");
            }

            NotifyIconData data = new NotifyIconData();


            data.cbSize = (uint)Marshal.SizeOf(data);
            disp.Invoke(new Action(() =>
            {
                data.hWnd = m_messageSink.Handle;
                data.uID  = m_id;

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

                Shell_NotifyIcon(NotifyCommand.Modify, ref data);
            }));
        }
Beispiel #6
0
 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.");
     }
 }
Beispiel #7
0
        /// <summary>
        /// Updates the taskbar icons with data provided by a given
        /// <see cref="NotifyIconData"/> instance.
        /// </summary>
        /// <param name="data">Configuration settings for the NotifyIcon.</param>
        /// <param name="command">Operation on the icon (e.g. delete the icon).</param>
        /// <param name="flags">Defines which members of the <paramref name="data"/>
        /// structure are set.</param>
        /// <returns>True if the data was successfully written.</returns>
        /// <remarks>See Shell_NotifyIcon documentation on MSDN for details.</remarks>
        public static bool WriteIconData(ref NotifyIconData data, NotifyCommand command, IconDataMembers flags)
        {
            //do nothing if in design mode
            if (IsDesignMode)
            {
                return(true);
            }

            data.ValidMembers = flags;
            var status      = false;
            var failedTries = 0;

            while (!status && failedTries < 5)
            {
                lock (SyncRoot)
                {
                    status = WinApi.Shell_NotifyIcon(command, ref data);
                    if (status)
                    {
                        return(status);
                    }
                }

                // handle low powered machines during startup:
                // http://msdn.microsoft.com/en-us/library/bb762159(VS.85).aspx
                failedTries += 1;

                System.Threading.Thread.Sleep(100); // ms
            }

            System.Console.WriteLine("failed to write icon data");
            return(false);
        }
Beispiel #8
0
        public TrayIcon(IntPtr Parent, string ToolTip, IntPtr iconPtr)
        {
            stHelperWindow = new Window("ToolTipWindow", serviceFunc, IntPtr.Zero, hidden: true, delayShow: true)
            {
                Top          = 5,
                Left         = 5,
                Width        = 20,
                Height       = 20,
                Style        = GDIWindow.Win32Enums.WindowStylesEx.WS_EX_VisualStudioEmulation,
                ZPos         = GDIWindow.Win32Enums.HWNDPosStates.TopMost,
                Transparency = 128
            };

            stHelperWindow.DelayedShow();

            data = new NotifyIconData()
            {
                uID              = ID = new Random().Next(),
                hWnd             = stHelperWindow.Handle,
                hIcon            = iconPtr,
                uFlags           = NIF.ICON | NIF.MESSAGE | NIF.TIP,// | NIF.INFO,
                szTip            = "ToolTip",
                uCallbackMessage = (MouseMessageForTrayIcon = RegisterWindowMessage("MouseMessageForTrayIcon"))
            };
            data.cbSize = Marshal.SizeOf(data);


            Shell_NotifyIcon(NIM.ADD, ref data);
        }
        public void ShowBalloon(uint iconId, IntPtr icon, string title, string text, uint timeout)
        {
            // find notify window
            uint threadId        = GetCurrentThreadId();
            EnumThreadWndProc cb = new EnumThreadWndProc(FindNotifyWindowCallback);

            m_foundNotifyWindow = false;
            EnumThreadWindows(threadId, cb, 0);
            if (m_foundNotifyWindow)
            {
                // show the balloon
                NotifyIconData data = new NotifyIconData();
                data.cbSize = (System.UInt32)
                              System.Runtime.InteropServices.Marshal.SizeOf(
                    typeof(NotifyIconData));
                data.hWnd = m_notifyWindow;
                data.uID  = iconId;
                //data.hIcon = icon;
                if (icon != IntPtr.Zero)
                {
                    data.hBalloonIcon = icon;
                }
                data.uFlags            = NotifyFlags.Info;
                data.uTimeoutOrVersion = 15000;
                data.szInfo            = text;
                data.szInfoTitle       = title;
                data.dwInfoFlags       = 0x04 | 0x20;
                Shell_NotifyIcon(NotifyCommand.Modify, ref data);
            }
        }
Beispiel #10
0
        /// <summary>
        /// Initializes the taskbar icon and registers a message listener
        /// in order to receive events from the taskbar area.
        /// </summary>
        public TaskBarIcon(Icon icon)
        {
            Icon = icon;

            // using dummy sink in design mode
            messageSink = new WindowMessageSink(NotifyIconVersion.Vista);

            // init icon data structure
            iconData             = NotifyIconData.CreateDefault(messageSink.MessageWindowHandle);
            iconData.IconHandle  = Icon?.Handle ?? IntPtr.Zero;
            iconData.ToolTipText = nameof(MangaReader);

            // create the taskbar icon
            CreateTaskbarIcon();

            // register event listeners
            messageSink.MouseEventReceived += OnMouseEvent;
            messageSink.TaskbarCreated     += OnTaskbarCreated;

            // register listener in order to get notified when the application closes
            if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime)
            {
                lifetime.Exit += OnExit;
            }
        }
Beispiel #11
0
        private void AddNotifyIconWin32()
        {
            IntPtr hWnd = PlatformImpl.Handle.Handle;

            var assets = AvaloniaLocator.Current.GetService <IAssetLoader>();

            // TODO: Design my own icon
            using Stream iconStream = assets.Open(new Uri("avares://Labyrinth/Assets/avalonia-logo.ico"));
            var icon = new Icon(iconStream);

            notifyIconData = new NotifyIconData {
                HWnd             = hWnd,
                UFlags           = NotifyIconFlag.NIF_MESSAGE | NotifyIconFlag.NIF_ICON | NotifyIconFlag.NIF_STATE,
                DwState          = NotifyIconState.NIS_HIDDEN,
                DwStateMask      = NotifyIconState.NIS_HIDDEN,
                UCallbackMessage = WindowMessage.WM_NOTIFYICON_CB,
                HIcon            = icon.Handle,
            };

            int size = Marshal.SizeOf(notifyIconData);

            notifyIconData.CbSize = (uint)size;

            IntPtr dataPtr = Marshal.AllocHGlobal(size);

            Marshal.StructureToPtr(notifyIconData, dataPtr, true);

            // Create the notify icon
            ShellNotifyIconW(NotifyIconMessage.NIM_ADD, dataPtr);

            // Process mouse events on the icon
            subclassWndProc = Win32SubclassWndProc;
            SetWindowSubclass(hWnd, subclassWndProc, IntPtr.Zero, IntPtr.Zero);
        }
Beispiel #12
0
        private void Create(uint id)
        {
            NotifyIconData data = new NotifyIconData();

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

            m_handle  = m_messageSink.Handle;
            data.hWnd = m_handle;
            m_id      = id;
            data.uID  = m_id;

            data.uCallbackMessage = 0x400;
            data.uFlags          |= NotifyFlags.Message;

            data.hIcon   = m_icon.Handle;           // this should always be valid
            data.uFlags |= NotifyFlags.Icon;

            data.szTip   = m_text;
            data.uFlags |= NotifyFlags.Tip;

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

            Shell_NotifyIcon(NotifyCommand.Add, ref data);

            // add handlers
            m_messageSink.ClickNotify        += new NotifyIconTarget.NotifyIconHandler(OnClick);
            m_messageSink.DoubleClickNotify  += new NotifyIconTarget.NotifyIconHandler(OnDoubleClick);
            m_messageSink.RightClickNotify   += new NotifyIconTarget.NotifyIconHandler(OnRightClick);
            m_messageSink.ClickBalloonNotify += new NotifyIconTarget.NotifyIconHandler(OnClickBalloon);
            m_messageSink.TaskbarCreated     += new EventHandler(OnTaskbarCreated);
        }
Beispiel #13
0
 /// <summary>
 /// Updates the taskbar icons with data provided by a given
 /// <see cref="NotifyIconData"/> instance.
 /// </summary>
 /// <param name="data">Configuration settings for the NotifyIcon.</param>
 /// <param name="command">Operation on the icon (e.g. delete the icon).</param>
 /// <param name="flags">Defines which members of the <paramref name="data"/>
 /// structure are set.</param>
 /// <returns>True if the data was successfully written.</returns>
 /// <remarks>See Shell_NotifyIcon documentation on MSDN for details.</remarks>
 private bool WriteIconData(ref NotifyIconData data, NotifyCommand command, IconDataMembers flags)
 {
     data.ValidMembers |= flags;
     lock (lockObject)
     {
         return(WinApi.Shell_NotifyIcon(command, ref data));
     }
 }
            public static void DeleteTrayIcon(Guid iconGuid)
            {
                var command = NotifyCommand.Delete;
                var data    = new NotifyIconData();

                data.Size         = (uint)Marshal.SizeOf(data);
                data.Guid         = iconGuid;
                data.ValidMembers = IconDataFlags.Guid;

                Shell_NotifyIcon(command, ref data);
            }
Beispiel #15
0
        public static void SetFocusToNotifyIcon(int iconId)
        {
            NotifyIconData IconData = new NotifyIconData {
                cbSize = Marshal.SizeOf(typeof(NotifyIconData))
            };

            IconData.hwnd = NotifyIconInteropHelper.HookWindow.Handle;
            IconData.uID  = iconId;

            NotifyIconInteropHelper.Shell_NotifyIcon(NotifyMessage.SetFocus, ref IconData);
        }
Beispiel #16
0
 /// <summary>
 ///     Updates the taskbar icons with data provided by a given
 ///     <see cref="NotifyIconData" /> instance.
 /// </summary>
 /// <param name="data">Configuration settings for the NotifyIcon.</param>
 /// <param name="command">Operation on the icon (e.g. delete the icon).</param>
 /// <param name="flags">
 ///     Defines which members of the <paramref name="data" />
 ///     structure are set.
 /// </param>
 /// <returns>True if the data was successfully written.</returns>
 /// <remarks>See Shell_NotifyIcon documentation on MSDN for details.</remarks>
 public static bool WriteIconData(ref NotifyIconData data, NotifyCommand command, IconDataMembers flags)
 {
     //do nothing if in design mode
     if (IsDesignMode)
     {
         return(true);
     }
     data.ValidMembers = flags;
     lock (SyncRoot) {
         return(WinApi.Shell_NotifyIcon(command, ref data));
     }
 }
Beispiel #17
0
    /// <summary>
    /// Updates the taskbar icons.
    /// </summary>
    /// <param name="data">Configuration settings for the NotifyIcon.</param>
    /// <param name="command">Operation on the icon (e.g. delete the icon).</param>
    /// <param name="flags">Defines which members of the <paramref name="data"/> structure are set.</param>
    /// <returns>True if the data was successfully written.</returns>
    /// <remarks>See Shell_NotifyIcon documentation on MSDN for details.</remarks>
    public static bool WriteIconData(ref NotifyIconData data, NotifyCommands command, IconDataMembers flags)
    {
        if (VisualHelper.IsInDesignMode())
        {
            return(true);
        }

        data.ValidMembers = flags;

        lock (VisualHelper.LockObject)
            return(Native.External.Shell32.Shell_NotifyIcon(command, ref data));
    }
            public static void CreateTrayIcon(Guid iconGuid, IntPtr windowHandle)
            {
                var data = new NotifyIconData
                {
                    Size = (uint)Marshal.SizeOf(typeof(NotifyIconData)),
                    CallbackMessageId = MessageId,
                    WindowHandle      = windowHandle,
                    Guid         = iconGuid,
                    ValidMembers = IconDataFlags.Callback | IconDataFlags.Guid
                };

                Shell_NotifyIcon(NotifyCommand.Add, ref data);
            }
            public static void SetTrayIconTooltip(Guid iconGuid, string message)
            {
                var command = NotifyCommand.Modify;

                var data = new NotifyIconData();

                data.Size         = (uint)Marshal.SizeOf(data);
                data.ToolTipText  = message;
                data.Guid         = iconGuid;
                data.ValidMembers = IconDataFlags.Tooltip | IconDataFlags.Guid;


                Shell_NotifyIcon(command, ref data);
            }
        /// <summary>
        /// Removes the given tray icon using the TrayData we've fetched for it.
        /// </summary>
        private static void RemoveIcon(ExtraButtonData td)
        {
            var data = new NotifyIconData()
            {
                hWnd = td.hWnd,
                uID  = td.uID
            };

            //Try to remove the icon. Throw the last Win32 error if this fails.
            if (!Shell_NotifyIcon(NIM_DELETE, data))
            {
                throw new Win32Exception();
            }
        }
Beispiel #21
0
        public static NotifyIconData GetDefaultNotifyIconData(IntPtr handle)
        {
            var data = new NotifyIconData();

            data.cbSize           = (uint)Marshal.SizeOf(data);
            data.hWnd             = handle;
            data.hIcon            = IntPtr.Zero;
            data.dwState          = NotifyIconState.Hidden;
            data.dwStateMask      = NotifyIconState.Hidden;
            data.uCallbackMessage = 0x0400;
            data.uFlags           = NotifyIconFlags.Message | NotifyIconFlags.Icon | NotifyIconFlags.Tip;

            return(data);
        }
        /// <summary>
        /// Updates the taskbar icons with data provided by a given
        /// <see cref="NotifyIconData"/> instance.
        /// </summary>
        /// <param name="data">Configuration settings for the NotifyIcon.</param>
        /// <param name="command">Operation on the icon (e.g. delete the icon).</param>
        /// <param name="flags">Defines which members of the <paramref name="data"/>
        /// structure are set.</param>
        /// <returns>True if the data was successfully written.</returns>
        /// <remarks>See Shell_NotifyIcon documentation on MSDN for details.</remarks>
        public bool WriteIconData(ref NotifyIconData data, NotifyCommand command, IconDataMembers flags)
        {
            //do nothing if in design mode
            if (IsDesignMode)
            {
                return(true);
            }

            data.ValidMembers = flags;
            lock (lockObject)
            {
                return(Interop.Shell_NotifyIcon(command, ref data));
            }
        }
Beispiel #23
0
        public static bool smethod_2(ref NotifyIconData notifyIconData_0, NotifyCommand notifyCommand_0, IconDataMembers iconDataMembers_0)
        {
            if (Boolean_0)
            {
                return(true);
            }
            notifyIconData_0.ValidMembers = iconDataMembers_0;
            object obj2 = object_0;

            lock (obj2)
            {
                return(Class5.Shell_NotifyIcon(notifyCommand_0, ref notifyIconData_0));
            }
        }
Beispiel #24
0
        /// <summary>
        /// Removes object from tray.
        /// </summary>
        private void Remove()
        {
            if (this.ID == 0)
            {
                return;
            }
            NotifyIconData data = new NotifyIconData();

            data.Size      = ((uint)(Marshal.SizeOf(data)));
            data.WndHandle = this.Handle;
            data.ID        = this.ID;
            Shell_NotifyIcon(Commands.Remove, ref data);
            this._ID = 0;
        }
            public static void SetTrayIconImage(Guid iconGuid, string iconPath)
            {
                var iconHandle = LoadImage(IntPtr.Zero, iconPath, IconImage, 0, 0, LoadFromFile);

                var command = NotifyCommand.Modify;

                var data = new NotifyIconData();

                data.Size         = (uint)Marshal.SizeOf(data);
                data.IconHandle   = iconHandle;
                data.Guid         = iconGuid;
                data.ValidMembers = IconDataFlags.Icon | IconDataFlags.Guid;

                Shell_NotifyIcon(command, ref data);
            }
Beispiel #26
0
        public static void DeleteNotifyIcon(int iconId)
        {
            NotifyIconInteropHelper.DestroyIcon(NotifyIconInteropHelper.iconHandles[iconId]);
            NotifyIconInteropHelper.iconHandles.Remove(iconId);

            NotifyIconData IconData = new NotifyIconData {
                cbSize = Marshal.SizeOf(typeof(NotifyIconData))
            };

            IconData.hwnd = NotifyIconInteropHelper.HookWindow.Handle;
            IconData.uID  = iconId;

            NotifyIconInteropHelper.Shell_NotifyIcon(NotifyMessage.Delete, ref IconData);
            NotifyIconInteropHelper.HookWindow.RemoveMessageHook(iconId);
        }
Beispiel #27
0
 public NotifyIcon(Window parent, System.Drawing.Icon icon)
 {
     _data                  = new NotifyIconData();
     _data.cbSize           = Marshal.SizeOf(typeof(NotifyIconData));
     _data.uID              = _id++;
     _data.uFlags           = 0x8 | 0x2 | 0x1;
     _data.dwState          = 0x0;
     _data.hIcon            = icon.Handle;
     _data.hWnd             = new WindowInteropHelper(parent).Handle;
     _data.uCallbackMessage = CallbackMessage;
     _src = HwndSource.FromHwnd(_data.hWnd);
     _src.AddHook(new HwndSourceHook(WndProc));
     Shell_NotifyIcon(0x0, ref _data);
     this.IsVisible = true;
 }
Beispiel #28
0
        public static void ChangeNotifyIcon(int iconId, Bitmap icon)
        {
            NotifyIconInteropHelper.DestroyIcon(NotifyIconInteropHelper.iconHandles[iconId]);
            NotifyIconInteropHelper.iconHandles[iconId] = icon.GetHicon();

            NotifyIconData IconData = new NotifyIconData {
                cbSize = Marshal.SizeOf(typeof(NotifyIconData))
            };

            IconData.hwnd   = NotifyIconInteropHelper.HookWindow.Handle;
            IconData.uID    = iconId;
            IconData.uFlags = 0x00000002; // NIF_ICON (2)
            IconData.hIcon  = NotifyIconInteropHelper.iconHandles[iconId];

            NotifyIconInteropHelper.Shell_NotifyIcon(NotifyMessage.Modify, ref IconData);
        }
Beispiel #29
0
        public 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;

                Shell_NotifyIcon(NotifyCommand.Delete, ref data);

                m_id = 0;
            }
        }
Beispiel #30
0
        /// <summary>
        /// Updates tray object.
        /// </summary>
        private void Update()
        {
            NotifyIconData data = new NotifyIconData();

            data.Size       = ((uint)(Marshal.SizeOf(data)));
            data.WndHandle  = this.Handle = msgTarget.Handle;
            data.ID         = this.ID;
            data.Flags     |= Flags.Icon | Flags.Tip | Flags.State;
            data.IconHandle = this._Icon.Handle;
            data.Tip        = this._Text;
            if (!this.Visible)
            {
                data.State |= State.Hidden;
            }
            data.StateMask |= State.Hidden;
            Shell_NotifyIcon(Commands.Modify, ref data);
        }
        public void Show(NotifyIcon notifyIcon, Icon icon, string text, int timeout)
        {
            var data = new NotifyIconData
            {
                cbSize = (uint)Marshal.SizeOf(typeof(NotifyIconData)),
                hWnd = GetHandle(notifyIcon),
                uFlags = NotifyFlags.Info,
                uTimeoutOrVersion = timeout,
                szInfo = text,
                hIcon = icon.Handle,
                hBalloonIcon = icon.Handle,
                uID = 1,
                dwInfoFlags = 0x00000004 | 0x00000020
            };

            Shell_NotifyIcon(NotifyCommand.Modify, ref data);
        }
Beispiel #32
0
 public void ShowBalloon(uint iconId, string title, string text, uint timeout)
 {
     // find notify window
     uint threadId = GetCurrentThreadId();
     EnumThreadWndProc cb = new EnumThreadWndProc(FindNotifyWindowCallback);
     m_foundNotifyWindow = false;
     EnumThreadWindows(threadId, cb, 0);
     if(m_foundNotifyWindow)
     {
         // show the balloon
         NotifyIconData data = new NotifyIconData();
         data.cbSize = (System.UInt32)System.Runtime.InteropServices.Marshal.SizeOf(typeof(NotifyIconData));
         data.hWnd = m_notifyWindow;
         data.uID = iconId;
         data.uFlags = NotifyFlags.Info;
         data.uTimeoutOrVersion = timeout;
         data.szInfo = text;
         data.szInfoTitle = title;
         Shell_NotifyIcon(NotifyCommand.Modify, ref data);
     }
 }
Beispiel #33
0
        public void ShowBalloon(string title, string text, NotifyInfoFlags type, int timeoutInMilliSeconds)
        {
            if(timeoutInMilliSeconds < 0)
                throw new ArgumentException("The parameter must be positive", "timeoutInMilliseconds");

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

            data.hWnd = m_messageSink.Handle;
            data.uID = m_id;

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

            Shell_NotifyIcon(NotifyCommand.Modify, ref data);
        }
Beispiel #34
0
        // update an existing icon
        private void Update()
        {
            NotifyIconData data = new NotifyIconData ();
            data.cbSize = (uint) Marshal.SizeOf (data);

            data.hWnd = m_messageSink.Handle;
            data.uID = m_id;

            // this null check has been introduced by Drew... I don't know why it's needed
            // but the app was crashing sometimes -- especially when ccnet is calling through
            // to a nant task that's crashed, for example.
            // this can cause the icon to disappear until the remoting starts to work again,
            // but this is preferable to having the app crash
            if (m_icon != null)
                data.hIcon = m_icon.Handle; // this should always be valid
            data.uFlags |= NotifyFlags.Icon;

            data.szTip = m_text;
            data.uFlags |= NotifyFlags.Tip;
            data.uFlags |= NotifyFlags.State;

            if (!m_visible)
                data.dwState = NotifyState.Hidden;
            data.dwStateMask |= NotifyState.Hidden;

            Shell_NotifyIcon (NotifyCommand.Modify, ref data);
        }
 public static extern bool Shell_NotifyIcon(NotifyIconMessage message,
   NotifyIconData pnid);
Beispiel #36
0
        public 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;

                Shell_NotifyIcon(NotifyCommand.Delete, ref data);

                m_id = 0;
            }
        }
Beispiel #37
0
 internal static extern int ShellNotifyIcon(int message, NotifyIconData pnid);
Beispiel #38
0
        private void Create(uint id)
        {
            NotifyIconData data = new NotifyIconData();
            data.cbSize = (uint)Marshal.SizeOf(data);

            m_handle = m_messageSink.Handle;
            data.hWnd = m_handle;
            m_id = id;
            data.uID = m_id;

            data.uCallbackMessage = 0x400;
            data.uFlags |= NotifyFlags.Message;

            data.hIcon = m_icon.Handle; // this should always be valid
            data.uFlags |= NotifyFlags.Icon;

            data.szTip = m_text;
            data.uFlags |= NotifyFlags.Tip;

            if(!m_visible)
                data.dwState = NotifyState.Hidden;
            data.dwStateMask |= NotifyState.Hidden;

            Shell_NotifyIcon(NotifyCommand.Add, ref data);

            // add handlers
            m_messageSink.ClickNotify += new NotifyIconTarget.NotifyIconHandler(OnClick);
            m_messageSink.DoubleClickNotify += new NotifyIconTarget.NotifyIconHandler(OnDoubleClick);
            m_messageSink.RightClickNotify += new NotifyIconTarget.NotifyIconHandler(OnRightClick);
            m_messageSink.ClickBalloonNotify += new NotifyIconTarget.NotifyIconHandler(OnClickBalloon);
            m_messageSink.TaskbarCreated += new EventHandler(OnTaskbarCreated);
        }
Beispiel #39
0
 public static extern System.Int32 Shell_NotifyIcon(NotifyCommand cmd, ref NotifyIconData data);
Beispiel #40
0
        // update an existing icon
        private void Update()
        {
            NotifyIconData data = new NotifyIconData();
            data.cbSize = (uint)Marshal.SizeOf(data);

            data.hWnd = m_messageSink.Handle;
            data.uID = m_id;

            data.hIcon = m_icon.Handle; // this should always be valid
            data.uFlags |= NotifyFlags.Icon;

            data.szTip = m_text;
            data.uFlags |= NotifyFlags.Tip;
            data.uFlags |= NotifyFlags.State;

            if(!m_visible)
                data.dwState = NotifyState.Hidden;
            data.dwStateMask |= NotifyState.Hidden;

            Shell_NotifyIcon(NotifyCommand.Modify, ref data);
        }
Beispiel #41
0
 public static extern int Shell_NotifyIcon(NotifyCommand cmd, ref NotifyIconData data);