예제 #1
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;
}
예제 #2
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;
}
예제 #3
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;
}