现在的位置: 首页 > 综合 > 正文

NotifyIconDome

2013年06月24日 ⁄ 综合 ⁄ 共 2553字 ⁄ 字号 评论关闭

/*
 * Created by SharpDevelop.
 * Author: MXi4oyu
 * Email:798033502@qq.com
 * Date: 2013-7-2
 * Time: 23:35
 */
using System;
using System.Diagnostics;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;

namespace NotifyIconDome
{
    public sealed class NotificationIcon
    {
        private NotifyIcon notifyIcon;
        private ContextMenu notificationMenu;
        
        #region Initialize icon and menu
        public NotificationIcon()
        {
            notifyIcon = new NotifyIcon();
            notificationMenu = new ContextMenu(InitializeMenu());
            
            notifyIcon.DoubleClick += IconDoubleClick;
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(NotificationIcon));
            notifyIcon.Icon = (Icon)resources.GetObject("QQ2013");
            notifyIcon.ContextMenu = notificationMenu;
        }
        
        private MenuItem[] InitializeMenu()
        {
            MenuItem[] menu = new MenuItem[] {
                new MenuItem("About", menuAboutClick)
            };
            return menu;
        }
        #endregion
        
        #region Main - Program entry point
        /// <summary>Program entry point.</summary>
        /// <param name="args">Command
Line Arguments</param>

        [STAThread]
        public static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            
            bool isFirstInstance;
            // Please use a unique name for the mutex to prevent conflicts with other programs
            using (Mutex mtx = new Mutex(true"NotifyIconDome"out isFirstInstance)) {
                if (isFirstInstance) {
                    NotificationIcon notificationIcon = new NotificationIcon();
                    notificationIcon.notifyIcon.Visible = true;
                    Application.Run();
                    notificationIcon.notifyIcon.Dispose();
                } else {
                    // The application is already running
                    // TODO: Display message box or change focus to existing application instance
                }
            } // releases the Mutex
        }
        #endregion
        
        #region Event Handlers
        private void menuAboutClick(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start(@"http://blog.sina.com.cn/xi4oyu");
        }
        
        private void IconDoubleClick(object sender, EventArgs e)
        {
            System.Diagnostics.Process.Start(@"http://itbook.taobao.com");
        }
        #endregion
    }
}

抱歉!评论已关闭.