/// <summary> /// Creates new instance of the class. /// </summary> public WinMsgTarget(SystemTrayControl TrayControl) { this.TrayControl = TrayControl; this.Text = "Windows messages target window"; UserMessage = RegisterWindowMessage("Diacom Tray Control Message"); TrayCreatedMessage = RegisterWindowMessage("TaskbarCreated"); }
/// <summary> /// Initializes tray icon components. /// </summary> private void InitializeTray() { this.components = new System.ComponentModel.Container(); // Icons. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(GetType()); this.ServiceIsPendingIcon = ((System.Drawing.Icon)(resources.GetObject("Icon_INI.ico"))); this.ServiceIsRunningIcon = ((System.Drawing.Icon)(resources.GetObject("Icon_ST.ico"))); this.ServiceIsStoppedIcon = ((System.Drawing.Icon)(resources.GetObject("Icon_OK.ico"))); this.ServiceNotControlledIcon = ((System.Drawing.Icon)(resources.GetObject("Icon_NON.ico"))); this.ServiceProviderIsNotOKIcon = ((System.Drawing.Icon)(resources.GetObject("Icon_ERR.ico"))); this.ServiceConfiguredIcon = ((System.Drawing.Icon)(resources.GetObject("Icon_NON.ico"))); // Context Menu. // About. this.CMIAbout.Index = 0; this.CMIAbout.Text = "About"; this.CMIAbout.Click += new EventHandler(CMIAbout_Click); // Separator #0. this.CMISeparator0.Index = 1; this.CMISeparator0.Text = "-"; // Configure APCService. this.CMIConfigureAPCService.Index = 2; this.CMIConfigureAPCService.DefaultItem = true; this.CMIConfigureAPCService.Text = "Configure APCService"; this.CMIConfigureAPCService.Click += new EventHandler(CMIConfigureAPCService_Click); // Configure Control Tool. this.CMIConfigureControlTool.Index = 3; this.CMIConfigureControlTool.Text = "Configure Control Tool"; this.CMIConfigureControlTool.Click += new EventHandler(CMIConfigureControlTool_Click); // Separator #1. this.CMISeparator1.Index = 4; this.CMISeparator1.Text = "-"; // Start APCService. this.CMIStartService.Index = 5; this.CMIStartService.Text = "Start APCService"; this.CMIStartService.Click += new EventHandler(CMIStartService_Click); // Restart APCService. this.CMIRestartService.Index = 6; this.CMIRestartService.Text = "Restart APCService"; this.CMIRestartService.Click += new EventHandler(CMIRestartService_Click); // Stop APCService. this.CMIStopService.Index = 7; this.CMIStopService.Text = "Stop APCService"; this.CMIStopService.Click += new EventHandler(CMIStopService_Click); // Separator #2. this.CMISeparator2.Index = 8; this.CMISeparator2.Text = "-"; // Exit. this.CMIExit.Index = 9; this.CMIExit.Text = "Exit"; this.CMIExit.Click += new EventHandler(CMIExit_Click); // Adding items. this.TrayMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] { this.CMIAbout, this.CMISeparator0, this.CMIConfigureAPCService, this.CMIConfigureControlTool, this.CMISeparator1, this.CMIStartService, this.CMIRestartService, this.CMIStopService, this.CMISeparator2, this.CMIExit }); this.TrayMenu.Popup += new EventHandler(ContextMenu_Popup); // Connect it to the tray this.Tray = new SystemTrayControl(ServiceNotControlledIcon); this.Tray.Menu = this.TrayMenu; this.Tray.Visible = false; this.Tray.LeftMouseButtonDoubleClick += new EventHandler(this.OnDoubleClick); // // Timer (disabled yet). // this.Timer = new System.Windows.Forms.Timer(this.components); this.Timer.Tick += new EventHandler(this.OnTimerTick); this.Timer.Interval = 1000; this.Timer.Enabled = false; // // Load options from the serialized file. System.IO.FileStream fs = null; try { SoapFormatter optFormatter = new SoapFormatter(); fs = new System.IO.FileStream(iniFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite); this.APCSrvOpt = ((APCServiceOptions)(optFormatter.Deserialize(fs))); } catch (Exception _x) { System.Diagnostics.Debug.WriteLine(_x.ToString()); this.APCSrvOpt = new APCServiceOptions(); ShowMessage(MessageType.WarningNoOptionsFile, null, "APCService Control Tool will run with default options"); } finally { if (fs != null) { fs.Close(); } } // Seting own properties. this.Info = String.Format("Controlling \\\\{0}", this.APCSrvOpt.MachineName); // Service controller. if (this.GetServiceController()) { this.Tray.Text = "Connection established."; } else { this.Tray.Text = "Connection refused."; } this.Tray.Visible = true; // Enabling timer. this.Timer.Enabled = true; }