tags:

views:

147

answers:

2

One of my applications has a Windows Explorer like file list control. When the user right clicks on a file I can successfully show the Explorer context menu (with some extra options of my own). However if the user right clicks on the list control itself (no items selected), then I'm unable to show the 'correct' context menu. I'd like to show the one you see in Windows Explorer on the right side rather then the one in the tree on the left side.

I've tried a bunch of variations in my calls to GetUIObjectOf, I surfed the Google web, etc, but I haven't found a solution yet. Any help?

+2  A: 

Call IShellFolder::CreateViewObject() to get the IContextMenu for a folder itself. IShellFolder::GetUIObjectOf() is meant for retrieving interfaces for individual items inside of a folder, not for a folder itself. This is stated in MSDN's documentation:

IShellFolder::CreateViewObject Method

This method is also used to request objects that expose one of several optional interfaces, including IContextMenu or IExtractIcon. In this context, CreateViewObject is similar in usage to IShellFolder::GetUIObjectOf. However, you call IShellFolder::GetUIObjectOf to request an object for one of the items contained by a folder. Call IShellFolder::CreateViewObject to request an object for the folder itself.

Remy Lebeau - TeamB
Thanks a lot. Works like a charm :-)
crimson13
A: 

The solution posted by Remy Lebeau is probably the way to go, but if you are not using all of the shell objects or want a more customized menu, you would look in HKCR\Directory\Background for a list of GUID's that implement IContextMenu, the rest of the menu items, you would have to add yourself.

Anders