コード例 #1
0
ファイル: SysTrayApp.cs プロジェクト: noproblan/npl-vhdgamer
        public SysTrayApp()
        {
            // create vhdpath directory, if it doesnt exist
            String localVhdBasePath = Path.Combine(Application.StartupPath, Options.vhdlocalpath);
            if (!Directory.Exists(localVhdBasePath))
            {
                Directory.CreateDirectory(localVhdBasePath);
            }
            gamesLibrary = new GamesLibrary(new VhdStorage(new DirectoryInfo(localVhdBasePath)));

            lobby = new Lobby();
            lobby.Listen();

            /******************************************************************************************
             * Announce Own Games every 10s
             *****************************************************************************************/
            this.announcingTimer = new Timer();
            this.announcingTimer.Interval = Options.ANNOUNCING_INTERVAL;
            this.announcingTimer.Tick += delegate(object o, EventArgs e) {
                lobby.Send(new AnnouncementMessage(new UserInfo(Options.nickname), gamesLibrary.GetGameNames()));
            };
            this.announcingTimer.Start();

            /******************************************************************************************
             * GUI Init
             *****************************************************************************************/
            trayIcon = new NotifyIcon();
            trayIcon.Text = "vhdgamer";
            trayIcon.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath);

            // Add menu to tray icon and show it.
            trayMenu = new ContextMenu();
            trayMenu.Popup += delegate { updateContextMenu(); };

            trayIcon.ContextMenu = trayMenu;
            trayIcon.MouseClick += new MouseEventHandler(trayIcon_Click);
            trayIcon.Visible = true;

            updateContextMenu();

            // info for user (if click on tooltop -> show menu)
            trayIcon.ShowBalloonTip(1000, "vhdgamer", "Click here to start or download games...", ToolTipIcon.Info);
            trayIcon.BalloonTipClicked += delegate { trayIcon.GetType().InvokeMember("ShowContextMenu", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, trayIcon, null); };
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: noproblan/npl-vhdgamer
        static void Main(string[] args)
        {
            Lobby localLobby = new Lobby();
            localLobby.OnMessageReveived += delegate(object o, MessageEventArgs e) {
                Console.WriteLine("RX: " + ((ChatMessage)e.Message).Text);
            };
            localLobby.Listen();

            Thread.Sleep(2000);

            localLobby.Send(new ChatMessage("Hallo"));

            Thread.Sleep(2000);

            localLobby.StopListening();

            //Lobby externalLobby = new Lobby(54321, 12345);
            //externalLobby.OnMessageSent += delegate(object o, MessageEventArgs e) {
            //    Console.WriteLine("TX: " + ((ChatMessage)e.Message).Text);
            //};
            //externalLobby.Send(new ChatMessage("Hallo"));
        }