如何执行/ShellExecuteEx/InvokeCommand ITEMIDLIST指向Shell对象?
我正在构建一种码头,我很难找到如何保存“运行”、“搜索”、“帮助”、“打印机”等内容并在之后重新打开它们。
我尝试了这个:
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);
无论我在最后一行尝试 InvokeCommand 总是返回 E_INVALIDARG。我用 ShellExecuteEx 尝试了一下,得到了同样的错误。
我尝试了所有可能的动词。
我尝试枚举动词并得到 E_INVALIDARG。
我无法让它工作,但在正常的文件系统路径(如“c:\”)和文件夹上的 clsid 上。我错过了什么?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决方案。我必须创建一个上下文菜单,然后使用 QueryContextMenu 来填充它,使用 GetDefaultMenuItem() 获取默认项并使用 InvokeCommand 调用它。
有必要从默认菜单项中减去赋予 QueryContextMenu 的第一个项目的索引,否则您将有一个偏移量。
这非常有帮助:http://blogs.msdn.com/ oldnewthing/archive/2004/09/30/236133.aspx
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