Esempio n. 1
0
bool getAcadMenuGroup(IAcadMenuGroup  **pVal)
{

    IAcadApplication *acadApp = NULL;
    LPDISPATCH  pDisp = NULL;

    if (!getApplication(&pDisp))
        return false;

    HRESULT hr = S_OK;
    hr = pDisp->QueryInterface(IID_IAcadApplication, (LPVOID*)&acadApp);
    if (FAILED(hr))
        return false;


    LPDISPATCH  pTempDisp = NULL;
    IAcadMenuGroups *mnuGrps = NULL;
    long cnt = 0;

    //get the menu groups
    hr = acadApp->get_MenuGroups(&mnuGrps);
    if (FAILED(hr))
    {
        acadApp->Release();
        return false;
    }
    mnuGrps->get_Count(&cnt);


    //get AutoCAD menu group. say it is index 0.
    IAcadMenuGroup *mnuGrp = NULL;

    VARIANT  vtName;
    vtName.vt = VT_I4;
    BSTR  grpName;
    bool found = false ;
    for (long i=0; i < cnt; i++)
    {
        vtName.lVal = i;
        hr = mnuGrps->Item(vtName, &mnuGrp);
        if (FAILED(hr))
            return false;


        hr  = mnuGrp->get_Name(&grpName);
        CString cgrpName(grpName);
        if (cgrpName.CompareNoCase("Acad")==0)
        {
            found = true;
            *pVal = mnuGrp;
            break;
        }
    }

    acadApp->Release();
    return found;
}
Esempio n. 2
0
bool ArxToolBar::GetAcadMenuGroup( IAcadMenuGroup**  pVal )
{
    IAcadApplication* acadApp = NULL;
    HRESULT hr = S_OK;

    if( !GetAcadApplication( acadApp ) )
        return false;

    LPDISPATCH  pTempDisp = NULL;
    IAcadMenuGroups* mnuGrps = NULL;
    long cnt = 0;

    //得到菜单组集
    hr = acadApp->get_MenuGroups( &mnuGrps );
    if ( FAILED( hr ) )
    {
        acadApp->Release();
        return false;
    }
    acadApp->Release();

    mnuGrps->get_Count( &cnt );

    //得到菜单组
    IAcadMenuGroup* mnuGrp = NULL;

    VARIANT  vtName;
    vtName.vt = VT_I4;
    BSTR  grpName;
    bool found = false ;
    for ( long i = 0; i < cnt; i++ )
    {
        vtName.lVal = i;
        hr = mnuGrps->Item( vtName, &mnuGrp );
        if ( FAILED( hr ) )
            continue;

        hr  = mnuGrp->get_Name( &grpName );
        CString cgrpName( grpName );
        SysFreeString( grpName );

        if ( cgrpName.CompareNoCase( _T( "ACAD" ) ) == 0 )
        {
            found = true;
            *pVal = mnuGrp;
            break;
        }
        else
        {
            mnuGrp->Release();
        }
    }

    mnuGrps->Release();

    return found;
}
Esempio n. 3
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;
}
Esempio n. 5
0
bool AppMenu::GetAcadMenuGroup( IAcadMenuGroup**  pVal, LPCTSTR menuname )
{
    IAcadApplication* acadApp = NULL;
    HRESULT hr = S_OK;

    if( !GetAcadApplication( acadApp ) )
        return false;

    LPDISPATCH  pTempDisp = NULL;
    IAcadMenuGroups* mnuGrps = NULL;
    long cnt = 0, cntmnu = 0;

    //得到菜单组集
    hr = acadApp->get_MenuGroups( &mnuGrps );
    if ( FAILED( hr ) )
    {
        acadApp->Release();
        return false;
    }
    acadApp->Release();

    mnuGrps->get_Count( &cnt );

    //得到菜单组
    IAcadMenuGroup* mnuGrp = NULL;
    IAcadPopupMenus*  mnus = NULL;
    IAcadPopupMenu* pPopUpMenu = NULL;

    VARIANT  vtName, vtMenu;
    vtName.vt = VT_I4;
    vtMenu.vt = VT_I4;

    BSTR  mnuName;
    bool found = false ;
    for ( long i = 0; i < cnt; i++ )
    {
        vtName.lVal = i;
        hr = mnuGrps->Item( vtName, &mnuGrp );
        if ( FAILED( hr ) )
        {
            return false;
        }

        mnuGrp->get_Menus( &mnus );

        mnus->get_Count( &cntmnu );

        for( long j = 0; j < cntmnu; j++ )
        {
            vtMenu.lVal = j;
            hr = mnus->Item( vtMenu, &pPopUpMenu );
            if( FAILED( hr ) )
                continue;

            pPopUpMenu->get_Name( &mnuName );
            pPopUpMenu->Release();

            CString sMenuName( mnuName );
            SysFreeString( mnuName );

            sMenuName.Replace( _T( "&" ), _T( "" ) ); //debug
            if( sMenuName.CompareNoCase( menuname ) == 0 )
            {
                found = true;
                *pVal = mnuGrp;
                break;
            }
        }

        mnus->Release();

        if( found )
        {
            break;
        }
        else
        {
            mnuGrp->Release();
        }
    }

    mnuGrps->Release();

    return found;
}