title: How might I obtain the IContextMenu that is displayed in an IShellView context menu?
body: <p>Building a file open dialog replacement.  Much of it works now, but I would like to generate the view-mode drop-down for the toolbar directly from the shell view object.</p>
  <p>Looking at IShellView2, I can see IShellView2::GetView() will give me the FOLDERVIEWMODE's supported.  However, that doesn't give me the names of these modes, nor format that popup menu for me, nor immediately give me a way to actually set one of those modes (it would appear it is necessary to destroy the shell view window and create a replacement one for the current folder and specify the new FOLDERVIEWMODE desired... yeesh).</p>
  <p>At any rate, if one right clicks on an IShellView window, one gets a context menu, the first submenu of which is exactly what I want to place in my drop-down toolbar button (ie. the &quot;view&quot; fly-out menu (e.g. Small Icons, Medium Icons, etc.)).</p>
  <p>It seems like there ought to be a way to grab that submenu directly from the IShellView, rather than having to hardcode my values (and that way, if a given instance of IShellView supports extra view modes, they'd be there.  Similarly, those which should be disabled would be, since it would all be under the IShellView's control).</p>
  <p>I have read Raymond Chen's excellent <a href="http://blogs.msdn.com/oldnewthing/archive/2004/09/20/231739.aspx" rel="nofollow noreferrer">How to host an IContextMenu</a>.  Unfortunately, that just gives me a very simplistic context menu - the one for the folder itself, or for a file in a given folder, but NOT the context menu for the IShellView's shell view window (from which I might obtain the view fly-out).</p>
  <p>I have tried the following, based on Chen's article:</p>
  <pre><code>CComQIPtr&lt;IContextMenu&gt; pcm(m_shell_view); // &lt;&lt;-- FAIL resulting pointer is NULL &lt;&lt;&lt;
  
  // create a blank menu
  CMenu menu;
  if (!menu.CreatePopupMenu())
      throw CContextException(&quot;Unable to create an empty menu in which to store the context menu: &quot;);
  
  // obtain the full popup menu we need
  if (FAILED(m_hresult = pcm-&gt;QueryContextMenu(menu, 0, SCRATCH_QCM_FIRST, SCRATCH_QCM_LAST, CMF_NORMAL)))
      throw CLabeledException(&quot;Unable to query the context menu for the current folder&quot;);
  
  // 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);
  </code></pre>
  <p>Unfortunately, the attempt to query the m_shell_view (which is an IShellView*) for its IContextMenu interface fails.  This &quot;works&quot;:</p>
  <pre><code>// retrieve our current folder's PIDL
  PidlUtils::Pidl pidl(m_folder);
  
  // get the context menu for the current folder
  CComPtr&lt;IContextMenu&gt; pcm;
  if (FAILED(m_hresult = GetUIObjectOf(m_owner-&gt;m_hWnd, pidl, IID_PPV_ARGS(&amp;pcm))))
      throw CLabeledException(&quot;Unable to obtain the PIDL for the current folder&quot;);
  </code></pre>
  <p>But here I get only a very few options in the context menu (Open, Explore, ...).  Not the detailed context menu that I get if I simply right click on the shell view itself.</p>
  <p>I'm out of ideas as to how to proceed.  Help?!  ;)</p>