Ejemplo n.º 1
0
        /// <summary>
        /// Window process which handles messages sent to the system tray.
        /// </summary>
        /// <param name="hWnd">Window handle to use.</param>
        /// <param name="msg">Type of message received.</param>
        /// <param name="wParam">Win32 wParam object. Contents depend on msg.</param>
        /// <param name="lParam">Win32 lParam object. Contents depend on msg.</param>
        /// <returns>Null pointer or the result of the default window procedure which ensures every message is processed.</returns>
        private static IntPtr TrayWndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam)
        {
            if (lParam == new IntPtr(Windows.User32.NinBalloonUserClick))
            {
                Manager.TrayIcon.HandleNotificationClick(msg);
            }

            switch (msg)
            {
            case Windows.User32.WmDestroy:
                User32.PostQuitMessage(0);
                return(IntPtr.Zero);

            case Windows.User32.WmShow:
                Tray.ShowMainWindow();
                return(IntPtr.Zero);

            case Windows.User32.WmTrayMouseMessage:
                if (Manager.TrayIcon != null)
                {
                    Manager.TrayIcon.HandleMessage(lParam.ToInt64());
                }

                return(IntPtr.Zero);

            default:
                return(User32.DefWindowProcW(hWnd, msg, wParam, lParam));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initialize the system tray icon of not already initialized.
        /// </summary>
        public static void InitializeTray()
        {
            TrayMessageWindow = new NotificationArea.TrayMessageWindow(ProductConstants.TrayWindowClassName);

            if (TrayMessageWindow.GetHandle() == IntPtr.Zero)
            {
                return;
            }

            if (TrayIcon == null)
            {
                TrayIcon = new NotificationArea.Tray(TrayMessageWindow);
            }
        }