Example #1
0
 private void InternClose()
 {
     _newsMachine.CloseOverlay(true);
     _newsMachine = null;
     notifyIcon.Dispose();
     notifyIcon = null;
 }
Example #2
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            _this = this;

            notifyIcon = new System.Windows.Forms.NotifyIcon();
            notifyIcon.BalloonTipText = "程序开始运行";
            notifyIcon.BalloonTipTitle = "NewsApp";
            notifyIcon.Text = "NewsApp Tray";
            notifyIcon.Icon = System.Drawing.SystemIcons.WinLogo;
            notifyIcon.Visible = true;
            notifyIcon.ShowBalloonTip(1000);
            notifyIcon.MouseClick += new System.Windows.Forms.MouseEventHandler(notifyIcon_MouseClick);
            notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(new System.Windows.Forms.MenuItem[]
            {
                new System.Windows.Forms.MenuItem("关于", (obj, args) =>
                    System.Windows.MessageBox.Show(this, "NewsApp by bajdcc", "NewsApp")),
                new System.Windows.Forms.MenuItem("-"),
                new System.Windows.Forms.MenuItem("显示主界面", (obj, args) =>
                    Show()),
                new System.Windows.Forms.MenuItem("隐藏主界面", (obj, args) =>
                    Hide()),
                new System.Windows.Forms.MenuItem("-"),
                new System.Windows.Forms.MenuItem("显示新闻", (obj, args) =>
                    {
                        if (_newsMachine != null && _newsMachine.Overlay != null)
                        {
                            _newsMachine.Overlay.Show();
                        }
                    }),
                new System.Windows.Forms.MenuItem("隐藏新闻", (obj, args) =>
                    {
                        if (_newsMachine != null && _newsMachine.Overlay != null)
                        {
                            _newsMachine.Overlay.Hide();
                        }
                    }),
                new System.Windows.Forms.MenuItem("关闭新闻", (obj, args) =>
                    {
                        if (_newsMachine != null && _newsMachine.Overlay != null)
                        {
                            _newsMachine.Cancel(true);
                        }
                    }),
                new System.Windows.Forms.MenuItem("背景透明", (obj, args) =>
                    {
                        NewsMachine.Settings.TransparentBackground = !NewsMachine.Settings.TransparentBackground;
                        var _this = obj as System.Windows.Forms.MenuItem;
                        _this.Checked = !_this.Checked;
                        if (_newsMachine != null && _newsMachine.Overlay != null)
                        {
                            _newsMachine.Cancel(true);
                        }
                    })
                {
                    Checked = false
                },
                new System.Windows.Forms.MenuItem("鼠标穿透", (obj, args) =>
                    {
                        NewsMachine.Settings.TransparentWindow = !NewsMachine.Settings.TransparentWindow;
                        var _this = obj as System.Windows.Forms.MenuItem;
                        _this.Checked = !_this.Checked;
                        if (_newsMachine != null && _newsMachine.Overlay != null)
                        {
                            _newsMachine.Cancel(true);
                        }
                    })
                {
                    Checked = true
                },
                new System.Windows.Forms.MenuItem("-"),
                new System.Windows.Forms.MenuItem("手动刷新", (obj, args) =>
                    {
                        if (_newsMachine != null)
                        {
                            _newsMachine.Reset();
                        }
                    }),
                new System.Windows.Forms.MenuItem("-"),
                new System.Windows.Forms.MenuItem("退出", (obj, args) =>
                    AnimateClose())
            });

            _newsMachine = new NewsMachine();
            _newsMachine.OnLogging += TraceOutput;
            _newsMachine.MainDispatcher = Dispatcher;
            _newsMachine.Start();
        }