How to add context menu to one specific File

纵饮孤独 提交于 2020-03-05 21:55:50

问题


I just learned how to create a context menu for the Desktop, but what I really want is to only have the context menu for one specific link. Is this possible? I have not figured out how yet. I was hoping to specify the file instead of an extension in HKEY_CLASSES_ROOT, but I have not gotten been able to get it to work. This is my most current attempt.

[HKEY_CLASSES_ROOT\Applications\My Link.lnk\Shell\Toggle]
"Position"="Top"
"Icon"="\"C:\\Program Files (x86)\\My Toggle\\My Toggle.Exe\""
@="Toggle"

[HKEY_LOCAL_MACHINE\Software\Classes\My Link.lnk\shell\Toggle\command]
@="\"C:\\Program Files (x86)\\My Toggle\\My Toggle.Exe\""

回答1:


The old fashioned way of creating interfaces to COM objects (Namely IContextMenu) You can then check all files passed to the handler in its Initialize method, using DragQueryFile to access information about the files passed, or in the QueryContextMenu, where actual menu items are added.
There, you could simply not add menu items unless it is the specific file you want it for. Other menu handlers for the file type would still add their own menu items.

Note the shortcut link will be resolved, so your handler would be looking at the file linked to rather than the shortcut itself. How to retrieve info about the actual lnk file is how I stumbled across this and I still don't know! 😂




回答2:


In case someone else is trying to do the same type of thing. My best solution was to create a new shortcut type extension called .lnky, and assign the context menu to it. Unless I am missing something I was not able to find a way to create a context menu for a single file and not a file extension.

This guide helped a lot: Add menu item to windows context menu only for specific filetype

[HKEY_CLASSES_ROOT\.lnky]
@="lnkyfile"

[HKEY_CLASSES_ROOT\lnkyfile]
@="Shortcut"
"IsShortcut"=""
"NeverShowExt"=""
[HKEY_CLASSES_ROOT\lnkyfile\Shell\My Toggle]
"Position"="Top"
"Icon"="\"C:\\Program Files (x86)\\My program\\My program.Exe\""
@="My Action"
[HKEY_CLASSES_ROOT\lnkyfile\Shell\My Toggle\command]
@="\"C:\\Program Files (x86)\\My program\\My program.Exe\""

The result of this is when I right clink on my lnky file it has my action next to my program icon at the top of the context menu. My program.Exe runs when I click on My Action.



来源:https://stackoverflow.com/questions/43769772/how-to-add-context-menu-to-one-specific-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!