Exemple #1
0
STDMETHODIMP CExplorerCommandProvider::GetCommands(IUnknown* punkSite, REFIID riid, LPVOID* ppenumr)
{
   ATLTRACE(L"CExplorerCommandProvider::GetCommands\n");
   typedef CComEnum< IEnumExplorerCommand, &IID_IEnumExplorerCommand, IExplorerCommand*, _CopyInterface<IExplorerCommand> > CEnumCommands;
   HMENU hMenuPopup = ::GetSubMenu(m_hMenu, _T("CommandMenu"));
   CInterfaceArray<IExplorerCommand> aList;
   for( int i = 0; i < ::GetMenuItemCount(hMenuPopup); i++ ) {
      CComPtr<IExplorerCommand> spCommand;
      HR( _GetCommand(hMenuPopup, ::GetMenuItemID(hMenuPopup, i), IID_PPV_ARGS(&spCommand)) );
      aList.Add(spCommand);
   }
   CComObject<CEnumCommands>* pEnumResources;
   HR( CComObject<CEnumCommands>::CreateInstance(&pEnumResources) );
   HR( pEnumResources->Init(&aList.GetData()->p, &aList.GetData()->p + aList.GetCount(), NULL, AtlFlagCopy) );
   return pEnumResources->QueryInterface(riid, ppenumr);
}
Exemple #2
0
STDMETHODIMP CExplorerCommand::EnumSubCommands(IEnumExplorerCommand** ppEnum)
{
   typedef CComEnum< IEnumExplorerCommand, &IID_IEnumExplorerCommand, IExplorerCommand*, _CopyInterface<IExplorerCommand> > CEnumCommands;
   HMENU hMenuPopup = ::GetSubMenu(m_spProvider->m_hMenu, _T("CommandMenu"));
   hMenuPopup = ::GetSubMenu(hMenuPopup, ::GetMenuPosFromID(hMenuPopup, m_mii.wID));
   CInterfaceArray<IExplorerCommand> aList;
   for( int i = 0; hMenuPopup != NULL && i < ::GetMenuItemCount(hMenuPopup); i++ ) {
      ATLASSERT(::GetSubMenu(hMenuPopup, i)==NULL);  // No sub-sub menus!
      CComPtr<IExplorerCommand> spCommand;
      HR( m_spProvider->_GetCommand(hMenuPopup, ::GetMenuItemID(hMenuPopup, i), IID_PPV_ARGS(&spCommand)) );
      aList.Add(spCommand);
   }
   CComObject<CEnumCommands>* pEnumResources;
   HR( CComObject<CEnumCommands>::CreateInstance(&pEnumResources) );
   HR( pEnumResources->Init(&aList.GetData()->p, &aList.GetData()->p + aList.GetCount(), NULL, AtlFlagCopy) );
   return pEnumResources->QueryInterface(ppEnum);
}