小弟刚才学了下添加Windows右键菜单(鼠标右键文件或文件夹弹出的菜单),大概源码如下:////创建项:shell
RegistryKey shell = Registry.ClassesRoot.OpenSubKey(@"*shell", true);
if (shell == null)
{
shell = Registry.ClassesRoot.CreateSubKey(@"*\shell");
}
RegistryKey custom = shell.CreateSubKey("鼠标右键菜单");
RegistryKey cmd = custom.CreateSubKey("command");
cmd.SetValue("", Application.ExecutablePath + " %1");
//Application.ExecutablePath 是本程序自身的路径
//%1 是传入打开的文件路径
cmd.Close();
custom.Close();
shell.Close();执行后效果图:但是现在有个疑问,我怎么使用这个菜单功能呢?就是当点击这个菜单执行程序里面的某个功能。
如鼠标右键 txt文档,点击“打开”后自动执行记事本打开文档。给点思路
RegistryKey shell = Registry.ClassesRoot.OpenSubKey(@"*shell", true);
if (shell == null)
{
shell = Registry.ClassesRoot.CreateSubKey(@"*\shell");
}
RegistryKey custom = shell.CreateSubKey("鼠标右键菜单");
RegistryKey cmd = custom.CreateSubKey("command");
cmd.SetValue("", Application.ExecutablePath + " %1");
//Application.ExecutablePath 是本程序自身的路径
//%1 是传入打开的文件路径
cmd.Close();
custom.Close();
shell.Close();执行后效果图:但是现在有个疑问,我怎么使用这个菜单功能呢?就是当点击这个菜单执行程序里面的某个功能。
如鼠标右键 txt文档,点击“打开”后自动执行记事本打开文档。给点思路
有一个参数string[] Args
那么Args[0]就是传入的打开文件名。在Main中写
void Main(string[] Args)
{
string filename = "";
if (Args.GetLength(0) > 0) filename = Args[0];
//打开filename文件
...
}