我可以获得shell接口IShellView
,我可以右键单击文件夹视图的白色区域(背景)获取其上下文菜单,以下是我的代码:
...
IShellFolder* psf = NULL;
HRESULT hr = psfDesk->BindToObject(g_pidlSelectingFolder, NULL, IID_PPV_ARGS(&psf));
...
IShellView* pShellView = NULL;
if (FAILED(psfSelf->CreateViewObject(hParent, IID_PPV_ARGS(&pShellView))))
return;
IContextMenu3* pcm3 = NULL;
hr = pShellView->GetItemObject(SVGIO_BACKGROUND, IID_IContextMenu3, (LPVOID*)&pcm3);
HMENU hMenu = ::CreatePopupMenu();
pcm3->QueryContextMenu(g_hMenu, 0, 1, 10000, CMF_NORMAL);
POINT pt;
::GetCursorPos(&pt);
BOOL nCommandID = TrackPopupMenu(hMenu, TPM_RETURNCMD | TPM_LEFTALIGN, pt.x, pt.y, 0, hParentWnd, NULL);
if (nCommandID == ...) ...
DestroyMenu(hMenu);
以下两个图像都是我的快捷菜单和完整的shell上下文菜单: http://jetyi.blog.sohu.com/album/photosetview-46937434-13489242.html
你看,2end是一个完整的快捷菜单,第一个是我通过代码获取快捷菜单。为什么他们不同,谁能解决这个问题?
为了解决这个问题,我用我的快捷方式扩展项目调试shell,我找到了一些有用的信息。以下是代码1:
...
psf->GetUIObjectOf(hParentWnd, 1, (LPCITEMIDLIST*)&pdilChild, IID_IContextMenu, NULL, (LPVOID*)&pcm);
pcm->QueryInterface(IID_IContextMenu3, (LPVOID*)&pcm3);
pcm3->QueryContextMenu(hMenu, 0, 1, 50000, dwFlags);
...
Code-1可以获得用户在'psf'(IShellFolder *)指定的文件夹中选择项目的完整上下文菜单(第3个图像)。 我的VS2008 statck显示了这些信息:
ShortcutMenuShellEx.dll!CShellExInit::Initialize(...)
shell32.dll!_HDXA_AppendMenuItems2@36() - 0x14b bytes
shell32.dll!CDefFolderMenu::QueryContextMenu() + 0x2c1 bytes
shell32.dll!CContextMenuOnContextMenuArray::QueryContextMenu() + 0x7d bytes
shell32.dll!CDefView::_DoContextMenuPopup() + 0xfb bytes
shell32.dll!CDefView::ContextMenu() + 0x1e4 bytes
shell32.dll!CDefView::WndProc() + 0xf2bc bytes
shell32.dll!CDefView::s_WndProc() + 0x56 bytes
user32.dll!_InternalCallWinProc@20() + 0x28 bytes
...
但是,使用forename代码:
...
pShellView->GetItemObject(SVGIO_BACKGROUND, IID_IContextMenu3, (LPVOID*)&pcm3);
...
获取短语境菜单(第1张图片)。 我的VS2008堆栈显示了以下信息:
ShortcutMenuShellEx.dll!CShellExInit::Initialize(...)
shell32.dll!_HDXA_AppendMenuItems2@36() - 0x14b bytes
shell32.dll!CDefFolderMenu::QueryContextMenu() + 0x2c1 bytes
shell32.dll!CContextMenuOnContextMenuArray::QueryContextMenu() + 0x7d bytes
user32.dll!_InternalCallWinProc@20() + 0x28 bytes
...
我找不到CDefView::xxx
,是否导致问题?
答案 0 :(得分:0)
您需要学习以下示例。我向你保证,除非你一直在使用外壳,否则很难掌握它。
如何托管IContextMenu http://blogs.msdn.com/b/oldnewthing/archive/2004/09/20/231739.aspx