3

I am working on an application in that I need to display the sub menu of "New" context menu. i.e. when we right click on the desktop, we get new context menu item, on clicking on new, we get "Folder", "shortcut", "Text Document" and etc.

My questions are-

  1. Is there any API to Get List to sub menu of new?
  2. Also is there any API to get sub menu of "Send To"?
Arslan Ali
  • 17,418
  • 8
  • 58
  • 76
Umesha MS
  • 2,861
  • 8
  • 41
  • 60

1 Answers1

7

The New and Send To menu items are simple shell extensions which implement the IContextMenu(2,3) interfaces. The CLSID of the New shell extension is {D969A300-E7FF-11d0-A93B-00A0C90F2719}, and the CLSID of the Send To shell extension is {7BA4C740-9E81-11CF-99D3-00AA004AE837}. So you need to implement the host for IContextMenu interface.

  1. Create one of the COM objects

  2. Query it for IContextMenu and IShellExtInit

  3. Call IShellExtInit.Initialize()

  4. Create a temp menu

  5. Call IContextMenu.QueryContextMenu()

In the temp menu, you will have all of the available commands.

  1. To run a command call IContextMenu.InvokeCommand().

A lot of details you can find in The Old New Thing blog:

How to host an IContextMenu, part 1 - Initial foray

How to host an IContextMenu, part 2 - Displaying the context menu

How to host an IContextMenu, part 3 - Invocation location

How to host an IContextMenu, part 4 - Key context

How to host an IContextMenu, part 5 - Handling menu messages

How to host an IContextMenu, part 6 - Displaying menu help

How to host an IContextMenu, part 7 - Invoking the default verb

How to host an IContextMenu, part 8 - Optimizing for the default command

How to host an IContextMenu, part 9 - Adding custom commands

How to host an IContextMenu, part 10 - Composite extensions - groundwork

How to host an IContextMenu, part 11 - Composite extensions - composition

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Denis Anisimov
  • 3,297
  • 1
  • 10
  • 18
  • it worked for me, thanks for the solution. On more question, once i click on any option(text, folder, short cut). it creates file, but it will not be in edit mode, i.e. on clicking on test file, it creates "New Text document.txt". user has to explicitly need to rename the item. – Umesha MS Apr 15 '14 at 07:12
  • "New" shell extension is waiting that it is called from Windows Explorer and it has more integration with Explorer. Explorer provide a lot of interfaces like IShellView through IObjectWithSite interface of shell extension. And it allows to shell extension to call user friendly rename functionality. – Denis Anisimov Apr 15 '14 at 07:53
  • Hi New worked fine, but when i created Send To, then on context menu Send to comes. but on clicking on send to display empty list. do i need to any changes to send to apart from New. – Umesha MS Apr 23 '14 at 08:42
  • With which parameters do you call IShellExtInit.Initialize? – Denis Anisimov Apr 23 '14 at 09:02
  • ShellExtInit->Initialize(NULL, _pdtobj, NULL); I initialized IdataObject – Umesha MS Apr 23 '14 at 11:13
  • Do you call IContextMenu2::HandleMenuMsg or IContextMenu3::HandleMenuMsg2 with WM_INITMENUPOPUP? – Denis Anisimov Apr 23 '14 at 12:05
  • it contains CFSTR_SHELLIDLIST, if possible can you give me a sample of IDataObject for send to. – Umesha MS Apr 24 '14 at 10:39
  • Try create DataObject with SHCreateDataObject or CIDLData_CreateFromIDArray functions. – Denis Anisimov Apr 24 '14 at 15:37
  • I create IDataObject using SHCreateDataObject API. but still it is not showing sub menu. – Umesha MS Apr 25 '14 at 05:44
  • one more information, i am right clicking on virtual file. ie file does not exist on the disk. – Umesha MS Apr 25 '14 at 05:54
  • It does not matter. In my answer on another question a screenshot of Send to menu of virtual file: http://stackoverflow.com/questions/22990080/how-to-addenable-standard-send-to-context-menu-option-in-a-namespace-extensi/22994132#22994132 – Denis Anisimov Apr 25 '14 at 12:02
  • Try to add CFSTR_FILEDESCRIPTOR+CFSTR_FILECONTENTS formats in your DataObject. – Denis Anisimov Apr 28 '14 at 03:19