views:

246

answers:

1

I'm building a kind of dock, and I struggle at finding how to save things like "Run", "Search", "Help", "Printers" and reopen them after that.

I tried this :

CComPtr<IShellFolder> pDF;
SHGetDesktopFolder(&pDF);

LPITEMIDLIST pidlPrintersAndFaxes=0;
hr=pDF->ParseDisplayName(0, 0, L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{2227A280-3AEA-1069-A2DE-08002B30309D}", 0, &pidlPrintersAndFaxes, NULL);

CComPtr<IShellFolder> pSF;
hr=pDF->BindToObject(pidlPrintersAndFaxes, 0, IID_IShellFolder, (void**)&pSF);

LPITEMIDLIST pidlPrinter=0;
hr=pSF->ParseDisplayName(0, 0, L"PDFCreator", 0, &pidlPrinter, NULL);

CComPtr<IContextMenu> pPrinterCtxMenu;
hr=pSF->GetUIObjectOf(0, 1, (LPCITEMIDLIST*)&pidlPrinter, IID_IContextMenu, 0, (void**)&pPrinterCtxMenu);

CMINVOKECOMMANDINFO cmd={0};
cmd.cbSize=sizeof(CMINVOKECOMMANDINFO);
cmd.lpVerb=MAKEINTRESOURCE(0);
cmd.nShow=SW_SHOWNORMAL;
hr=pPrinterCtxMenu->InvokeCommand(&cmd);

Whatever I try InvokeCommand on the last line always return E_INVALIDARG. I tried it with ShellExecuteEx and got the same error.

I tried every possible verbs.

I tried to enumerate the verbs and got E_INVALIDARG.

I can't make it work but on normal filesystem path like "c:\" and clsid on folders. What did I miss ?

+1  A: 

I found the solution. I must create a context menu, then QueryContextMenu to fill it, get the default item with GetDefaultMenuItem() and invoke it with InvokeCommand.

It is necessary to substract the index of the first item given to QueryContextMenu from the default menu item, because otherwise you'll have an offset.

This was very helpful : http://blogs.msdn.com/oldnewthing/archive/2004/09/30/236133.aspx

Emmanuel Caradec