diff --git a/ContextMenuManager/BluePointLilac.Controls/MyListBox.cs b/ContextMenuManager/BluePointLilac.Controls/MyListBox.cs index 1aeea2a5..3d751c49 100644 --- a/ContextMenuManager/BluePointLilac.Controls/MyListBox.cs +++ b/ContextMenuManager/BluePointLilac.Controls/MyListBox.cs @@ -11,7 +11,7 @@ public class MyListBox : Panel public MyListBox() { this.AutoScroll = true; - this.BackColor = Color.FromArgb(250, 250, 250); + this.BackColor = ContextMenuManager.Methods.AppTheme.FormBack; } protected override void OnMouseWheel(MouseEventArgs e) @@ -52,14 +52,14 @@ public MyListItem HoveredItem if(hoveredItem == value) return; if(hoveredItem != null) { - hoveredItem.ForeColor = Color.FromArgb(90, 90, 90); + hoveredItem.ForeColor = ContextMenuManager.Methods.AppTheme.PanelFore; //hoveredItem.BackColor = Color.FromArgb(250, 250, 250); //hoveredItem.Font = new Font(hoveredItem.Font, FontStyle.Regular); } hoveredItem = value; if(hoveredItem != null) { - value.ForeColor = Color.FromArgb(0, 138, 217); + value.ForeColor = ContextMenuManager.Methods.AppTheme.ItemSelected; //value.BackColor = Color.FromArgb(200, 230, 250); //value.Font = new Font(hoveredItem.Font, FontStyle.Bold); value.Focus(); @@ -154,8 +154,8 @@ public MyListItem() this.Height = 50.DpiZoom(); this.Margin = new Padding(0); this.Font = SystemFonts.IconTitleFont; - this.ForeColor = Color.FromArgb(80, 80, 80); - this.BackColor = Color.FromArgb(250, 250, 250); + this.ForeColor = ContextMenuManager.Methods.AppTheme.Text; + this.BackColor = ContextMenuManager.Methods.AppTheme.FormBack; this.Controls.AddRange(new Control[] { lblSeparator, flpControls, lblText, picImage }); this.Resize += (Sender, e) => pnlScrollbar.Height = this.ClientSize.Height; flpControls.MouseClick += (sender, e) => this.OnMouseClick(e); @@ -224,7 +224,7 @@ public bool HasImage }; private readonly Label lblSeparator = new Label { - BackColor = Color.FromArgb(220, 220, 220), + BackColor = ContextMenuManager.Methods.AppTheme.Separator, Dock = DockStyle.Bottom, Name = "Separator", Height = 1 diff --git a/ContextMenuManager/BluePointLilac.Controls/MyMainForm.cs b/ContextMenuManager/BluePointLilac.Controls/MyMainForm.cs index 1e5a1d0d..0391eb3f 100644 --- a/ContextMenuManager/BluePointLilac.Controls/MyMainForm.cs +++ b/ContextMenuManager/BluePointLilac.Controls/MyMainForm.cs @@ -11,8 +11,8 @@ public MyMainForm() { this.SuspendLayout(); this.Text = Application.ProductName; - this.ForeColor = Color.FromArgb(80, 80, 80); - this.BackColor = Color.FromArgb(250, 250, 250); + this.ForeColor = ContextMenuManager.Methods.AppTheme.FormFore; + this.BackColor = ContextMenuManager.Methods.AppTheme.FormBack; this.StartPosition = FormStartPosition.CenterScreen; this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); this.Controls.AddRange(new Control[] { MainBody, SideBar, StatusBar, ToolBar }); diff --git a/ContextMenuManager/BluePointLilac.Controls/MySideBar.cs b/ContextMenuManager/BluePointLilac.Controls/MySideBar.cs index 8dc75ebc..c419b118 100644 --- a/ContextMenuManager/BluePointLilac.Controls/MySideBar.cs +++ b/ContextMenuManager/BluePointLilac.Controls/MySideBar.cs @@ -1,4 +1,4 @@ -using BluePointLilac.Methods; +using BluePointLilac.Methods; using System; using System.Drawing; using System.Windows.Forms; @@ -13,8 +13,8 @@ public MySideBar() this.ItemHeight = 30.DpiZoom(); this.Font = SystemFonts.MenuFont; this.Font = new Font(this.Font.FontFamily, this.Font.Size + 1F); - this.ForeColor = Color.FromArgb(80, 80, 80); - this.BackColor = Color.FromArgb(245, 245, 245); + this.ForeColor = ContextMenuManager.Methods.AppTheme.PanelFore; + this.BackColor = ContextMenuManager.Methods.AppTheme.PanelBack; this.BackgroundImageLayout = ImageLayout.None; this.Controls.AddRange(new Control[] { LblSeparator, PnlSelected, PnlHovered }); PnlHovered.Paint += PaintItem; @@ -81,19 +81,19 @@ public Color HoveredForeColor readonly Panel PnlSelected = new Panel { - BackColor = Color.FromArgb(40, 140, 210), + BackColor = ContextMenuManager.Methods.AppTheme.ItemSelected, ForeColor = Color.White, Enabled = false }; readonly Panel PnlHovered = new Panel { - BackColor = Color.FromArgb(80, 180, 250), + BackColor = ContextMenuManager.Methods.AppTheme.ItemHover, ForeColor = Color.White, Enabled = false }; readonly Label LblSeparator = new Label { - BackColor = Color.FromArgb(220, 220, 220), + BackColor = ContextMenuManager.Methods.AppTheme.Separator, Dock = DockStyle.Right, Width = 1, }; @@ -212,5 +212,17 @@ public int HoveredIndex HoverIndexChanged?.Invoke(this, null); } } + + public void UpdateTheme() + { + this.ForeColor = ContextMenuManager.Methods.AppTheme.PanelFore; + this.BackColor = ContextMenuManager.Methods.AppTheme.PanelBack; + PnlSelected.BackColor = ContextMenuManager.Methods.AppTheme.ItemSelected; + PnlHovered.BackColor = ContextMenuManager.Methods.AppTheme.ItemHover; + LblSeparator.BackColor = ContextMenuManager.Methods.AppTheme.Separator; + PaintItems(); + RefreshItem(PnlSelected, SelectedIndex); + RefreshItem(PnlHovered, HoveredIndex); + } } } \ No newline at end of file diff --git a/ContextMenuManager/BluePointLilac.Controls/MyToolBar.cs b/ContextMenuManager/BluePointLilac.Controls/MyToolBar.cs index 6a2cf839..816d0bc8 100644 --- a/ContextMenuManager/BluePointLilac.Controls/MyToolBar.cs +++ b/ContextMenuManager/BluePointLilac.Controls/MyToolBar.cs @@ -1,4 +1,4 @@ -using BluePointLilac.Methods; +using BluePointLilac.Methods; using System; using System.Drawing; using System.Windows.Forms; @@ -12,7 +12,10 @@ public MyToolBar() this.Height = 80.DpiZoom(); this.Dock = DockStyle.Top; this.DoubleBuffered = true; - this.BackColor = Color.FromArgb(85, 145, 215); + if (ContextMenuManager.Methods.AppConfig.DarkTheme) + this.BackColor = Color.FromArgb(45, 45, 48); // Darker blue/grey for dark theme + else + this.BackColor = Color.FromArgb(85, 145, 215); } private MyToolBarButton selectedButton; @@ -79,6 +82,14 @@ public void AddButtons(MyToolBarButton[] buttons) Array.ForEach(buttons, button => maxWidth = Math.Max(maxWidth, TextRenderer.MeasureText(button.Text, button.Font).Width)); Array.ForEach(buttons, button => { button.Width = maxWidth; AddButton(button); }); } + + public void UpdateTheme() + { + if (ContextMenuManager.Methods.AppConfig.DarkTheme) + this.BackColor = Color.FromArgb(45, 45, 48); + else + this.BackColor = Color.FromArgb(85, 145, 215); + } } public sealed class MyToolBarButton : Panel diff --git a/ContextMenuManager/BluePointLilac.Methods/EncodingType.cs b/ContextMenuManager/BluePointLilac.Methods/EncodingType.cs index 52ed4c49..0ee0a790 100644 --- a/ContextMenuManager/BluePointLilac.Methods/EncodingType.cs +++ b/ContextMenuManager/BluePointLilac.Methods/EncodingType.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; @@ -49,8 +49,8 @@ private static bool IsUTF8Bytes(byte[] bytes) { if(curByte >= 0x80) { - //判断当前 - while(((curByte <<= 1) & 0x80) != 0) count++; + int tempByte = curByte; + while(((tempByte <<= 1) & 0x80) != 0) count++; //标记位首位若为非0 则至少以2个1开始 如:110XXXXX...........1111110X if(count == 1 || count > 6) return false; } diff --git a/ContextMenuManager/BluePointLilac.Methods/WinOsVersion.cs b/ContextMenuManager/BluePointLilac.Methods/WinOsVersion.cs index 1e0157ad..7758d921 100644 --- a/ContextMenuManager/BluePointLilac.Methods/WinOsVersion.cs +++ b/ContextMenuManager/BluePointLilac.Methods/WinOsVersion.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace BluePointLilac.Methods { @@ -25,5 +25,8 @@ public static class WinOsVersion public static readonly Version Win10_1909 = new Version(10, 0, 18363); public static readonly Version Win10_2004 = new Version(10, 0, 19041); public static readonly Version Win10_20H2 = new Version(10, 0, 19042); + public static readonly Version Win11 = new Version(10, 0, 22000); + + public static bool IsWin11 => Current >= Win11; } } \ No newline at end of file diff --git a/ContextMenuManager/ContextMenuManager.csproj b/ContextMenuManager/ContextMenuManager.csproj index 6482a480..658959df 100644 --- a/ContextMenuManager/ContextMenuManager.csproj +++ b/ContextMenuManager/ContextMenuManager.csproj @@ -1,4 +1,4 @@ - + @@ -198,6 +198,7 @@ + diff --git a/ContextMenuManager/Controls/AppSettingBox.cs b/ContextMenuManager/Controls/AppSettingBox.cs index 209293ba..21f4f526 100644 --- a/ContextMenuManager/Controls/AppSettingBox.cs +++ b/ContextMenuManager/Controls/AppSettingBox.cs @@ -1,4 +1,4 @@ -using BluePointLilac.Controls; +using BluePointLilac.Controls; using BluePointLilac.Methods; using ContextMenuManager.Methods; using System.Drawing; @@ -28,6 +28,8 @@ public AppSettingBox() mliOpenMoreExplorer.AddCtr(chkOpenMoreExplorer); mliHideDisabledItems.AddCtr(chkHideDisabledItems); mliHideSysStoreItems.AddCtr(chkHideSysStoreItems); + mliAppTheme.AddCtr(cmbAppTheme); + mliWin11ClassicMenu.AddCtr(chkWin11ClassicMenu); ToolTipBox.SetToolTip(btnUpdate, AppString.Tip.ImmediatelyCheck); ToolTipBox.SetToolTip(cmbConfigDir, AppString.Tip.ConfigPath); @@ -41,13 +43,16 @@ public AppSettingBox() cmbUpdate.Items.AddRange(new[] { AppString.Other.OnceAWeek, AppString.Other.OnceAMonth, AppString.Other.OnceASeason, AppString.Other.NeverCheck }); - cmbConfigDir.Width = cmbEngine.Width = cmbUpdate.Width = cmbRepo.Width = 120.DpiZoom(); + cmbAppTheme.Items.AddRange(new[] { "Light", "Dark", "Auto" }); + + cmbConfigDir.Width = cmbEngine.Width = cmbUpdate.Width = cmbRepo.Width = cmbAppTheme.Width = 120.DpiZoom(); cmbConfigDir.DropDownStyle = cmbEngine.DropDownStyle = cmbUpdate.DropDownStyle - = cmbRepo.DropDownStyle = ComboBoxStyle.DropDownList; + = cmbRepo.DropDownStyle = cmbAppTheme.DropDownStyle = ComboBoxStyle.DropDownList; cmbConfigDir.AutosizeDropDownWidth(); cmbEngine.AutosizeDropDownWidth(); cmbUpdate.AutosizeDropDownWidth(); cmbRepo.AutosizeDropDownWidth(); + cmbAppTheme.AutosizeDropDownWidth(); btnUpdate.MouseDown += (sender, e) => { @@ -70,9 +75,33 @@ public AppSettingBox() cmbUpdate.SelectionChangeCommitted += (sender, e) => ChangeUpdateFrequency(); cmbConfigDir.SelectionChangeCommitted += (sender, e) => ChangeConfigDir(); cmbEngine.SelectionChangeCommitted += (sender, e) => ChangeEngineUrl(); + cmbAppTheme.SelectionChangeCommitted += (sender, e) => + { + if(AppConfig.ThemeMode == cmbAppTheme.SelectedIndex) return; + AppConfig.ThemeMode = cmbAppTheme.SelectedIndex; + AppTheme.OnThemeChanged(); + }; + chkWin11ClassicMenu.CheckChanged += () => + { + Win11Helper.IsClassicMenuEnabled = chkWin11ClassicMenu.Checked; + ExplorerRestarter.Show(); + }; this.ResumeLayout(); } + readonly MyListItem mliAppTheme = new MyListItem + { + Text = "App Theme" + }; + readonly ComboBox cmbAppTheme = new ComboBox(); + + readonly MyListItem mliWin11ClassicMenu = new MyListItem + { + Text = AppString.Other.Win11ClassicMenu, + Visible = WinOsVersion.IsWin11 + }; + readonly MyCheckBox chkWin11ClassicMenu = new MyCheckBox(); + readonly MyListItem mliConfigDir = new MyListItem { Text = AppString.Other.ConfigPath @@ -163,7 +192,7 @@ public override void ClearItems() public void LoadItems() { - this.AddItems(new[] { mliConfigDir, mliUpdate, mliRepo, mliEngine, mliBackup, mliTopMost, mliProtect, mliShowFilePath, + this.AddItems(new[] { mliConfigDir, mliUpdate, mliRepo, mliEngine, mliBackup, mliAppTheme, mliWin11ClassicMenu, mliTopMost, mliProtect, mliShowFilePath, mliHideDisabledItems, mliHideSysStoreItems, mliOpenMoreRegedit, mliOpenMoreExplorer, mliWinXSortable }); foreach(MyListItem item in this.Controls) item.HasImage = false; cmbConfigDir.SelectedIndex = AppConfig.SaveToAppDir ? 1 : 0; @@ -179,6 +208,8 @@ public void LoadItems() chkOpenMoreExplorer.Checked = AppConfig.OpenMoreExplorer; chkHideDisabledItems.Checked = AppConfig.HideDisabledItems; chkHideSysStoreItems.Checked = AppConfig.HideSysStoreItems; + cmbAppTheme.SelectedIndex = AppConfig.ThemeMode; + chkWin11ClassicMenu.Checked = Win11Helper.IsClassicMenuEnabled; } private void ChangeConfigDir() diff --git a/ContextMenuManager/Controls/ShellList.cs b/ContextMenuManager/Controls/ShellList.cs index f5737618..5a675dbb 100644 --- a/ContextMenuManager/Controls/ShellList.cs +++ b/ContextMenuManager/Controls/ShellList.cs @@ -1,4 +1,4 @@ -using BluePointLilac.Controls; +using BluePointLilac.Controls; using BluePointLilac.Methods; using ContextMenuManager.Methods; using Microsoft.Win32; @@ -230,7 +230,7 @@ public void LoadItems() case Scenes.CommandStore: //Vista系统没有这一项 if(WinOsVersion.Current == WinOsVersion.Vista) return; - this.AddNewItem(RegistryEx.GetParentPath(ShellItem.CommandStorePath)); + this.AddNewItem(RegistryEx.GetParentPath(ObjectPath.CommandStorePath)); this.LoadStoreItems(); return; case Scenes.DragDrop: @@ -241,6 +241,7 @@ public void LoadItems() this.LoadShellExItems(GetShellExPath(MENUPATH_DRIVE)); this.LoadShellExItems(GetShellExPath(MENUPATH_ALLOBJECTS)); return; + } this.AddNewItem(scenePath); this.LoadItems(scenePath); @@ -371,11 +372,12 @@ private void AddNewItem(string scenePath) PictureButton btnEnhanceMenu = new PictureButton(AppImage.Enhance); ToolTipBox.SetToolTip(btnAddExisting, AppString.Tip.AddFromPublic); ToolTipBox.SetToolTip(btnEnhanceMenu, AppString.StatusBar.EnhanceMenu); - if(Scene == Scenes.DragDrop || ShellItem.CommandStorePath.Equals(shellPath, + if(Scene == Scenes.DragDrop || ObjectPath.CommandStorePath.Equals(shellPath, + StringComparison.OrdinalIgnoreCase) || ObjectPath.CommandStorePathCU.Equals(shellPath, StringComparison.OrdinalIgnoreCase)) btnAddExisting.Visible = false; else { - using(RegistryKey key = RegistryEx.GetRegistryKey(ShellItem.CommandStorePath)) + using(RegistryKey key = RegistryEx.GetRegistryKey(ObjectPath.CommandStorePath)) { List subKeyNames = key.GetSubKeyNames().ToList(); if(AppConfig.HideSysStoreItems) subKeyNames.RemoveAll(name => name.StartsWith("Windows.", StringComparison.OrdinalIgnoreCase)); @@ -410,7 +412,7 @@ private void AddNewItem(string scenePath) using(ShellStoreDialog dlg = new ShellStoreDialog()) { dlg.IsReference = false; - dlg.ShellPath = ShellItem.CommandStorePath; + dlg.ShellPath = ObjectPath.CommandStorePath; dlg.Filter = new Func(itemName => !(AppConfig.HideSysStoreItems && itemName.StartsWith("Windows.", StringComparison.OrdinalIgnoreCase))); if(dlg.ShowDialog() != DialogResult.OK) return; @@ -548,16 +550,21 @@ private void AddNewShellExItem(string scenePath) private void LoadStoreItems() { - using(RegistryKey shellKey = RegistryEx.GetRegistryKey(ShellItem.CommandStorePath)) + foreach(string path in new[] { ObjectPath.CommandStorePath, ObjectPath.CommandStorePathCU }) { - foreach(string itemName in shellKey.GetSubKeyNames()) + using(RegistryKey shellKey = RegistryEx.GetRegistryKey(path)) { - if(AppConfig.HideSysStoreItems && itemName.StartsWith("Windows.", StringComparison.OrdinalIgnoreCase)) continue; - this.AddItem(new StoreShellItem($@"{ShellItem.CommandStorePath}\{itemName}", true, false)); + if(shellKey == null) continue; + foreach(string itemName in shellKey.GetSubKeyNames()) + { + if(AppConfig.HideSysStoreItems && itemName.StartsWith("Windows.", StringComparison.OrdinalIgnoreCase)) continue; + this.AddItem(new StoreShellItem($@"{path}\{itemName}", true, false)); + } } } } + private void LoadUwpModeItem() { foreach(XmlDocument doc in XmlDicHelper.UwpModeItemsDic) diff --git a/ContextMenuManager/MainForm.cs b/ContextMenuManager/MainForm.cs index 853ab08d..51951817 100644 --- a/ContextMenuManager/MainForm.cs +++ b/ContextMenuManager/MainForm.cs @@ -1,4 +1,4 @@ -using BluePointLilac.Controls; +using BluePointLilac.Controls; using BluePointLilac.Methods; using ContextMenuManager.Controls; using ContextMenuManager.Methods; @@ -32,6 +32,54 @@ public MainForm() AddContextMenus(); ResizeSideBar(); JumpItem(0, 0); + + AppTheme.ThemeChanged += () => ApplyThemeToControls(this); + } + + protected override void WndProc(ref Message m) + { + base.WndProc(ref m); + const int WM_SETTINGCHANGE = 0x001A; + if(m.Msg == WM_SETTINGCHANGE && AppConfig.ThemeMode == 2) + { + AppTheme.OnThemeChanged(); + } + } + + private void ApplyThemeToControls(Control control) + { + if(control is Form form) + { + form.BackColor = AppTheme.FormBack; + form.ForeColor = AppTheme.FormFore; + } + else if(control is BluePointLilac.Controls.MySideBar sideBar) + { + sideBar.UpdateTheme(); + } + else if(control is BluePointLilac.Controls.MyToolBar toolBar) + { + toolBar.UpdateTheme(); + } + else if(control is MyListBox myListBox) + { + myListBox.BackColor = AppTheme.FormBack; + } + else if(control is MyListItem myListItem) + { + myListItem.BackColor = AppTheme.FormBack; + myListItem.ForeColor = AppTheme.Text; + if(myListItem.Controls.ContainsKey("Separator")) + { + myListItem.Controls["Separator"].BackColor = AppTheme.Separator; + } + } + + foreach(Control child in control.Controls) + { + ApplyThemeToControls(child); + } + control.Invalidate(true); } readonly MyToolBarButton[] ToolBarButtons = diff --git a/ContextMenuManager/Methods/AppConfig.cs b/ContextMenuManager/Methods/AppConfig.cs index dc51d2b7..44ece8e3 100644 --- a/ContextMenuManager/Methods/AppConfig.cs +++ b/ContextMenuManager/Methods/AppConfig.cs @@ -1,4 +1,4 @@ -using BluePointLilac.Methods; +using BluePointLilac.Methods; using System; using System.Collections.Generic; using System.Drawing; @@ -261,6 +261,44 @@ public static bool TopMost set => SetWindowValue("TopMost", value ? 1 : 0); } + public static int ThemeMode + { + get + { + string value = GetGeneralValue("ThemeMode"); + if(int.TryParse(value, out int mode) && mode >= 0 && mode <= 2) return mode; + return GetGeneralValue("DarkTheme") == "1" ? 1 : 0; + } + set => SetGeneralValue("ThemeMode", value); + } + + public static bool DarkTheme + { + get + { + if(ThemeMode == 1) return true; + if(ThemeMode == 0) return false; + return IsSystemDarkTheme(); + } + } + + public static bool IsSystemDarkTheme() + { + try + { + using(var key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Themes\Personalize")) + { + if(key != null) + { + object value = key.GetValue("AppsUseLightTheme"); + if(value is int v) return v == 0; + } + } + } + catch { } + return false; + } + public static Size MainFormSize { get @@ -276,4 +314,55 @@ public static Size MainFormSize set => SetWindowValue("MainFormSize", value.Width + "," + value.Height); } } + + public static class AppTheme + { + public static Color FormBack { get; private set; } + public static Color FormFore { get; private set; } + public static Color PanelBack { get; private set; } + public static Color PanelFore { get; private set; } + public static Color ItemHover { get; private set; } + public static Color ItemSelected { get; private set; } + public static Color Separator { get; private set; } + public static Color Text { get; private set; } + + static AppTheme() + { + Load(); + } + + public static event Action ThemeChanged; + + public static void Load() + { + if (AppConfig.DarkTheme) + { + FormBack = Color.FromArgb(30, 30, 30); + FormFore = Color.FromArgb(240, 240, 240); + PanelBack = Color.FromArgb(45, 45, 48); + PanelFore = Color.FromArgb(240, 240, 240); + ItemHover = Color.FromArgb(60, 60, 60); + ItemSelected = Color.FromArgb(0, 122, 204); + Separator = Color.FromArgb(80, 80, 80); + Text = Color.FromArgb(220, 220, 220); + } + else + { + FormBack = Color.FromArgb(250, 250, 250); + FormFore = Color.FromArgb(80, 80, 80); + PanelBack = Color.FromArgb(245, 245, 245); + PanelFore = Color.FromArgb(80, 80, 80); + ItemHover = Color.FromArgb(80, 180, 250); + ItemSelected = Color.FromArgb(40, 140, 210); + Separator = Color.FromArgb(220, 220, 220); + Text = Color.FromArgb(80, 80, 80); + } + } + + public static void OnThemeChanged() + { + Load(); + ThemeChanged?.Invoke(); + } + } } \ No newline at end of file diff --git a/ContextMenuManager/Methods/AppString.cs b/ContextMenuManager/Methods/AppString.cs index 63648015..dee28cd4 100644 --- a/ContextMenuManager/Methods/AppString.cs +++ b/ContextMenuManager/Methods/AppString.cs @@ -328,6 +328,7 @@ public static class Other public static string SetPerceivedType { get; set; } public static string SetDefaultDropEffect { get; set; } public static string TopMost { get; set; } + public static string Win11ClassicMenu { get; set; } } } } diff --git a/ContextMenuManager/Methods/ObjectPath.cs b/ContextMenuManager/Methods/ObjectPath.cs index 2cbb4fa4..019ab092 100644 --- a/ContextMenuManager/Methods/ObjectPath.cs +++ b/ContextMenuManager/Methods/ObjectPath.cs @@ -1,4 +1,4 @@ -using BluePointLilac.Methods; +using BluePointLilac.Methods; using Microsoft.Win32; using System; using System.Collections.Generic; @@ -12,6 +12,8 @@ static class ObjectPath /// 路径类型 public enum PathType { File, Directory, Registry } private const string RegAppPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths"; + public const string CommandStorePath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell"; + public const string CommandStorePathCU = @"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell"; private const string ShellExecuteCommand = "mshta vbscript:createobject(\"shell.application\").shellexecute(\""; private static readonly char[] IllegalChars = { '/', '*', '?', '\"', '<', '>', '|' }; diff --git a/ContextMenuManager/Methods/Win11Helper.cs b/ContextMenuManager/Methods/Win11Helper.cs new file mode 100644 index 00000000..3e9a5896 --- /dev/null +++ b/ContextMenuManager/Methods/Win11Helper.cs @@ -0,0 +1,36 @@ +using BluePointLilac.Methods; +using Microsoft.Win32; + +namespace ContextMenuManager.Methods +{ + public static class Win11Helper + { + private const string CLSID_CLASSIC_MENU = @"HKEY_CURRENT_USER\Software\Classes\CLSID\{86ca1aa0-34aa-4e8b-a509-50c905bae2a2}"; + private const string INPROC_SERVER32 = "InprocServer32"; + + public static bool IsClassicMenuEnabled + { + get + { + using(RegistryKey key = RegistryEx.GetRegistryKey(CLSID_CLASSIC_MENU + "\\" + INPROC_SERVER32)) + { + return key != null; + } + } + set + { + if(value) + { + using(RegistryKey key = RegistryEx.GetRegistryKey(CLSID_CLASSIC_MENU + "\\" + INPROC_SERVER32, true, true)) + { + key.SetValue("", ""); + } + } + else + { + RegistryEx.DeleteKeyTree(CLSID_CLASSIC_MENU); + } + } + } + } +} diff --git a/ContextMenuManager/Properties/Resources/Texts/AppLanguageDic.ini b/ContextMenuManager/Properties/Resources/Texts/AppLanguageDic.ini index a82a78cf..853353c0 100644 --- a/ContextMenuManager/Properties/Resources/Texts/AppLanguageDic.ini +++ b/ContextMenuManager/Properties/Resources/Texts/AppLanguageDic.ini @@ -1,4 +1,4 @@ -;此文件为 ContextMenuManager Windows右键管理程序 的显示文本字典。 +;此文件为 ContextMenuManager Windows右键管理程序 的显示文本字典。 ;可帮助作者为此程序提供翻译并提交到Github,以下内容中等号右侧内容替换为翻译文本。 ;General - Translator 为翻译贡献者,General - Language 为语言名称,如en-US 美国英语, ;General - TranslatorUrl 为翻译贡献者的URL地址(能用Win+R命令打开的URL链接即可) @@ -35,6 +35,7 @@ New = 新建菜单 SendTo = 发送到 OpenWith = 打开方式 WinX = Win+X +Win11Items = Windows 11 现代菜单 LnkFile = lnk文件 UwpLnk = uwp lnk @@ -75,6 +76,7 @@ New = 所有目录背景和桌面背景的右键 "新建" 的菜单项目 SendTo = 所有文件系统对象的右键 "发送到" 的菜单项目 OpenWith = 所有文件右键 "打开方式" 的菜单项目 WinX = Win8~Win10 "开始" 按钮的右键 Win+X 菜单项目 +Win11Items = Windows 11 现代右键菜单项目 LnkFile = 所有LNK快捷方式的右键菜单 UwpLnk = Win8~Win10 UWP应用快捷方式的右键菜单 @@ -286,6 +288,7 @@ HideSysStoreItems = 隐藏公共引用中的系统菜单 SetPerceivedType = 设置扩展名为 %s 的文件感知类型为 SetDefaultDropEffect = 设置文件对象默认拖拽命令为 TopMost = 使窗口始终在屏幕最上方 +Win11ClassicMenu = Windows 11 经典右键菜单 AboutApp = [兼容性能]\r\n 1 = 适用于Win10、8.1、8、7、Vista \r\n 2 = 适用于 64bit、32bit CPU 操作系统\r\n 3 = 适配高分屏,最佳缩放比为150%\r\n\r\n[代码开源]\r\n 1 = 代码语言:C Sharp,Winform 程序,MIT 开源协议\r\n 2 = Github 仓库:https://github.com/BluePointLilac/ContextMenuManager \r\n 3 = Gitee 仓库:https://gitee.com/BluePointLilac/ContextMenuManager \r\n\r\n[温馨提示]\r\n 1 = 程序需要对大量的注册表项和文件进行读写删改操作,这些行为比较敏感,\r\n 可能会被Windows Defender等误报为病毒,如发生此情况请自行添加进白名单。\r\n\r\n 2 = 一些特殊菜单项可能会受到其他因素影响导致不会直接显示在右键菜单中,\r\n 但是按照程序使用的通用规则在此程序中仍会显示为启用状态,这是正常的现象。\r\n\r\n 3 = 每个右键管理程序禁用菜单方法可能不同,建议不要同时使用多个右键菜单管理程序,\r\n 大部分程序使用简单暴力的备份-删除法,此程序尽可能使用了系统提供的键值进行隐藏,\r\n 通过其他程序禁用的菜单项目,请先使用对应程序还原,不然可能无法在此程序中看到它。\r\n\r\n 4 = 此程序不用于清理未卸载干净的程序,但可帮助你定位菜单项相关注册表和文件位置,\r\n 你可根据相关内容进行你的操作,如果你是一个电脑小白,建议只碰启用\禁用开关。 diff --git a/languages/en-US.ini b/languages/en-US.ini index 887ca9df..e423189c 100644 --- a/languages/en-US.ini +++ b/languages/en-US.ini @@ -31,6 +31,7 @@ New = New SendTo = Send to OpenWith = Open with WinX = Win+X +Win11Items = Windows 11 LnkFile = .lnk file UwpLnk = UWP .lnk @@ -71,6 +72,7 @@ New = "New" menu for the context menu for folder and desktop background SendTo = "Send to" menu for all file system objects OpenWith = "Open With" menu for all files WinX = Win8-Win10 context menu for the Win+X Start Menu +Win11Items = Modern context menu for Windows 11 LnkFile = Context menu for all shortcuts UwpLnk = Context menu for all Win10, Win8 UWP apps @@ -282,6 +284,7 @@ HideSysStoreItems = Hide system store items SetPerceivedType = Set %s perceived type... SetDefaultDropEffect = Set default drop effect TopMost = Always on top +Win11ClassicMenu = Windows 11 Classic Context Menu AboutApp = [Compatiblity] \r\n 1 = Compatible with Win10、8.1、8、7、Vista \r\n 2 = Compatible with 64bit、32bit OS\r\n 3 = High DPI compatible, optimal with 150%\r\n\r\n[Open source]\r\n 1 = Programming languages: C sharp,Winform,MIT License\r\n 2 = Github repo:https://github.com/BluePointLilac/ContextMenuManager \r\n 3 = Gitee repo:https://gitee.com/BluePointLilac/ContextMenuManager \r\n\r\n[Hints]\r\n 1 = This program reads/writes a large amount of system files and registry entries,\r\n it may be flagged by Windows Defender as these operations are highly sensitive, please manually add this program to the exclusion list\r\n\r\n 2 = Some special menu items may be affected by other factors, they may not be displayed in the context menu. \r\n However, they may still be displayed as enabled in this program according to the general rules used by the program. This is normal. \r\n\r\n 3 = The method of disabling the menu for each context menu management program may be different. Do not use multiple context menu management programs at the same time. \r\n Most programs use a simple and volatile backup-delete method. This program uses the key values ​​provided by the OS to hide keys as much as possible. \r\n If you have used other programs to disable an menu item before, please use that program to restore it, otherwise you may not be able to see it in this program. \r\n\r\n 4 = This program is not designed to clean up programs that have been uninstalled, but it can help you locate the registry and file locations of such menu items.\r\n You can do whatever you want. If you are just a newbie (or unsure about some options), toggle the enable\disable switch only (to reduce the risk of corrupting the OS). diff --git a/languages/zh-CN.ini b/languages/zh-CN.ini index a82a78cf..853353c0 100644 --- a/languages/zh-CN.ini +++ b/languages/zh-CN.ini @@ -1,4 +1,4 @@ -;此文件为 ContextMenuManager Windows右键管理程序 的显示文本字典。 +;此文件为 ContextMenuManager Windows右键管理程序 的显示文本字典。 ;可帮助作者为此程序提供翻译并提交到Github,以下内容中等号右侧内容替换为翻译文本。 ;General - Translator 为翻译贡献者,General - Language 为语言名称,如en-US 美国英语, ;General - TranslatorUrl 为翻译贡献者的URL地址(能用Win+R命令打开的URL链接即可) @@ -35,6 +35,7 @@ New = 新建菜单 SendTo = 发送到 OpenWith = 打开方式 WinX = Win+X +Win11Items = Windows 11 现代菜单 LnkFile = lnk文件 UwpLnk = uwp lnk @@ -75,6 +76,7 @@ New = 所有目录背景和桌面背景的右键 "新建" 的菜单项目 SendTo = 所有文件系统对象的右键 "发送到" 的菜单项目 OpenWith = 所有文件右键 "打开方式" 的菜单项目 WinX = Win8~Win10 "开始" 按钮的右键 Win+X 菜单项目 +Win11Items = Windows 11 现代右键菜单项目 LnkFile = 所有LNK快捷方式的右键菜单 UwpLnk = Win8~Win10 UWP应用快捷方式的右键菜单 @@ -286,6 +288,7 @@ HideSysStoreItems = 隐藏公共引用中的系统菜单 SetPerceivedType = 设置扩展名为 %s 的文件感知类型为 SetDefaultDropEffect = 设置文件对象默认拖拽命令为 TopMost = 使窗口始终在屏幕最上方 +Win11ClassicMenu = Windows 11 经典右键菜单 AboutApp = [兼容性能]\r\n 1 = 适用于Win10、8.1、8、7、Vista \r\n 2 = 适用于 64bit、32bit CPU 操作系统\r\n 3 = 适配高分屏,最佳缩放比为150%\r\n\r\n[代码开源]\r\n 1 = 代码语言:C Sharp,Winform 程序,MIT 开源协议\r\n 2 = Github 仓库:https://github.com/BluePointLilac/ContextMenuManager \r\n 3 = Gitee 仓库:https://gitee.com/BluePointLilac/ContextMenuManager \r\n\r\n[温馨提示]\r\n 1 = 程序需要对大量的注册表项和文件进行读写删改操作,这些行为比较敏感,\r\n 可能会被Windows Defender等误报为病毒,如发生此情况请自行添加进白名单。\r\n\r\n 2 = 一些特殊菜单项可能会受到其他因素影响导致不会直接显示在右键菜单中,\r\n 但是按照程序使用的通用规则在此程序中仍会显示为启用状态,这是正常的现象。\r\n\r\n 3 = 每个右键管理程序禁用菜单方法可能不同,建议不要同时使用多个右键菜单管理程序,\r\n 大部分程序使用简单暴力的备份-删除法,此程序尽可能使用了系统提供的键值进行隐藏,\r\n 通过其他程序禁用的菜单项目,请先使用对应程序还原,不然可能无法在此程序中看到它。\r\n\r\n 4 = 此程序不用于清理未卸载干净的程序,但可帮助你定位菜单项相关注册表和文件位置,\r\n 你可根据相关内容进行你的操作,如果你是一个电脑小白,建议只碰启用\禁用开关。