Esempio n. 1
0
bool AppMenu::GetLastMenuFromMenubar( CString& sMenu )
{
    IAcadApplication* pAcad = NULL;
    if( !GetAcadApplication( pAcad ) )
        return false;

    IAcadMenuBar* pMenuBar = NULL;
    IAcadPopupMenu*  pPopUpMenu = NULL;

    pAcad->get_MenuBar( &pMenuBar );
    pAcad->Release();
    long numberOfMenus;
    pMenuBar->get_Count( &numberOfMenus );

    //得到菜单栏上面的最后一个菜单
    BSTR name;
    VARIANT vIndex;
    vIndex.vt = VT_I4;
    vIndex.lVal = numberOfMenus - 1;

    pMenuBar->Item( vIndex, &pPopUpMenu );
    pMenuBar->Release();
    pPopUpMenu->get_NameNoMnemonic( &name );
    pPopUpMenu->Release();

    sMenu.Format( _T( "%s" ), name ); //debug 大写,用于转化LPWSTR类型字符串
    SysFreeString( name );

    return true;
}
bool CAddCADFrameMenu::GetFirstMenuFromMenubar(CString &sMenu)
{
 IAcadApplication *pAcad = NULL;
 if(!GetAcadApplication(pAcad))
  return false;

 IAcadMenuBar *pMenuBar=NULL;
 IAcadPopupMenu  *pPopUpMenu=NULL;
 
 pAcad->get_MenuBar(&pMenuBar);
    pAcad->Release();

 //得到菜单栏上面的最后一个菜单
 BSTR name;
 VARIANT vIndex;
 vIndex.vt=VT_I4;
 vIndex.lVal=0;
 
 pMenuBar->Item(vIndex,&pPopUpMenu);
 pMenuBar->Release();
 pPopUpMenu->get_NameNoMnemonic(&name);
 pPopUpMenu->Release();
 
 sMenu.Format("%S",name);//debug 大写,用于转化LPWSTR类型字符串
 SysFreeString(name);

 return true;
}