public MainWindow() { CommonManager.Instance.NWMode = true; Settings.LoadFromXmlFileNW(); ChSet5.LoadFile(); cmd.SetSendMode(true); cmd.SetNWSetting(Settings.Instance.NWServerIP, Settings.Instance.NWServerPort); CommonManager.Instance.ReloadCustContentColorList(); CommonManager.Instance.DB.SetNoAutoReloadEPG(Settings.Instance.NgAutoEpgLoadNW); if (Settings.Instance.NoStyle == 0) { ResourceDictionary rd = new ResourceDictionary(); rd.MergedDictionaries.Add( Application.LoadComponent(new Uri("/PresentationFramework.Aero, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35;component/themes/aero.normalcolor.xaml", UriKind.Relative)) as ResourceDictionary //Application.LoadComponent(new Uri("/PresentationFramework.Classic, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, ProcessorArchitecture=MSIL;component/themes/Classic.xaml", UriKind.Relative)) as ResourceDictionary ); this.Resources = rd; } mutex = new System.Threading.Mutex(false, "Global\\EpgTimer_BonNW"); if (!mutex.WaitOne(0, false)) { CheckCmdLine(); mutex.Close(); mutex = null; closeFlag = true; Close(); return; } if (CommonManager.Instance.NWMode == false) { bool startExe = false; try { if (ServiceCtrlClass.ServiceIsInstalled("EpgTimer Service") == true) { if (ServiceCtrlClass.IsStarted("EpgTimer Service") == false) { bool check = false; for (int i = 0; i < 5; i++) { if (ServiceCtrlClass.StartService("EpgTimer Service") == true) { check = true; } System.Threading.Thread.Sleep(1000); if (ServiceCtrlClass.IsStarted("EpgTimer Service") == true) { check = true; } } if (check == false) { MessageBox.Show("サービスの開始に失敗しました。\r\nVista以降のOSでは、管理者権限で起動されている必要があります。"); closeFlag = true; Close(); return; } else { serviceMode = true; startExe = true; } } else { serviceMode = true; startExe = true; } } } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); serviceMode = false; } try { if (serviceMode == false) { String moduleFolder = System.IO.Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]); String exePath = moduleFolder + "\\EpgTimerSrv.exe"; System.Diagnostics.Process process = System.Diagnostics.Process.Start(exePath); startExe = true; } } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); startExe = false; } if (startExe == false) { MessageBox.Show("EpgTimerSrv.exeの起動ができませんでした"); closeFlag = true; Close(); return; } } InitializeComponent(); initExe = true; try { if (Settings.Instance.WakeMin == true) { this.Visibility = System.Windows.Visibility.Hidden; } //ウインドウ位置の復元 if (Settings.Instance.MainWndTop != -100) { this.Top = Settings.Instance.MainWndTop; } if (Settings.Instance.MainWndLeft != -100) { this.Left = Settings.Instance.MainWndLeft; } if (Settings.Instance.MainWndWidth != -100) { this.Width = Settings.Instance.MainWndWidth; } if (Settings.Instance.MainWndHeight != -100) { this.Height = Settings.Instance.MainWndHeight; } this.WindowState = Settings.Instance.LastWindowState; //上のボタン Button settingButton = new Button(); settingButton.MinWidth = 75; settingButton.Margin = new Thickness(2, 2, 2, 5); settingButton.Click += new RoutedEventHandler(settingButton_Click); settingButton.Content = "設定"; if (Settings.Instance.NoStyle == 0) { settingButton.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("設定", settingButton); Button searchButton = new Button(); searchButton.MinWidth = 75; searchButton.Margin = new Thickness(2, 2, 2, 5); searchButton.Click += new RoutedEventHandler(searchButton_Click); searchButton.Content = "検索"; if (Settings.Instance.NoStyle == 0) { searchButton.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("検索", searchButton); Button closeButton = new Button(); closeButton.MinWidth = 75; closeButton.Margin = new Thickness(2, 2, 2, 5); closeButton.Click += new RoutedEventHandler(closeButton_Click); closeButton.Content = "終了"; if (Settings.Instance.NoStyle == 0) { closeButton.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("終了", closeButton); Button stanbyButton = new Button(); stanbyButton.MinWidth = 75; stanbyButton.Margin = new Thickness(2, 2, 2, 5); stanbyButton.Click += new RoutedEventHandler(standbyButton_Click); stanbyButton.Content = "スタンバイ"; if (Settings.Instance.NoStyle == 0) { stanbyButton.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("スタンバイ", stanbyButton); Button suspendButton = new Button(); suspendButton.MinWidth = 75; suspendButton.Margin = new Thickness(2, 2, 2, 5); suspendButton.Click += new RoutedEventHandler(suspendButton_Click); suspendButton.Content = "休止"; if (Settings.Instance.NoStyle == 0) { suspendButton.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("休止", suspendButton); Button epgCapButton = new Button(); epgCapButton.MinWidth = 75; epgCapButton.Margin = new Thickness(2, 2, 2, 5); epgCapButton.Click += new RoutedEventHandler(epgCapButton_Click); epgCapButton.Content = "EPG取得"; if (Settings.Instance.NoStyle == 0) { epgCapButton.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("EPG取得", epgCapButton); Button epgReloadButton = new Button(); epgReloadButton.MinWidth = 75; epgReloadButton.Margin = new Thickness(2, 2, 2, 5); epgReloadButton.Click += new RoutedEventHandler(epgReloadButton_Click); epgReloadButton.Content = "EPG再読み込み"; if (Settings.Instance.NoStyle == 0) { epgReloadButton.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("EPG再読み込み", epgReloadButton); Button custum1Button = new Button(); custum1Button.MinWidth = 75; custum1Button.Margin = new Thickness(2, 2, 2, 5); custum1Button.Click += new RoutedEventHandler(custum1Button_Click); custum1Button.Content = "カスタム1"; if (Settings.Instance.NoStyle == 0) { custum1Button.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("カスタム1", custum1Button); Button custum2Button = new Button(); custum2Button.MinWidth = 75; custum2Button.Margin = new Thickness(2, 2, 2, 5); custum2Button.Click += new RoutedEventHandler(custum2Button_Click); custum2Button.Content = "カスタム2"; if (Settings.Instance.NoStyle == 0) { custum2Button.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("カスタム2", custum2Button); Button nwTVEndButton = new Button(); nwTVEndButton.MinWidth = 75; nwTVEndButton.Margin = new Thickness(2, 2, 2, 5); nwTVEndButton.Click += new RoutedEventHandler(nwTVEndButton_Click); nwTVEndButton.Content = "NetworkTV終了"; if (Settings.Instance.NoStyle == 0) { nwTVEndButton.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("NetworkTV終了", nwTVEndButton); Button logViewButton = new Button(); logViewButton.MinWidth = 75; logViewButton.Margin = new Thickness(2, 2, 2, 5); logViewButton.Click += new RoutedEventHandler(logViewButton_Click); logViewButton.Content = "情報通知ログ"; if (Settings.Instance.NoStyle == 0) { logViewButton.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("情報通知ログ", logViewButton); Button connectButton = new Button(); connectButton.MinWidth = 75; connectButton.Margin = new Thickness(2, 2, 2, 5); connectButton.Click += new RoutedEventHandler(connectButton_Click); connectButton.Content = "再接続"; if (Settings.Instance.NoStyle == 0) { connectButton.Style = (Style)App.Current.Resources["ButtonStyle1"]; } buttonList.Add("再接続", connectButton); ResetButtonView(); //タスクトレイの表示 taskTray = new TaskTrayClass(this); taskTray.Icon = Properties.Resources.TaskIconBlue; taskTray.Visible = true; taskTray.ContextMenuClick += new EventHandler(taskTray_ContextMenuClick); if (CommonManager.Instance.NWMode == false) { pipeServer = new PipeServer(); pipeName += System.Diagnostics.Process.GetCurrentProcess().Id.ToString(); pipeEventName += System.Diagnostics.Process.GetCurrentProcess().Id.ToString(); pipeServer.StartServer(pipeEventName, pipeName, OutsideCmdCallback, this); cmd.SendRegistGUI((uint)System.Diagnostics.Process.GetCurrentProcess().Id); CommonManager.Instance.DB.ReloadReserveInfo(); ReserveData item = new ReserveData(); if (CommonManager.Instance.DB.GetNextReserve(ref item) == true) { String timeView = item.StartTime.ToString("yyyy/MM/dd(ddd) HH:mm:ss ~ "); DateTime endTime = item.StartTime + TimeSpan.FromSeconds(item.DurationSecond); timeView += endTime.ToString("HH:mm:ss"); taskTray.Text = "次の予約:" + item.StationName + " " + timeView + " " + item.Title; } else { taskTray.Text = "次の予約なし"; } } ResetTaskMenu(); CheckCmdLine(); if (CommonManager.Instance.NWMode == true) { if (Settings.Instance.WakeReconnectNW == false) { return; } if (CommonManager.Instance.NW.ConnectServer(Settings.Instance.NWServerIP, Settings.Instance.NWServerPort, Settings.Instance.NWWaitPort, OutsideCmdCallback, this) == false) { return; } iniConnectNW = true; byte[] binData; if (cmd.SendFileCopy("ChSet5.txt", out binData) == 1) { string filePath = SettingPath.SettingFolderPath; System.IO.Directory.CreateDirectory(filePath); filePath += "\\ChSet5.txt"; using (System.IO.BinaryWriter w = new System.IO.BinaryWriter(System.IO.File.Create(filePath))) { w.Write(binData); w.Close(); } ChSet5.LoadFile(); } CommonManager.Instance.DB.ReloadReserveInfo(); ReserveData item = new ReserveData(); if (CommonManager.Instance.DB.GetNextReserve(ref item) == true) { String timeView = item.StartTime.ToString("yyyy/MM/dd(ddd) HH:mm:ss ~ "); DateTime endTime = item.StartTime + TimeSpan.FromSeconds(item.DurationSecond); timeView += endTime.ToString("HH:mm:ss"); taskTray.Text = "次の予約:" + item.StationName + " " + timeView + " " + item.Title; } else { taskTray.Text = "次の予約なし"; } } } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); } }
public MainWindow() { Settings.LoadFromXmlFile(); CommonManager.Instance.NWMode = Settings.Instance.NWMode; CommonManager.Instance.MM.ReloadWorkData(); CommonManager.Instance.ReloadCustContentColorList(); Settings.Instance.ReloadOtherOptions(); CommonUtil.ApplyStyle(Settings.Instance.NoStyle == 0 ? Settings.Instance.StyleXamlPath : null); SemaphoreSecurity ss = new SemaphoreSecurity(); ss.AddAccessRule(new SemaphoreAccessRule("Everyone", SemaphoreRights.FullControl, AccessControlType.Allow)); semaphore = new Semaphore(int.MaxValue, int.MaxValue, "Global\\EpgTimer_Bon3", out firstInstance, ss); semaphore.WaitOne(0); if (!firstInstance && Settings.Instance.ApplyMultiInstance == false) { ConnectSrv(); DisconnectServer(); semaphore.Release(); semaphore.Close(); semaphore = null; CloseCmd(); return; } InitializeComponent(); #if DEBUG appName += "(debug)"; #endif initExe = true; try { infoWindowViewModel = new InfoWindowViewModel(); // 多重起動時は最小化しない if (firstInstance && Settings.Instance.WakeMin == true) { // Icon化起動すると Windows_Loaded イベントが来ないので // InitializeComponent 後に ConnectCmd しておく。 Dispatcher.BeginInvoke(new Action(() => ConnectCmd(Settings.Instance.NWMode && Settings.Instance.WakeReconnectNW == false) ), DispatcherPriority.Loaded); if (Settings.Instance.ShowTray && Settings.Instance.MinHide) { this.Visibility = Visibility.Hidden; } else { Dispatcher.BeginInvoke(new Action(() => { this.WindowState = System.Windows.WindowState.Minimized; minimizedStarting = true; })); } } //ウインドウ位置の復元 if (Settings.Instance.MainWndTop != -100) { this.Top = Settings.Instance.MainWndTop; } if (Settings.Instance.MainWndLeft != -100) { this.Left = Settings.Instance.MainWndLeft; } if (Settings.Instance.MainWndWidth != -100) { this.Width = Settings.Instance.MainWndWidth; } if (Settings.Instance.MainWndHeight != -100) { this.Height = Settings.Instance.MainWndHeight; } this.WindowState = Settings.Instance.LastWindowState; //上のボタン Action<string, Action> ButtonGen = (key, handler) => { Button btn = new Button(); btn.MinWidth = 75; btn.Margin = new Thickness(2, 2, 2, 5); btn.Click += (sender, e) => handler(); btn.Content = key; buttonList.Add(key, btn); }; ButtonGen("設定", OpenSettingDialog); ButtonGen("再接続", OpenConnectDialog); ButtonGen("再接続(前回)", () => ConnectCmd()); ButtonGen("検索", OpenSearchDialog); ButtonGen("スタンバイ", () => SuspendCmd(1)); ButtonGen("休止", () => SuspendCmd(2)); ButtonGen("終了", CloseCmd); ButtonGen("EPG取得", EpgCapCmd); ButtonGen("EPG再読み込み", EpgReloadCmd); ButtonGen("NetworkTV終了", NwTVEndCmd); ButtonGen("情報通知ログ", OpenNotifyLogDialog); ButtonGen("予約簡易表示", () => ShowInfoWindow()); ButtonGen("カスタム1", () => CustumCmd(1)); ButtonGen("カスタム2", () => CustumCmd(2)); ButtonGen("カスタム3", () => CustumCmd(3)); //検索ボタンは他と共通でショートカット割り振られているので、その部分はコマンド側で処理する。 this.CommandBindings.Add(new CommandBinding(EpgCmds.Search, (sender, e) => CommonButtons_Click("検索"))); mBinds.AddInputCommand(EpgCmds.Search); SetSearchButtonTooltip(buttonList["検索"]); StatusbarReset();//ステータスバーリセット if(Settings.Instance.InfoWindowEnabled) { ShowInfoWindow(); } //タスクトレイの表示 taskTray = new TaskTrayClass(this); if (CommonManager.Instance.NWMode == true && Settings.Instance.ChkSrvRegistTCP == true) { taskTray.Icon = TaskIconSpec.TaskIconGray; } else { taskTray.Icon = TaskIconSpec.TaskIconBlue; } taskTray.ContextMenuClick += (sender, e) => CommonButtons_Click(sender as string); ResetMainView(); //初期タブ選択 switch (Settings.Instance.StartTab) { //case CtxmCode.ReserveView: // this.tabItem_reserve.IsSelected = true; // break; case CtxmCode.TunerReserveView: this.tabItem_tunerReserve.IsSelected = true; break; case CtxmCode.RecInfoView: this.tabItem_recinfo.IsSelected = true; break; case CtxmCode.EpgAutoAddView: this.tabItem_AutoAdd.IsSelected = true; // this.autoAddView.tabItem_epgAutoAdd.IsSelected = true; break; case CtxmCode.ManualAutoAddView: this.tabItem_AutoAdd.IsSelected = true; this.autoAddView.tabItem_manualAutoAdd.IsSelected = true; break; case CtxmCode.EpgView: this.tabItem_epg.IsSelected = true; break; } } catch (Exception ex) { ExceptionLogger.Log(ex); MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); } }
public MainWindow() { Settings.LoadFromXmlFile(); CommonManager.Instance.NWMode = Settings.Instance.NWMode; CommonManager.Instance.MM.ReloadWorkData(); CommonManager.Instance.ReloadCustContentColorList(); if (Settings.Instance.NoStyle == 0) { if (System.IO.File.Exists(System.Reflection.Assembly.GetEntryAssembly().Location + ".rd.xaml")) { //ResourceDictionaryを定義したファイルがあるので本体にマージする try { App.Current.Resources.MergedDictionaries.Add( (ResourceDictionary)System.Windows.Markup.XamlReader.Load( System.Xml.XmlReader.Create(System.Reflection.Assembly.GetEntryAssembly().Location + ".rd.xaml"))); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } else { //既定のテーマ(Aero)をマージする App.Current.Resources.MergedDictionaries.Add( Application.LoadComponent(new Uri("/PresentationFramework.Aero, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35;component/themes/aero.normalcolor.xaml", UriKind.Relative)) as ResourceDictionary ); } } SemaphoreSecurity ss = new SemaphoreSecurity(); ss.AddAccessRule(new SemaphoreAccessRule("Everyone", SemaphoreRights.FullControl, AccessControlType.Allow)); semaphore = new Semaphore(int.MaxValue, int.MaxValue, "Global\\EpgTimer_Bon2", out firstInstance, ss); semaphore.WaitOne(0); if (!firstInstance) { CheckCmdLine(); if (Settings.Instance.ApplyMultiInstance == false) { semaphore.Release(); semaphore.Close(); semaphore = null; CloseCmd(); return; } } InitializeComponent(); initExe = true; try { // 多重起動時は最小化しない if (firstInstance && Settings.Instance.WakeMin == true) { // Icon化起動すると Windows_Loaded イベントが来ないので // InitializeComponent 後に ConnectCmd しておく。 if (Settings.Instance.NWMode == false || Settings.Instance.WakeReconnectNW == true) { ConnectCmd(false); } if (Settings.Instance.ShowTray && Settings.Instance.MinHide) { this.Visibility = Visibility.Hidden; } else { Dispatcher.BeginInvoke(new Action(() => { this.WindowState = System.Windows.WindowState.Minimized; })); } } //ウインドウ位置の復元 if (Settings.Instance.MainWndTop != -100) { this.Top = Settings.Instance.MainWndTop; } if (Settings.Instance.MainWndLeft != -100) { this.Left = Settings.Instance.MainWndLeft; } if (Settings.Instance.MainWndWidth != -100) { this.Width = Settings.Instance.MainWndWidth; } if (Settings.Instance.MainWndHeight != -100) { this.Height = Settings.Instance.MainWndHeight; } this.WindowState = Settings.Instance.LastWindowState; //上のボタン Action<string, RoutedEventHandler> ButtonGen = (key, handler) => { Button btn = new Button(); btn.MinWidth = 75; btn.Margin = new Thickness(2, 2, 2, 5); if (handler != null) btn.Click += new RoutedEventHandler(handler); btn.Content = key; buttonList.Add(key, btn); }; ButtonGen("設定", settingButton_Click); ButtonGen("検索", null); ButtonGen("終了", closeButton_Click); ButtonGen("スタンバイ", standbyButton_Click); ButtonGen("休止", suspendButton_Click); ButtonGen("EPG取得", epgCapButton_Click); ButtonGen("EPG再読み込み", epgReloadButton_Click); ButtonGen("カスタム1", custum1Button_Click); ButtonGen("カスタム2", custum2Button_Click); ButtonGen("NetworkTV終了", nwTVEndButton_Click); ButtonGen("情報通知ログ", logViewButton_Click); ButtonGen("再接続", connectButton_Click); ButtonGen("予約簡易表示", showInfoWindowButton_Click); //検索ボタンは他と共通でショートカット割り振られているので、コマンド側で処理する。 this.CommandBindings.Add(new CommandBinding(EpgCmds.Search, searchButton_Click)); mBinds.SetCommandToButton(buttonList["検索"], EpgCmds.Search); RefreshButton(); ResetButtonView(); //タスクトレイの表示 taskTray = new TaskTrayClass(this); taskTray.Icon = Properties.Resources.TaskIconBlue; taskTray.Visible = Settings.Instance.ShowTray; taskTray.ContextMenuClick += new EventHandler(taskTray_ContextMenuClick); taskTray.Text = GetTaskTrayReserveInfoText(); ResetTaskMenu(); CheckCmdLine(); // 設定から情報を読み取るので設定をロードした後作る infoWindowViewModel = new InfoWindowViewModel(); if(Settings.Instance.InfoWindowEnabled) { ShowInfoWindow(); } } catch (Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); } }
private static IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { TaskTrayClass self = hwndDictionary.SingleOrDefault(a => a.Value.Handle == hwnd).Key; if (msg == WM_APP_TRAY && self != null) { const int WM_LBUTTONUP = 0x0202; const int WM_RBUTTONUP = 0x0205; const int NIN_BALLOONSHOW = 0x0402; const int NIN_BALLOONHIDE = 0x0403; const int NIN_BALLOONTIMEOUT = 0x0404; switch (lParam.ToInt32() & 0xFFFF) { case WM_LBUTTONUP: if (self.targetWindow is ITaskTrayClickHandler) { ((ITaskTrayClickHandler)self.targetWindow).TaskTrayLeftClick(); } break; case WM_RBUTTONUP: if (self.targetWindow is ITaskTrayClickHandler) { ((ITaskTrayClickHandler)self.targetWindow).TaskTrayRightClick(); } break; case NIN_BALLOONSHOW: if (self.ForceHideBalloonTipSec > 0) { // 指定タイムアウトでバルーンチップを強制的に閉じる if (self.balloonTimer == null) { self.balloonTimer = new System.Windows.Threading.DispatcherTimer(); self.balloonTimer.Tick += (sender, e) => { if (self.Visible) { self.Visible = false; self.Visible = true; } self.balloonTimer.Stop(); }; } self.balloonTimer.Interval = TimeSpan.FromSeconds(self.ForceHideBalloonTipSec); self.balloonTimer.Start(); } break; case NIN_BALLOONHIDE: case NIN_BALLOONTIMEOUT: if (self.balloonTimer != null) { self.balloonTimer.Stop(); } break; } } else if (msg == (int)CommonUtil.RegisterTaskbarCreatedWindowMessage() && self != null) { self.Visible = self.Visible; } return(IntPtr.Zero); }
static TrayManager() { Tray = new TaskTrayClass(CommonManager.MainWindow); }
static TrayManager() { Tray = new TaskTrayClass(); }