Example #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;
}
Example #2
0
bool AppMenu::IsMenuExist( IAcadPopupMenu*& pMnu, long& index, LPCTSTR mnuname, IAcadPopupMenus* mnus )
{
    ASSERT( mnus != NULL );

    long cnt = 0l;
    HRESULT hr = mnus->get_Count( &cnt );
    bool found = false;
    int curMenuIndex = -1;
    BSTR tempName;

#ifdef _DEBUG
    acutPrintf( _T( "IsMenuExist cnt=%ld " ), cnt );
#endif

    //
    IAcadPopupMenu* toolsMenu = NULL;
    for ( long i = 0; i < cnt; i++ )
    {
        VARIANT vtName;
        VariantInit( &vtName );
        V_VT( &vtName ) = VT_I4;
        V_I4( &vtName ) = i;
        hr = mnus->Item( vtName, &toolsMenu );
        if ( FAILED( hr ) )
            return false;
        hr = toolsMenu->get_NameNoMnemonic( &tempName );
        CString mnuName( tempName );

#ifdef _DEBUG
        acutPrintf( _T( " %d,%s" ), i, mnuName );
#endif
        if( mnuName.Compare( mnuname ) == 0 )
        {
            index = i;
            pMnu = toolsMenu;
            return true;
        }
    }
    pMnu = NULL;
    return false;
}
Example #3
0
void CAddCADFrameMenu::ClearMenu(IAcadPopupMenus *mnus,LPCTSTR menuname)
{
	long cnt = 0l;
	HRESULT hr = mnus->get_Count(&cnt);

	//now get Tools menu
	IAcadPopupMenu *toolsMenu = NULL;
	BSTR   tempName;
	VARIANT vtName;
	VariantInit(&vtName);

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

		hr = toolsMenu->get_NameNoMnemonic(&tempName);
		CString mnuName(tempName);
		SysFreeString(tempName);
		if(mnuName.CompareNoCase(menuname)==0)
		{
			found = true;
			break;
		}
	}

	if (!found)
	{
		acutPrintf(_T("没有找到菜单 : %s "),menuname);
		return;
	}

	hr = toolsMenu->get_Count(&cnt);
	VARIANT vIndex;
	vIndex.vt = VT_I4;
	vIndex.lVal = cnt;
	IAcadPopupMenuItem *cmd1 = NULL;
	while(cnt--)
	{
		vIndex.lVal=cnt;
		hr=toolsMenu->Item(vIndex,&cmd1);
		hr=cmd1->Delete();
		cmd1->Release();
	}

	toolsMenu->RemoveFromMenuBar();
	toolsMenu->Release();

	mnus->RemoveMenuFromMenuBar(vtName);

	return;

}
Example #4
0
void CleanUpMenus()
{
    IAcadMenuGroup *mnuGrp = NULL;
    if (!getAcadMenuGroup(&mnuGrp))
        return ;

    //now get all the popup menus
    IAcadPopupMenus  *mnus = NULL;
    HRESULT hr = S_OK;
    hr = mnuGrp->get_Menus(&mnus);
    long cnt = 0l;
    hr = mnus->get_Count(&cnt);
    mnuGrp->Release();

    //now get Tools menu
    IAcadPopupMenu *toolsMenu = NULL;
    BSTR   tempName;
    VARIANT vtName;
    bool found = false;
    for (long i=0; i < cnt; i++)
    {
        vtName.vt = VT_I4;
        vtName.lVal = i;
        hr = mnus->Item(vtName, &toolsMenu);
        if (FAILED(hr))
            return ;

        hr = toolsMenu->get_NameNoMnemonic(&tempName);
        CString mnuName(tempName);
        SysFreeString(tempName);
        if(mnuName.CompareNoCase("Tools")==0)
        {
            found = true;
            break;
        }
    }
    mnus->Release();

    if (!found)
    {
        acutPrintf("Could not found tools menu\n");
        return;
    }

    hr = toolsMenu->get_Count(&cnt);
    VARIANT vIndex;
    vIndex.vt = VT_I4;
    vIndex.lVal = cnt;
    IAcadPopupMenu  *polySampCmds = NULL;
    IAcadPopupMenuItem *cmd1 = NULL;
    long index = 0l;
    for ( i=0; i < cnt; i++)
    {
        vtName.vt = VT_I4;
        vtName.lVal = i;
        hr = toolsMenu->Item(vtName, &cmd1);
        hr = cmd1->get_Label(&tempName);
        CString mnuName(tempName);
        SysFreeString(tempName);
        if(mnuName.CompareNoCase("PolySamp Application")==0)
        {   index = i-1;
            break;
        }
    }

    vIndex.vt = VT_I4;
    vIndex.lVal = index;
    //Remove all the menus loaded by this program
    IAcadPopupMenuItem *tempItem = NULL;
    hr = toolsMenu->Item(vIndex, &tempItem);
    hr = tempItem->Delete();
    tempItem->Release();
    hr = toolsMenu->Item(vIndex, &tempItem);
    hr = tempItem->Delete();
    tempItem->Release();
    toolsMenu->Release();


    return;
}
Example #5
0
void CreateMenus()
{

    IAcadMenuGroup *mnuGrp = NULL;
    if (!getAcadMenuGroup(&mnuGrp))
        return ;

    //now get all the popup menus
    IAcadPopupMenus  *mnus = NULL;
    HRESULT hr = S_OK;
    hr = mnuGrp->get_Menus(&mnus);
    long cnt = 0l;
    hr = mnus->get_Count(&cnt);
    mnuGrp->Release();

    //now get Tools menu
    IAcadPopupMenu *toolsMenu = NULL;
    BSTR   tempName;
    VARIANT vtName;
    bool found = false;
    for (long i=0; i < cnt; i++)
    {
        vtName.vt = VT_I4;
        vtName.lVal = i;
        hr = mnus->Item(vtName, &toolsMenu);
        if (FAILED(hr))
            return ;

        hr = toolsMenu->get_NameNoMnemonic(&tempName);
        CString mnuName(tempName);

        if(mnuName.CompareNoCase("Tools")==0)
        {
            found = true;
            break;
        }
    }
    mnus->Release();
    if (!found)
    {
        acutPrintf("Could not found tools menu\n");
        return;
    }

    hr = toolsMenu->get_Count(&cnt);
    VARIANT  vtIndex;
    vtIndex.vt = VT_I4;
    vtIndex.lVal = cnt + 1;
    IAcadPopupMenuItem  *item1 = NULL;
    hr = toolsMenu->AddSeparator(vtIndex, &item1);
    item1->Release();
    vtIndex.lVal = cnt + 2;
    IAcadPopupMenu *polyMnu = NULL;
    hr = toolsMenu->AddSubMenu(vtIndex, L"Polysamp Application", &polyMnu);
    toolsMenu->Release();


    IAcadPopupMenuItem *polycmds = NULL;
    vtIndex.lVal = 0;
    hr = polyMnu->AddMenuItem(vtIndex, L"POLY", L"_poly ", &polycmds);

    vtIndex.lVal = 1;
    hr = polyMnu->AddMenuItem(vtIndex, L"POLYEDIT", L"_polyedit ", &polycmds);
    vtIndex.lVal = 2;
    hr = polyMnu->AddMenuItem(vtIndex, L"TRANSACT", L"_TRANSACT ", &polycmds);
    vtIndex.lVal = 3;
    hr = polyMnu->AddMenuItem(vtIndex, L"HILITPOLY", L"_HILITPOLY ", &polycmds);
    vtIndex.lVal = 4;
    hr = polyMnu->AddMenuItem(vtIndex, L"CREATEINSERT", L"_CREATEINSERT ", &polycmds);
    vtIndex.lVal = 5;
    hr = polyMnu->AddMenuItem(vtIndex, L"HILITINSERT", L"_HILITINSERT ", &polycmds);
    vtIndex.lVal = 6;
    hr = polyMnu->AddMenuItem(vtIndex, L"USEDRAGDATA", L"_USEDRAGDATA ", &polycmds);
    vtIndex.lVal = 7;
    hr = polyMnu->AddMenuItem(vtIndex, L"HILITINSERT", L"_HILITINSERT ", &polycmds);
    vtIndex.lVal = 8;
    hr = polyMnu->AddMenuItem(vtIndex, L"HILITINSERT", L"_HILITINSERT ", &polycmds);
//	polycmds->Release();
    polyMnu->Release();

    return;
}
Example #6
0
void AppMenu::CreateMenus()
{
    CMDIFrameWnd* pMainFrame = acedGetAcadFrame();
    pMainFrame->LockWindowUpdate();

    //得到菜单栏上面的最后一个菜单
    CString sName;
    if( !GetLastMenuFromMenubar( sName ) )
        return;

    sName.Replace( _T( "&" ), _T( "" ) ); //debug

    IAcadMenuGroup* mnuGrp = NULL;
    if ( !GetAcadMenuGroup( &mnuGrp, sName ) )
        return ;

    //得到所有菜单组
    IAcadPopupMenus*   mnus = NULL;
    IAcadPopupMenu*   mnu = NULL;
    IAcadPopupMenuItem*  mnuitem = NULL;
    HRESULT hr = S_OK;
    hr = mnuGrp->get_Menus( &mnus );
    long cnt = 0l;
    hr = mnus->get_Count( &cnt );
    int i = 0;
    int j = 0;
    int k = 0;
    VARIANT index;
    VariantInit( &index );
    V_VT( &index ) = VT_I4;
    CArray<IAcadPopupMenu*, IAcadPopupMenu*> MnuAdrs;

    long lIndex = 0;
    TCHAR MenuName[256];
    for ( i = 0; i < m_menuCount; i++ )
    {
        CString tmpMenu = m_TopMenuNames[i];
        tmpMenu.Replace( _T( "&" ), _T( "" ) );
        if( IsMenuExist( mnu, lIndex, tmpMenu, mnus ) ) //处理二次加载
        {
            V_I4( &index ) = lIndex;
        }
        else
        {
            //			MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPTSTR)(LPCTSTR)m_TopMenuNames[i], -1, MenuName, 256);
            _tcscpy( MenuName, m_TopMenuNames[i] );
            mnus->Add( MenuName, &mnu );
            V_I4( &index ) = cnt++;
        }

        MnuAdrs.Add( mnu );
        mnu->InsertInMenuBar( index );
    }

    IAcadPopupMenu* MenuItem = NULL;
    int subMenuNum = 0;
    CCADMenuArray* Menus;
    TCHAR szSubMenu[256];
    TCHAR szSubMenuMacro[256];
    CString MenusName;
    CString Menusorder;
    for ( j = 0; j < m_menuCount; j++ )
    {
        Menus = m_menus.GetAt( j );
        subMenuNum = Menus->GetSize();
        for ( k = 0; k < subMenuNum; k++ )
        {
            mnu = MnuAdrs.GetAt( j );
            if ( !_tcscmp( _T( "--" ), Menus->GetAt( k )->name ) )
            {
                V_I4( &index ) = k;
                mnu->AddSeparator( index, &mnuitem );
            }
            else
            {
                V_I4( &index ) = k;
                MenusName = Menus->GetAt( k )->name;
                Menusorder = Menus->GetAt( k )->order;
                _tcscpy( szSubMenu, MenusName );
                _tcscpy( szSubMenuMacro, Menusorder );
                //MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPTSTR)(LPCTSTR)MenusName, -1, szSubMenu, 256);
                //MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPTSTR)(LPCTSTR)Menusorder, -1, szSubMenuMacro, 256);
                if ( _tcscspn( Menus->GetAt( k )->name, _T( "*" ) ) < ( size_t )MenusName.GetLength() )
                {
                    MenusName.TrimLeft( _T( '*' ) );
                    //					MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPTSTR)(LPCTSTR)MenusName, -1, szSubMenu, 256);
                    _tcscpy( szSubMenu, MenusName );
                    hr = mnu->AddSubMenu( index, szSubMenu, &MenuItem );
                }
                else if ( _tcscspn( Menus->GetAt( k )->name, _T( "$" ) ) < ( size_t )MenusName.GetLength() )
                {
                    MenusName.TrimLeft( _T( '$' ) );
                    if( MenusName.Compare( _T( "--" ) ) == 0 ) //添加子菜单的分隔符
                    {
                        hr = MenuItem->AddSeparator( index, &mnuitem );
                    }
                    else
                    {
                        //MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (LPTSTR)(LPCTSTR)MenusName, -1, szSubMenu, 256);
                        _tcscpy( szSubMenu, MenusName );
                        hr = MenuItem->AddMenuItem( index, szSubMenu, szSubMenuMacro, &mnuitem );
                    }
                }
                else
                {
                    hr = mnu->AddMenuItem( index, szSubMenu, szSubMenuMacro, &mnuitem );
                }
            }
        }
    }

    for ( i = 0; i < MnuAdrs.GetSize(); i++ )
    {
        MnuAdrs[i]->Release();
    }
    mnuitem->Release();
    mnus->Release();
    mnuGrp->Release();
    pMainFrame->UnlockWindowUpdate();

    stcMyTopMenuNames.Copy( m_TopMenuNames ); //将顶级菜单名存入静态数组中,卸载时使用

    //return ;
}
Example #7
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;
}