Esempio n. 1
0
        internal System.Windows.Forms.NotifyIcon NotifyIcon;                            // the icon that sits in the system tray

        /// <summary>
        /// This class should be created and passed into Application.Run( ... )
        /// </summary>
        public ChoApplicationContext(IChoWinFormApp winFormApp)
        {
            BuildDefaultContextMenu();
            InitializeContext(winFormApp);
        }
Esempio n. 2
0
        /// <summary>
        /// Create the NotifyIcon UI, the ContextMenu for the NotifyIcon and an Exit menu item.
        /// </summary>
        private void InitializeContext(IChoWinFormApp windowApp)
        {
            this._components            = new System.ComponentModel.Container();
            this.NotifyIcon             = new System.Windows.Forms.NotifyIcon(this._components);
            this._notifyIconContextMenu = GetContextMenu(windowApp);
            if (windowApp != null)
            {
                this._mainFormWindow = windowApp.MainFormWindow;
            }

            this.NotifyIcon.DoubleClick += new System.EventHandler(this.notifyIcon_DoubleClick);

            this.NotifyIcon.Icon = windowApp != null ? windowApp.TrayIcon : null;
            if (this.NotifyIcon.Icon == null)
            {
                Assembly entryAssembly = ChoAssembly.GetEntryAssembly();
                if (entryAssembly != null)
                {
                    this.NotifyIcon.Icon = Icon.ExtractAssociatedIcon(entryAssembly.Location);
                }
            }

            this.NotifyIcon.Text = windowApp != null ? (windowApp.TooltipText.IsNullOrWhiteSpace() ? ChoGlobalApplicationSettings.Me.ApplicationName : windowApp.TooltipText) : ChoGlobalApplicationSettings.Me.ApplicationName;

            string defaultBaloonTipText = "{0} is running...".FormatString(ChoGlobalApplicationSettings.Me.ApplicationName);

            this.NotifyIcon.BalloonTipText = windowApp != null ? (windowApp.BalloonTipText.IsNullOrWhiteSpace() ? defaultBaloonTipText : windowApp.BalloonTipText) : defaultBaloonTipText;

            this.NotifyIcon.ContextMenu = _notifyIconContextMenu;
            this.NotifyIcon.Visible     = true;

            if (this._mainFormWindow != null)
            {
                _mainWPFWindow.Show();
                ChoWindowsManager.HideConsoleWindow();
                ChoWindowsManager.MainWindowHandle = this._mainFormWindow.Handle;
                _mainFormWindow.Closed            += new EventHandler(mainForm_Closed);
                _mainFormWindow.Closing           += new System.ComponentModel.CancelEventHandler(mainForm_Closing);
                _mainFormWindow.Resize            += new EventHandler(mainForm_Resize);
            }
            else if (this._mainWPFWindow != null)
            {
                ChoWindowsManager.HideConsoleWindow();
                _mainWPFWindow.Visibility = Visibility.Hidden;
                _mainWPFWindow.Show();
                WindowInteropHelper windowInteropHelper = new WindowInteropHelper(_mainWPFWindow);
                ChoWindowsManager.MainWindowHandle = windowInteropHelper.Handle;

                //_mainWPFWindow.Show();
                //_mainWPFWindow.SourceInitialized += new EventHandler(mainWPFWindow_SourceInitialized);
                //ChoWindowsManager.MainWindowHandle = this._mainWPFWindow;
                //_mainFormWindow.Closed += new EventHandler(mainForm_Closed);
                //_mainFormWindow.Closing += new System.ComponentModel.CancelEventHandler(mainForm_Closing);
                //_mainFormWindow.Resize += new EventHandler(mainForm_Resize);
            }

            if (ChoGlobalApplicationSettings.Me.TrayApplicationBehaviourSettings.TurnOn)
            {
                if (ChoGlobalApplicationSettings.Me.TrayApplicationBehaviourSettings.HideMainWindowAtStartup)
                {
                    this._showContextMenuItem.Checked = false;
                    ToggleShowContextMenuItem();
                }
            }
            else
            {
                ShowMainWindow();
            }

            ChoGlobalApplicationSettings.Me.ObjectChanged += new EventHandler(Me_ConfigChanged);

            Me_ConfigChanged(null, null);
            if (ChoGlobalApplicationSettings.Me.TrayApplicationBehaviourSettings.TurnOn)
            {
                if (ChoGlobalApplicationSettings.Me.TrayApplicationBehaviourSettings.HideMainWindowAtStartup)
                {
                    HideMainWindow();
                }
                else
                {
                    HideMainWindow();
                    ShowMainWindow();
                }
            }
        }
Esempio n. 3
0
        private ContextMenu GetContextMenu(IChoWinFormApp windowApp)
        {
            ContextMenu contextMenu = windowApp != null?windowApp.GetContextMenu(_defaultContextMenu) : _defaultContextMenu;

            return(contextMenu);
        }