Exemple #1
0
bool ArxToolBar::GetAcadToolBar( IAcadToolbar** pVal, LPCTSTR menuname )
{
    // 获取主菜单组
    IAcadMenuGroup* mnuGrp = NULL;
    if ( !GetAcadMenuGroup( &mnuGrp ) )
        return false;

    //得到所有工具栏
    HRESULT hr = S_OK;
    IAcadToolbars* acToolbars = NULL;
    hr = mnuGrp->get_Toolbars( &acToolbars );
    if ( FAILED( hr ) )
    {
        mnuGrp->Release();
        return false;
    }

    long cnt = 0;
    hr = acToolbars->get_Count( &cnt );

    //得到菜单组
    IAcadToolbar* acToolbar = NULL;
    VARIANT  vtName;
    vtName.vt = VT_I4;

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

        acToolbar->get_Name( &toolBarName );
        acToolbar->Release();

        CString sToolBarName( toolBarName );
        SysFreeString( toolBarName );

        if( sToolBarName.CompareNoCase( menuname ) == 0 )
        {
            found = true;
            *pVal = acToolbar;
            break;
        }
    }
    acToolbars->Release();
    mnuGrp->Release();

    return found;
}
void CleanToolbars()
{
	IAcadMenuGroup *mnuGrp = NULL;
	if (!getAcadMenuGroup(&mnuGrp))
		return ;

	IAcadToolbars  *tlbrs = NULL;
	HRESULT hr = S_OK;

	hr = mnuGrp->get_Toolbars(&tlbrs);
	mnuGrp->Release();

	long cnt = 0;
	hr = tlbrs->get_Count(&cnt);

	IAcadToolbar *polyTlbr = NULL;
	BSTR  tempName;

	VARIANT vtName;
	for (long i = cnt-1; i >0 ; i--)
	{
		vtName.vt = VT_I4;
		vtName.lVal = i;
		hr = tlbrs->Item(vtName, &polyTlbr);
		hr = polyTlbr->get_Name(&tempName);
		CString tlbrName(tempName);
		SysFreeString(tempName);

		OutputDebugString(tlbrName);

		BOOL bFind = FALSE;
		for (int j = 0; j < Glb_toolbarArray.GetSize(); j++)
		{
			if (tlbrName.CompareNoCase(Glb_toolbarArray.GetAt(j))==0)
			{
				bFind = TRUE;
				polyTlbr->Delete();
				break;
			}
		}
	
		if (!bFind)
			polyTlbr->Release();
	}

	tlbrs->Release();
	Glb_toolbarArray.RemoveAll();

	return;
}
Exemple #3
0
void CleanUpToolbars()
{
    IAcadMenuGroup *mnuGrp = NULL;
    if (!getAcadMenuGroup(&mnuGrp))
        return ;


    IAcadToolbars  *tlbrs = NULL;
    HRESULT hr = S_OK;

    hr = mnuGrp->get_Toolbars(&tlbrs);
    mnuGrp->Release();

    long cnt = 0;
    hr = tlbrs->get_Count(&cnt);

    IAcadToolbar *polyTlbr = NULL;
    BSTR  tempName;

    VARIANT vtName;
    for ( long i=0; i < cnt; i++)
    {
        vtName.vt = VT_I4;
        vtName.lVal = i;
        hr = tlbrs->Item(vtName, &polyTlbr);
        hr = polyTlbr->get_Name(&tempName);
        CString tlbrName(tempName);
        SysFreeString(tempName);
        if(tlbrName.CompareNoCase("POLYSAMP APPLICATION")==0)
        {

            polyTlbr->Delete();
            //can not call following because delete has already removed it.
            //	polyTlbr->Release();
            break;
        }
        else
            polyTlbr->Release();

    }

    tlbrs->Release();
    return;
}