如何获得完整的shell上下文菜单,右键单击文件夹背景 [英] How to obtain full shell context menu of right-click a folder background

查看:887
本文介绍了如何获得完整的shell上下文菜单,右键单击文件夹背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以获得shell接口 IShellView ,我可以得到其上下文菜单右键单击文件夹视图的白色区域(背景),以下是我的代码:

I can obtain shell interface IShellView, and I can get its context menu of right click the folder view's white area (background), following is my code:

...
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

Both following images are my shortcut menu and the full shell context menu: http://jetyi.blog.sohu.com/album/photosetview-46937434-13489242.html

您会看到,2end是一个完整的快捷菜单,第一个是我通过代码获取快捷菜单。为什么他们是不同的,谁可以解决这个问题?

You see, the 2end one is full shortcut menu and the 1st one is my obtaining shortcut menu by the code. Why they are different, who can resolve this problem?

为了解决这个问题,我调试shell与我的快捷扩展项目,我找到一些有用的信息。以下是代码1:

For resolve this problem, I debug the shell with my shortcut extension project, I find some useful information. Following is the code-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 *)指定的文件夹中选择项目。
我的VS2008 statck显示的信息:

Code-1 can obtain a full context menu(the 3nd image) of user's selecting item in folder specified by 'psf'(IShellFolder*). My VS2008 statck show thes informations:

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  
...

但是,使用名字代码:

...
pShellView->GetItemObject(SVGIO_BACKGROUND, IID_IContextMenu3, (LPVOID*)&pcm3);
...

它获得短上下文菜单(第1张图像)。
我的VS2008堆栈显示这些信息:

It obtains the short context menu (the 1st image). My VS2008 stack shows these informations:

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 ,是不是导致了问题?

I can not find CDefView::xxx, is it that caused the problem?

推荐答案

您需要学习以下示例。我向你保证,除非你一直使用shell,否则非常困难。

You will need to study the following example. I assure you, it is extremely difficult to get your head around unless you work with the shell all the time.

如何托管IContextMenu
http://blogs.msdn.com/b/oldnewthing/archive/ 2004/09/20 / 231739.aspx

How to host an IContextMenu http://blogs.msdn.com/b/oldnewthing/archive/2004/09/20/231739.aspx

这篇关于如何获得完整的shell上下文菜单,右键单击文件夹背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆