2

I am trying to wrap my head around Microsoft's shell extension context menu handler example.

Its implementation only shows a context menu on a .cpp file right-click. I want to try to extend it to allow it to show the context menu whenever a folder, drive, or empty space is right-clicked in Explorer as well.

So far I was only able to modify it to register right-clicks for all file types, not just .cpp files by specifying * when registering it:

hr = RegisterShellExtContextMenuHandler(L"*", 
            CLSID_FileContextMenuExt, 
            L"CppShellExtContextMenuHandler.FileContextMenuExt");

I must be missing something else because it won't pop up for folders. I have tried this suggestion but it did not work.

How can I extend this sample to also have it work for folders? Am I missing something from the registry?

Edit: Thanks to Igor's suggestion, I got it to work for folders and drives, but it does not show up when you right-click the desktop or when you right click blank space in a folder, and I did register for Directory\Background and DesktopBackground. Why is this?

Community
  • 1
  • 1
Alexandru
  • 12,264
  • 17
  • 113
  • 208
  • 2
    `AllFileSystemObjects` or `Folder` in place of `*` should do it. See [this list](https://msdn.microsoft.com/en-us/library/windows/desktop/cc144110.aspx#predefined_shell_objects) of predefined object names. – Igor Tandetnik Jun 25 '16 at 03:48
  • Thanks! I appreciate it. Exactly what I was looking for. You should post this as an answer! – Alexandru Jun 25 '16 at 03:51
  • @IgorTandetnik While most work, the ones that don't seem to work are `Directory\Background` and `DesktopBackground` (I am on Windows 10, x64). Do you have any ideas as to why? I see the registry keys are created in the correct location, right beside TortoiseSVN ones from another application – Alexandru Jun 25 '16 at 04:37
  • I figured out why `Directory\Background` and `DesktopBackground` weren't working. The initializer was returning `E_FAIL` because it wasn't making use of `pidlFolder` - by default the logic only cares about `pDataObj`, which handles `LPDATAOBJECT` right clicks only:. `IFACEMETHODIMP FileContextMenuExt::Initialize( LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hKeyProgID)` – Alexandru Jun 25 '16 at 13:50
  • Just needed to wire up some logic like this: `if (pidlFolder && SHGetPathFromIDList(pidlFolder, m_szSelectedFile)) hr = S_OK;` – Alexandru Jun 25 '16 at 14:06
  • A side note: Many people like you are using this sample, change it for they purpose but keeping the name. I'm just learning C++ by making a shellext handler and using this sample, but changed the name. The name is also indicating that it's for `.cpp` files. When I googled for some problem on the name I found some pages for errors "not able to find the dll", and description "is an important file on the computer that contribute its specific functions to the Windows system performance and related program operations" :) Don't forget to change ".cpp" to "*" also in `DllUnregisterServer` – 244an Mar 26 '17 at 18:43

0 Answers0