end2endzone / ShellAnything

ShellAnything is a C++ open-source software which allow one to easily customize and add new options to *Windows Explorer* context menu. Define specific actions when a user right-click on a file or a directory.
MIT License
185 stars 28 forks source link

Hide existing items in Context Menu #73

Open wmjordan opened 4 years ago

wmjordan commented 4 years ago

Instead of adding items, is it possible to hide existing items in the Context Menu?

For instance, the following code will instruct ShellAnything to hide the existing "Properties" menu item.

<hide title="Properties" />

A thing has similar functionality is a close source software moo0 right clicker which does not use XML configuration files but provides user interfaces to do so.

end2endzone commented 4 years ago

Hi.

No, ShellAnything can not be used to remove existing items on the context menu.

I do not plan to implement this functionality because this is not a trivial task:

I am not saying it cannot be done, you obviously mentioned moo0 right clicker which I did not know about. I also remember printing all the menu items (including the ones that are not created by ShellAnything) in my debug builds.

Regarding your example, since the menu item is not a third party item, there could be registry settings that would remove the specific menu items. I have never searched for it. I doubt there would be a registry setting that would remove "Properties" but I guess you used this example as a "menu item that every computer has".

Regarding custom menu items (for example "Open with application XXX" and "Edit with application XXX"), then you need to look if application XXX has the ability to disable a specific menu. If not, then you may be able to disable ALL menu items of application XXX by unregistering its Shell Extension. You can also take a look a #57 for details on how to disable a Shell Extension.

I am open to suggestion and feature requests about ShellAnything. If you ever find documentation on how to properly implement such a functionality, I would gladly appreciate the help.

wmjordan commented 4 years ago

Thank you very much for keeping this issue opened.

It is really not a trivia task.

I'd been using the moo0 right clicker for quite a few years and occasionally I observed that some applications got hung and consume a lot of CPU resources. I made a mini dump from a recently hung application and analyzed it with windbg, suspected that the right clicker could be the cause of the hanging. -- it is really so hard to write a thing like that.

I observed the behavior of the right clicker. It implemented the customized context menu by replacing the existing context menu in Explorer with its owner drawn one. A bonus of this implementation is that geekers can customize not only menu items, but also the appearance of the context menu as well.

And another application which had done the similar thing was Mmm (I could not find the official web site anymore, hence this link to a blog, sorry), while it was in the Windows XP time, almost decades ago. This little application had another useful function to move rarely used menu items into a sub menu (by default named Rarely used), which was more convenient when we were to hide some items but sometimes still wanted to access them.

The common thing is that Both right clicker and Mmm replaces the builtin context menu with their owner drawn one. Maybe it is the way to go.

I am sorry that I know so little about shell programming that I can not provide more useful information to you.

Maybe you can give the right clicker a try and use a tool named Inspect executable file provided by Process Hacker to analyze the imported DLL functions from within the main DLL that the right clicker uses, which locates in "%systemroot%\System32\ShellExtBridge\ShellExtBridge119.dll". Would it be possible to figure out what API functions we shall use from the DLL imports to implement this featuer?

shot
end2endzone commented 4 years ago

Hi. Thank you for providing a better avenue of investigation.

I have no experience with owner drawn menus but there seems to be multiple examples or references on internet:

However, I feel this might require a huge time investment in order to get this feature working and I already have other priorities and plans in the pipeline for ShellAnything right now (like implementing plugin support which is defined in issue number 50).

I leave the issue open when someone have the time and the skills to implement such a feature.

wmjordan commented 4 years ago

Thank you for the information.

I actually don't know whether the owner drawn menu is the essential part of the implementation or not. I just made an assumption since both Mmm+ and Moo0 Right Clicker happen to appear so.

Obstacles to implementing this feature are:

  1. Suppressing the default context menu and replace it with your own. I observed there were imports to DestroyMenu, DeleteMenu from user32.dll in the DLL from Right Clicker(plz look at the screenshot in my prior comment)--could those functions have something to do with this feature?
  2. Maintaining menu hierarchy, for example, WinRAR can create its context menu item with sub items.
  3. Handling graphical menu items, for instance SageThumbs, which places a small preview image into the context menu when you right click an image file in Windows Explorer.

If we are to hide existing items in the context menu, we have to preserve those special items.

end2endzone commented 2 months ago

Status update for this issue:

wmjordan commented 2 months ago

2: For instance, a user seldom use the Cut/Copy/Paste commands in the context menu, but he does not want to remove them completely, he would like to place those three commands into a "Rarely used items..." menu. So, a "Rarely used items..." item will replace the aforementioned three menu items in the context menu. When the user expand that item, the submenu will show the Cut/Copy/Paste commands. 3: No, it is not about icons. If you check out the SageThumbs you can see that application places a small image in the caption part of a menu item when we right click a picture file in Windows Explorer. If you attempt to support the feature of hiding existing items in the context menu, please be sure to keep those special menu items with pictures.