构建文件打开对话框替换。现在大部分都可以使用,但我想直接从 shell View 对象为工具栏生成 View 模式下拉菜单。
查看 IShellView2,我可以看到 IShellView2::GetView() 将为我提供支持的 FOLDERVIEWMODE。但是,这并没有给我这些模式的名称,也没有为我格式化弹出菜单,也没有立即给我一种实际设置其中一种模式的方法(看起来有必要销毁 shell View 窗口并创建为当前文件夹替换一个并指定所需的新 FOLDERVIEWMODE ... 是的)。
无论如何,如果在 IShellView 窗口上单击鼠标右键,就会得到一个上下文菜单,其中的第一个子菜单正是我想要放置在下拉工具栏按钮(即“ View ”fly-出菜单(例如小图标、中图标等)。
似乎应该有一种方法可以直接从 IShellView 中获取该子菜单,而不必对我的值进行硬编码(这样一来,如果给定的 IShellView 实例支持额外的 View 模式,它们就会存在。同样,那些应该被禁用的将是,因为它们都在 IShellView 的控制之下。
我读过Raymond Chen的优秀How to host an IContextMenu .不幸的是,这只给了我一个非常简单的上下文菜单——文件夹本身的菜单,或者给定文件夹中的文件的菜单,而不是 IShellView 的外壳 View 窗口的上下文菜单(我可以从中获得 View 弹出窗口) ).
根据 Chen 的文章,我尝试了以下方法:
CComQIPtr<IContextMenu> pcm(m_shell_view); // <<-- FAIL resulting pointer is NULL <<<
// create a blank menu
CMenu menu;
if (!menu.CreatePopupMenu())
throw CContextException("Unable to create an empty menu in which to store the context menu: ");
// obtain the full popup menu we need
if (FAILED(m_hresult = pcm->QueryContextMenu(menu, 0, SCRATCH_QCM_FIRST, SCRATCH_QCM_LAST, CMF_NORMAL)))
throw CLabeledException("Unable to query the context menu for the current folder");
// display the menu to the user
// menu.getsubmenu
::TrackPopupMenu(menu, ::GetSystemMetrics(SM_MENUDROPALIGNMENT)|TPM_TOPALIGN|TPM_LEFTBUTTON, pt.x, pt.y, 0, m_shell_view_hwnd, NULL);
不幸的是,尝试查询 m_shell_view(这是一个 IShellView*)的 IContextMenu 接口(interface)失败。这个“有效”:
// retrieve our current folder's PIDL
PidlUtils::Pidl pidl(m_folder);
// get the context menu for the current folder
CComPtr<IContextMenu> pcm;
if (FAILED(m_hresult = GetUIObjectOf(m_owner->m_hWnd, pidl, IID_PPV_ARGS(&pcm))))
throw CLabeledException("Unable to obtain the PIDL for the current folder");
但在这里,我在上下文菜单中只获得了很少的选项(打开、探索……)。如果我只是右键单击 shell View 本身,则不会得到详细的上下文菜单。
我不知道如何继续。帮助?! ;)
最佳答案
尝试以 SVGIO_BACKGROUND 作为 uItem 的 IShellView::GetItemObject 来获取 View 对象上的 IContextMenu:http://msdn.microsoft.com/en-us/library/bb774832%28VS.85%29.aspx
关于c++ - 我如何获得显示在 IShellView 上下文菜单中的 IContextMenu?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1744902/