【问题标题】:How do you make context menu submenus in Windows?如何在 Windows 中制作上下文菜单子菜单?
【发布时间】:2011-12-09 17:13:28
【问题描述】:

我一直在编写实用程序并通过 * 的 Shell 键上的 Regedit 将它们映射到上下文菜单,但我不知道如何像一些更流行的实用程序那样制作子菜单。

例如,如果我有三个脚本将文件移动和重命名到三个不同的文件夹,那么现在我有三个不同的上下文菜单条目。我希望有一个名为“移动和重命名...”的扩展至这三个。

【问题讨论】:

    标签: windows contextmenu


    【解决方案1】:

    您可以通过注册表创建上下文菜单的子菜单,WIN 7 见here

    备份建议先备份您的注册表!

    此示例将带有单个命令的子菜单放入任何文件(不是文件夹或桌面)的右键单击上下文中。

    菜单:

    [HKEY_CLASSES_ROOT\*\shell\Custom Menu]
    "MUIVerb"="Custom Tools"
    "SubCommands"="Custom.copytoclip"
    

    命令:

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Custom.copytoclip]
    @="copytoclip description here"
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Custom.copytoclip\command]
    @="cmd /c clip < %1"
    

    请谨慎编辑您的注册表,其他版本的窗口可能会有所不同。

    【讨论】:

    • “建议先备份您的注册表”是我从未遵循的用于进行简单更改的神话。这是法律免责声明。
    【解决方案2】:

    您可以使用子命令指定组/菜单名称并指定项目,例如 - 为 EXE 文件制作上下文菜单

    group name: "InstallShield debug" 
    group subcommands:InstDbg1;InstDbg2;InstDbg3;InstDbg4;InstDbg5;InstDbg6;InstDbg7 
    group item1:  name: "debug installer /d" ; key  InstDbg1 
    group item2:  name: "debug installer /d /v..." ; key  InstDbg2 
    etc
    

    用于此的 reg 文件是

    Windows Registry Editor Version 5.00
    
    ;cascading context menu - use empty lines between registry items
    ;separator before: "CommandFlags"=dword:00000020
    ;SubCommands contains keys to be found in the registry - should match
    
    KEY_CLASSES_ROOT\exefile\shell\InstallShield cascade menu]
    "MUIVerb"="InstallShield debug"
    "Icon"="C:\\Program Files (x86)\\InstallShield\\2020\\System\\isdev.exe"
    "SubCommands"="InstDbg1;InstDbg2;InstDbg3;InstDbg4;InstDbg5;InstDbg6;InstDbg7"
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\InstDbg1]
    @=""
    "MUIVerb"="debug installer /d"
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\InstDbg1\command]
    @="\"%1\" /d"
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\InstDbg2]
    @=""
    "MUIVerb"="debug installer /d /v TEST_STATUS=Good"
    "CommandFlags"=dword:00000020
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\InstDbg2\command]
    @="\"%1\" /d /v\"TEST_STATUS=Good\""
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\InstDbg3]
    @=""
    "MUIVerb"="debug installer /d /v TEST_STATUS=Undetermined"
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\InstDbg3\command]
    @="\"%1\" /d /v\"TEST_STATUS=Undetermined\""
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\InstDbg4]
    @=""
    "MUIVerb"="debug installer /d /v TEST_STATUS=Unauthorized"
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\InstDbg4\command]
    @="\"%1\" /d /v\"TEST_STATUS=Unauthorized\""
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\InstDbg5]
    @=""
    "MUIVerb"="run installer /v TEST_STATUS=Good"
    "CommandFlags"=dword:00000020
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\InstDbg5\command]
    @="\"%1\" /v\"TEST_STATUS=Good\""
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\InstDbg6]
    @=""
    "MUIVerb"="run installer /v TEST_STATUS=Undetermined"
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\InstDbg6\command]
    @="\"%1\" /v\"TEST_STATUS=Undetermined\""
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\InstDbg7]
    @=""
    "MUIVerb"="run installer /v TEST_STATUS=Unauthorized"
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\InstDbg7\command]
    @="\"%1\" /v\"TEST_STATUS=Unauthorized\""
    

    结果:

    【讨论】:

      【解决方案3】:

      你必须写一个自定义的Context Menu Handler

      【讨论】:

        【解决方案4】:

        您尚未指定您使用的语言。无论如何,您需要做的是编写一个 Shell 扩展。有一个指南,here

        正如 David 指出的那样,在 C# 中不可能做到这一点This blog post 解释它。

        【讨论】:

        • 不支持编写托管 shell 扩展,即使在 .net 4 中也是如此。
        • 使用 .net 4 删除了特定的阻塞(并行运行时),但仍然存在代码注入问题。因此,MS 不支持托管 shell 扩展。
        • 嗯,给定的原因是“我们还没有测试所有场景”。他们只是不想接电话。我也不会。 .NET 4 进程内并行执行非常适合支持这种情况。由 DevDiv,而不是 Windows 组。
        猜你喜欢
        • 1970-01-01
        • 2013-12-27
        • 1970-01-01
        • 2014-07-27
        • 2016-08-19
        • 1970-01-01
        • 2012-06-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多