在windows中,系统为我们准备了6个电源icon的右键菜单。
具体实现可以进行在注册表中添加值实现。
具体位置如下:
HKEY_LOCAL_MACHINESOFTWARE\Microsoft\Windows\CurrentVersion\Applets\SysTray\BattMeter\ContextMenu\%d
附上C#例子
using Microsoft.Win32;
const string BATT_CONTEXT_MEUN_KEY = "SOFTWARE\Microsoft\Windows\CurrentVersion\Applets\SysTray\BattMeter\ContextMenu\";
private void AddButton_Click(object sender, RoutedEventArgs e)
{
string strBattconMenuName;
RegistryKey hkeyLm = Registry.LocalMachine;
for (int i = 1; i < 7; i++) {
strBattconMenuName = "";
strBattconMenuName = BATT_CONTEXT_MEUN_KEY + i;
RegistryKey hkeyBattConMenu = hkeyLm.OpenSubKey(strBattconMenuName,true);
if(hkeyBattConMenu != null){
string strapplication = (string)hkeyBattConMenu.GetValue("Application");
if(strapplication == ""){
hkeyBattConMenu.SetValue("Application","C:\Program Files\test\Test.exe");
hkeyBattConMenu.SetValue("ItemName","Test APP");
hkeyBattConMenu.Close();
break;
}
}
hkeyBattConMenu.Close();
}
hkeyLm.Close();
}
private void DeleteButton_Click(object sender, RoutedEventArgs e)
{
string strBattconMenuName;
RegistryKey hkeyLm = Registry.LocalMachine;
for (int i = 1; i < 7; i++)
{
strBattconMenuName = "";
strBattconMenuName = BATT_CONTEXT_MEUN_KEY + i;
RegistryKey hkeyBattConMenu = hkeyLm.OpenSubKey(strBattconMenuName, true);
if (hkeyBattConMenu != null)
{
string strapplication = (string)hkeyBattConMenu.GetValue("ItemName");
if (strapplication == "Test APP")
{
hkeyBattConMenu.SetValue("Application", "");
hkeyBattConMenu.SetValue("ItemName", "");
hkeyBattConMenu.Close();
break;
}
}
hkeyBattConMenu.Close();
}
hkeyLm.Close();
}
}