private void Window_Loaded(object sender, RoutedEventArgs e) { try { // set up the tray icon System.Windows.Forms.NotifyIcon notifyIcon = _trayIcon = new System.Windows.Forms.NotifyIcon { Icon = new System.Drawing.Icon("Resources\\icon.ico"), Text = Title, Visible = true }; _trayIcon.DoubleClick += delegate(object sender2, EventArgs args) { Show(); WindowState = WindowState.Normal; }; // grab the handles of everything we'll be tweaking _taskbar = new TaskbarElement("Shell_TrayWnd"); _startButton = new TaskbarElement(_taskbar, "Start", 1); _startMenu = new TaskbarElement("Windows.UI.Core.CoreWindow", "Start"); // get the buttons on the taskbar that directly have the taskbar as a parent for (int i = 0; i < 3; i++) { _taskbarButtons[i] = new TaskbarElement(_taskbar, "TrayButton", (i + 1)); } _cortanaButton = new TaskbarElement(_taskbar, "TrayButton", 1); _cortanaSearchMenu = new TaskbarElement("Windows.UI.Core.CoreWindow", "Cortana"); _mainAppContainer = new TaskbarElement(_taskbar, "ReBarWindow32", 1); _trayIconContainer = new TaskbarElement(_taskbar, "TrayNotifyWnd", 1); //_volumeContainer = new TaskbarElement(_taskbar, "") _showDesktopButton = new TaskbarElement(_trayIconContainer, "TrayShowDesktopButtonWClass", 1); // set up sliders SliderTaskWidth.Maximum = _taskbar.GetWidth(); //if (CheckAutoStart.IsChecked == true) { // create an instance of a dummy taskbar with some settings _dummyTaskbar = new Window(); _dummyTaskbar.WindowState = WindowState.Normal; _dummyTaskbar.WindowStyle = WindowStyle.None; _dummyTaskbar.ResizeMode = ResizeMode.NoResize; _dummyTaskbar.Width = _taskBarWidth; _dummyTaskbar.Height = _taskbar.GetHeight(); _dummyTaskbar.Top = _taskbar.GetTop(); _dummyTaskbar.Left = (_taskbar.GetWidth() / 2) - _dummyTaskbar.Width / 2; _dummyTaskbar.AllowsTransparency = true; UpdateDummySliders(); _dummyTaskbar.ShowInTaskbar = false; _dummyTaskbar.Hide(); //} } catch (Exception ex) { using (StreamWriter sw = new StreamWriter("debug.txt")) { sw.WriteLine(ex); } } if (!File.Exists("settings.json")) { CreateSettings(); _settings.LoadSettings(); } else { _settings.LoadSettings(); //TODO (justin): add some error checking here SliderTaskWidth.Value = Convert.ToInt16(_settings.FindSetting("width").SettingValue); SliderDummyTaskRed.Value = Convert.ToByte(_settings.FindSetting("red").SettingValue); SliderDummyTaskGreen.Value = Convert.ToByte(_settings.FindSetting("green").SettingValue); SliderDummyTaskBlue.Value = Convert.ToByte(_settings.FindSetting("blue").SettingValue); SliderDummyTaskOpacity.Value = Convert.ToByte(_settings.FindSetting("opacity").SettingValue); CheckTaskbarVisible.IsChecked = Convert.ToBoolean(_settings.FindSetting("showtaskbar").SettingValue); CheckHideStart.IsChecked = Convert.ToBoolean(_settings.FindSetting("hidestartbutton").SettingValue); CheckHideShowDesk.IsChecked = Convert.ToBoolean(_settings.FindSetting("hideshowdesktopbutton").SettingValue); CheckAutoStart.IsChecked = Convert.ToBoolean(_settings.FindSetting("autostart").SettingValue); CheckLaunchWithWindows.IsChecked = Convert.ToBoolean(_settings.FindSetting("launchwithwindows").SettingValue); } textBoxSettings.Text = File.ReadAllText("settings.json"); _dummyTaskbar?.Show(); Focus(); // set up background worker _bgWorker = new BackgroundWorker { WorkerSupportsCancellation = true }; _bgWorker.DoWork += _bgWorker_DoWork; // TODO: create method for the button click action // because this is stupid if (CheckAutoStart.IsChecked == true) { ButtonStart_Click(null, null); } }
private void ApplyStyle() { // make taskbar transparent if (CheckTaskbarVisible.IsChecked == true) { // show the taskbar _taskbar.AccentPolicy.AccentState = Utility.AccentState.ACCENT_DISABLED; _taskbar.ApplyAccentPolicy(); } else { // hide the taskbar _taskbar.AccentPolicy.AccentState = Utility.AccentState.ACCENT_INVALID_STATE; _taskbar.ApplyAccentPolicy(); } // make sure the dummy taskbar maintains position _dummyTaskbar.Top = _taskbar.GetTop(); _dummyTaskbar.Width = _taskBarWidth; _dummyTaskbar.Left = (_taskbar.GetWidth() / 2) - _dummyTaskbar.Width / 2; _dummyTaskbar.Height = _taskbar.GetHeight(); //_dummyTaskbar.Background = new SolidColorBrush(Color.FromArgb((byte)SliderDummyTaskOpacity.Value, 0, 0, 0)); UpdateDummySliders(); // get the offsets of buttons that may or may not be visible int offset = 0; // (_startButton.IsElementVisible() ? _startButton.GetWidth() : 0); for (int i = 0; i < 3; i++) { offset += _taskbarButtons[i].IsElementVisible() ? _taskbarButtons[i].GetWidth() : 0; } // resize the app container and then move it into position _mainAppContainer.ResizeElement((int)_dummyTaskbar.Width - _trayIconContainer.GetWidth() - offset - 32); _mainAppContainer.MoveElement((int)_dummyTaskbar.Left + offset + 32); // move the start button into position if (_startButton.IsElementVisible()) { _startButton.MoveElement((int)_dummyTaskbar.Left); } // show or hide the show desktopbutton if (CheckHideShowDesk.IsChecked == true) { _showDesktopButton.HideElement(); } else { _showDesktopButton.ShowElement(); } // move taskbar buttons into position for (int i = 0; i < 3; i++) { if (_taskbarButtons[i].IsElementVisible()) { _taskbarButtons[i].MoveElement((int)_dummyTaskbar.Left + offset - (_taskbarButtons[i].GetWidth() * i)); } } // move the start menu into the correct position if (_dummyTaskbar.Top == 0) { _startMenu.MoveElement((int)_dummyTaskbar.Left, (int)_dummyTaskbar.Height); _cortanaSearchMenu.MoveElement((int)_dummyTaskbar.Left, (int)_dummyTaskbar.Height); } else { _startMenu.MoveElement((int)_dummyTaskbar.Left); _cortanaSearchMenu.MoveElement((int)_dummyTaskbar.Left, (int)_dummyTaskbar.Top - (_cortanaSearchMenu.GetHeight())); } // move the tray icon container into position _trayIconContainer.MoveElement((int)_dummyTaskbar.Left + (int)_dummyTaskbar.Width - _trayIconContainer.GetWidth()); }