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;
}
Exemple #2
0
void AppMenu::CleanUpMenus()
{
    IAcadMenuGroup* mnuGrp = NULL;
    for( int i = 0; i < stcMyTopMenuNames.GetSize(); i++ )
    {
        CString sMenu = stcMyTopMenuNames.GetAt( i );
        sMenu.Replace( _T( "&" ), _T( "" ) );

        if ( !GetAcadMenuGroup( &mnuGrp, sMenu ) )
        {
#ifdef _DEBUG
            acutPrintf( _T( "没有找到 %s 所属的菜单组,无法卸载。 " ), sMenu );
#endif

            //   mnuGrp->Release();
            continue;
        }

        //得到所有菜单组
        IAcadPopupMenus*  mnus = NULL;
        HRESULT hr = S_OK;
        hr = mnuGrp->get_Menus( &mnus );

        ClearMenu( mnus, sMenu );

        mnus->Release();
        mnuGrp->Release();

    }

    stcMyTopMenuNames.RemoveAll();
}
Exemple #3
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;
}
Exemple #4
0
void CreateToolbars()
{
    IAcadMenuGroup *mnuGrp = NULL;
    if (!getAcadMenuGroup(&mnuGrp))
        return ;
    //now get all the popup menus
    IAcadToolbars  *tlbrs = NULL;
    HRESULT hr = S_OK;
    hr = mnuGrp->get_Toolbars(&tlbrs);
    mnuGrp->Release();
    //let us create toolbars for polysamp
    IAcadToolbar  *tlbr = NULL;
    hr = tlbrs->Add(L"POLYSAMP APPLICATION", &tlbr);
    if FAILED(hr)
        return;
    tlbrs->Release();
    //now add toolbar buttons
    IAcadToolbarItem  *button1 = NULL;
    IAcadToolbarItem  *button2 = NULL;
    IAcadToolbarItem  *button3 = NULL;
    IAcadToolbarItem  *button4, *button5, *button6, *button7, *button8 = NULL;
    VARIANT index;
    index.vt = VT_I4;
    index.lVal = 100l;

    VARIANT vtFalse;
    vtFalse.vt = VT_BOOL;
    vtFalse.boolVal = VARIANT_FALSE;

    hr = tlbr->AddToolbarButton(index, L"POLY", L"Creates poly entity", L"_poly ", vtFalse, &button1);
    button1->Release();
    hr = tlbr->AddToolbarButton(index, L"DRAGPOLY", L"Creates poly entity using dragging", L"_dragpoly ", vtFalse, &button2);
    button1->Release();
    hr = tlbr->AddToolbarButton(index, L"POLYEDIT", L"Edits poly entity", L"_POLYEDIT ", vtFalse, &button3);
    button1->Release();
    hr = tlbr->AddToolbarButton(index, L"TRANSACT", L"Test Transaction on  poly entity", L"_TRANSACT ", vtFalse, &button4);
    button1->Release();
    hr = tlbr->AddToolbarButton(index, L"HILITPOLY", L"Hilight poly entity", L"_HILITPOLY ", vtFalse, &button5);
    button1->Release();
    hr = tlbr->AddToolbarButton(index, L"HILITSOLID", L"Hilight solid entity", L"_HILITSOLID ", vtFalse, &button1);
    button1->Release();
    hr = tlbr->AddToolbarButton(index, L"CREATEINSERT", L"Creates inserted entity", L"_CREATEINSERT ", vtFalse, &button6);
    button1->Release();
    hr = tlbr->AddToolbarButton(index, L"HILITINSERT", L"Highlight inserted entity", L"_HILITINSERT ", vtFalse, &button7);
    button1->Release();
    hr = tlbr->AddToolbarButton(index, L"USEDRAGDATA", L"Test user dragging mechanism", L"_USEDRAGDATA ", vtFalse, &button8);
    button1->Release();


    tlbr->Dock(acToolbarDockLeft);
    tlbr->Release();
    return;


}
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 #6
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;
}
void CreateToolbars()
{
	if (Glb_toolbarArray.GetCount() > 0)
		return;

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

	IAcadToolbars  *tlbrs = NULL;
	HRESULT hr = S_OK;
	hr = mnuGrp->get_Toolbars(&tlbrs);
	mnuGrp->Release();

	// 得到arx所在路径
	TCHAR lpPath[MAX_PATH] = {0};
	GetModuleFileName(GetModuleHandle("DistToolBar.arx"), lpPath, MAX_PATH);
	PathRemoveFileSpec(lpPath);
	PathAddBackslash(lpPath);

	CString strXmlFile = lpPath;
	strXmlFile += "toolbar.xml";

	// 得到icon路径
	PathAppend(lpPath, "icon");
	PathAddBackslash(lpPath);

	MSXML2::IXMLDOMDocumentPtr lpDocument;
	hr = lpDocument.CreateInstance(__uuidof(DOMDocument));

	if ( FAILED(hr) ) 
		_com_raise_error(hr);

	VARIANT_BOOL isSuccessful;

	// 装载XML字符串
	if (!lpDocument->load(_variant_t(strXmlFile)))
	{
		OutputDebugString("LoadXML failed!");

		return;
	}

	MSXML2::IXMLDOMElementPtr lpDocElement = NULL;
	lpDocument->get_documentElement(&lpDocElement);

	// toolbar list
	MSXML2::IXMLDOMNodeListPtr lpToolbarList = lpDocElement->getElementsByTagName(_bstr_t("toolbar"));

	MSXML2::IXMLDOMNodePtr lpToolbar = NULL;

	for ( ; (lpToolbar = lpToolbarList->nextNode()) != NULL ; )
	{

		MSXML2::IXMLDOMNodePtr lpCaptionNode = lpToolbar->attributes->getNamedItem("caption");
		CString strCaption = (char*)lpCaptionNode->text;

		OutputDebugString(strCaption);

		// 添加工具条
		IAcadToolbar  *tlbr = NULL;
		hr = tlbrs->Add(CComBSTR(strCaption), &tlbr);

		if FAILED(hr)
			continue;

		Glb_toolbarArray.Add(strCaption);

		// button list
		MSXML2::IXMLDOMNodeListPtr lpButtonList = lpToolbar->GetchildNodes();

		MSXML2::IXMLDOMNodePtr lpButton = NULL;

		for ( ; (lpButton = lpButtonList->nextNode()) != NULL ; )
		{
			MSXML2::IXMLDOMNodePtr lpToolTipNode = lpButton->attributes->getNamedItem("tooltip");
			CString strToolTip = (char*)lpToolTipNode->text;

			MSXML2::IXMLDOMNodePtr lpCommandNode = lpButton->attributes->getNamedItem("command");
			CString strCommand = (char*)lpCommandNode->text;
			strCommand += " ";

			MSXML2::IXMLDOMNodePtr lpIconNode = lpButton->attributes->getNamedItem("icon");
			CString strIcon = (char*)lpIconNode->text;

			OutputDebugStringX("tooltip=%s, command=%s, icon=%s", strToolTip, strCommand, strIcon);

			// 添加工具按钮
			IAcadToolbarItem *button=NULL;
			VARIANT index;
			index.vt = VT_I4;
			index.lVal = 100l;

			VARIANT vtFalse;
			vtFalse.vt = VT_BOOL;
			vtFalse.boolVal = VARIANT_FALSE;

			CString strIconFile = lpPath;
			strIconFile += strIcon;

			if (!PathFileExists(strIconFile))
			{
				strIconFile = lpPath;
				strIconFile += "dist.ico";
			}

			if (!PathFileExists(strIconFile)) continue;

			hr = tlbr->AddToolbarButton(index, CComBSTR(strToolTip), CComBSTR(strToolTip), CComBSTR(strCommand), vtFalse, &button);

			hr = button->SetBitmaps(CComBSTR(strIconFile), CComBSTR(strIconFile));

			button->Release();
		}

		tlbr->Dock(acToolbarDockRight);//acToolbarFloating
		tlbr->Release();
	}

	tlbrs->Release();

	return;
}
Exemple #8
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;
}
Exemple #9
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;
}
Exemple #10
0
void ArxToolBar::CreateToolBars( const TCHAR* bmpDir )
{
    CMDIFrameWnd* pMainFrame = acedGetAcadFrame();
    pMainFrame->LockWindowUpdate();

    // 获取主菜单组
    IAcadMenuGroup* mnuGrp = NULL;
    if ( !GetAcadMenuGroup( &mnuGrp ) )
        return ;

    //得到所有菜单组
    HRESULT hr = S_OK;
    IAcadToolbars* acToolbars = NULL;
    hr = mnuGrp->get_Toolbars( &acToolbars );

    // 如果bmpDir路径没有反斜杠(\),则添加一个反斜杠
    CString path( bmpDir );
    // 取最后一个字符
    if( path.Right( 1 ) != _T( "\\" ) )
    {
        path.Format( _T( "%s\\" ), bmpDir );
    }

    VARIANT index;
    VariantInit( &index );
    V_VT( &index ) = VT_I4;

    TCHAR MenuName[256];
    int delta = 30; // 工具栏间距
    int top = 200, left = 200;
    for ( int i = 0; i < m_menuCount; i++ )
    {
        IAcadToolbar* acToolbar = NULL;
        _tcscpy( MenuName, m_TopMenuNames[i] );
        hr = acToolbars->Add( MenuName, &acToolbar );

        acToolbar->put_Visible( true );
        acToolbar->Dock( acToolbarFloating );
        acToolbar->Float( top + i * delta, left, 1 );

        CCADToolButtonArray* Menus = m_menus[i];
        COleVariant flyOutButton;
        for ( int j = 0; j < Menus->GetSize(); j++ )
        {
            // 添加按钮
            V_I4( &index ) = ( long )j;
            CADToolButton* btn = Menus->GetAt( j );
            IAcadToolbarItem* acToolbarItem = NULL;

            if( _tcscmp( _T( "--" ), btn->name ) == 0 )
            {
                hr = acToolbar->AddSeparator( index, &acToolbarItem );
            }
            else
            {
                hr = acToolbar->AddToolbarButton( index, btn->name, btn->help, btn->order, flyOutButton, &acToolbarItem );

                TCHAR szBmpFile[256];
                _stprintf( szBmpFile, _T( "%s%s" ), path, btn->bmp );
                //acutPrintf(_T("\n路径:%s"), szBmpFile);

                hr = acToolbarItem->SetBitmaps( szBmpFile, szBmpFile );
            }
        }
        //acToolbarItem->Release();
        acToolbar->Release();
    }

    acToolbars->Release();
    mnuGrp->Release();
    pMainFrame->UnlockWindowUpdate();

    //stcMyToolBarNames.Copy(m_TopMenuNames); //将工具栏名称存入静态数组中,卸载时使用
}
void CreateToolbars()
{
    IAcadMenuGroup *mnuGrp = NULL;
    if (!getAcadMenuGroup(&mnuGrp))
        return ;
    //now get all the popup menus 
    IAcadToolbars  *tlbrs = NULL;
    HRESULT hr = S_OK;
    hr = mnuGrp->get_Toolbars(&tlbrs);
    mnuGrp->Release();
    //let us create toolbars for polysamp
    IAcadToolbar  *tlbr = NULL;
    hr = tlbrs->Add(L"POLYSAMP APPLICATION", &tlbr);
    if FAILED(hr)
        return;
    tlbrs->Release();
    //now add toolbar buttons
    IAcadToolbarItem *button=NULL;
    VARIANT index;
    index.vt = VT_I4;
    index.lVal = 100l;

    VARIANT vtFalse;
    vtFalse.vt = VT_BOOL;
    vtFalse.boolVal = VARIANT_FALSE;

    TCHAR szFileName[MAX_PATH];
    GetModuleFileName(GetModuleHandle(_T("asdkPolyUi.arx")),szFileName,MAX_PATH);
    CString csPath(szFileName);
    csPath=csPath.Left(csPath.ReverseFind(_T('\\')));
    //x64 binaries are created within x64\ folder
#if defined(_WIN64) || defined(_AC64)
    csPath=csPath.Left(csPath.ReverseFind(_T('\\')));
#endif
    csPath=csPath.Left(csPath.ReverseFind(_T('\\'))+1);

    hr = tlbr->AddToolbarButton(index, L"POLY", L"Creates poly entity", L"_poly ", vtFalse, &button);
    hr=button->SetBitmaps(CComBSTR(csPath+_T("1_Poly1.ico")),CComBSTR(csPath+_T("1_Poly1.ico")));
    button->Release();
    hr = tlbr->AddToolbarButton(index, L"DRAGPOLY", L"Creates poly entity using dragging", L"_dragpoly ", vtFalse, &button);
    hr=button->SetBitmaps(CComBSTR(csPath+_T("1_Poly2.ico")),CComBSTR(csPath+_T("1_Poly2.ico")));
    button->Release();
    hr = tlbr->AddToolbarButton(index, L"POLYEDIT", L"Edits poly entity", L"_POLYEDIT ", vtFalse, &button);
    hr=button->SetBitmaps(CComBSTR(csPath+_T("1_Poly3.ico")),CComBSTR(csPath+_T("1_Poly3.ico")));
    button->Release();
    hr = tlbr->AddToolbarButton(index, L"TRANSACT", L"Test Transaction on  poly entity", L"_TRANSACT ", vtFalse, &button);
    hr=button->SetBitmaps(CComBSTR(csPath+_T("1_Poly4.ico")),CComBSTR(csPath+_T("1_Poly4.ico")));
    button->Release();
    hr = tlbr->AddToolbarButton(index, L"HILITPOLY", L"Hilight poly entity", L"_HILITPOLY ", vtFalse, &button);
    hr=button->SetBitmaps(CComBSTR(csPath+_T("1_Poly5.ico")),CComBSTR(csPath+_T("1_Poly5.ico")));
    button->Release();
    hr = tlbr->AddToolbarButton(index, L"HILITSOLID", L"Hilight solid entity", L"_HILITSOLID ", vtFalse, &button);
    hr=button->SetBitmaps(CComBSTR(csPath+_T("1_Poly6.ico")),CComBSTR(csPath+_T("1_Poly6.ico")));
    button->Release();
    hr = tlbr->AddToolbarButton(index, L"CREATEINSERT", L"Creates inserted entity", L"_CREATEINSERT ", vtFalse, &button);
    hr=button->SetBitmaps(CComBSTR(csPath+_T("1_Poly7.ico")),CComBSTR(csPath+_T("1_Poly7.ico")));
    button->Release();
    hr = tlbr->AddToolbarButton(index, L"HILITINSERT", L"Highlight inserted entity", L"_HILITINSERT ", vtFalse, &button);
    hr=button->SetBitmaps(CComBSTR(csPath+_T("1_Poly8.ico")),CComBSTR(csPath+_T("1_Poly8.ico")));
    button->Release();
    hr = tlbr->AddToolbarButton(index, L"USEDRAGDATA", L"Test user dragging mechanism", L"_USEDRAGDATA ", vtFalse, &button);
    hr=button->SetBitmaps(CComBSTR(csPath+_T("1_Poly1.ico")),CComBSTR(csPath+_T("1_Poly1.ico")));
    button->Release();


    tlbr->Dock(acToolbarDockLeft);
    tlbr->Release();
    return;


}
Exemple #12
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 ;
}
Exemple #13
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;
}
Exemple #14
0
void AppToolBar::CreateToolBars()
{
    CMDIFrameWnd* pMainFrame = acedGetAcadFrame();
    pMainFrame->LockWindowUpdate();

    // 获取主菜单组
    IAcadMenuGroup* mnuGrp = NULL;
    if ( !GetAcadMenuGroup( &mnuGrp ) )
        return ;

    //得到所有菜单组
    HRESULT hr = S_OK;
    IAcadToolbars* acToolbars = NULL;
    hr = mnuGrp->get_Toolbars( &acToolbars );

    CString appFileName = acedGetAppName(); //取出完整的应用程序名称,含路径
    TCHAR dir[_MAX_DIR], drive[_MAX_DRIVE], path[_MAX_PATH];
    _tsplitpath( appFileName, drive, dir, NULL, NULL );
    _tmakepath( path, drive, dir, NULL, NULL );

    VARIANT index;
    VariantInit( &index );
    V_VT( &index ) = VT_I4;

    TCHAR MenuName[256];
    int delta = 30; // 工具栏间距
    int top = 200, left = 200;
    for ( int i = 0; i < m_menuCount; i++ )
    {
        IAcadToolbar* acToolbar = NULL;
        _tcscpy( MenuName, m_TopMenuNames[i] );
        hr = acToolbars->Add( MenuName, &acToolbar );

        acToolbar->put_Visible( true );
        acToolbar->Dock( acToolbarFloating );
        acToolbar->Float( top + i * delta, left, 1 );

        CCADToolButtonArray* Menus = m_menus[i];
        COleVariant flyOutButton;
        for ( int j = 0; j < Menus->GetSize(); j++ )
        {
            // 添加按钮
            V_I4( &index ) = ( long )j;
            CADToolButton* btn = Menus->GetAt( j );
            IAcadToolbarItem* acToolbarItem = NULL;

            if( _tcscmp( _T( "--" ), btn->name ) == 0 )
            {
                hr = acToolbar->AddSeparator( index, &acToolbarItem );
            }
            else
            {
                hr = acToolbar->AddToolbarButton( index, btn->name, btn->help, btn->order, flyOutButton, &acToolbarItem );

                CString bmpFile;
                bmpFile.Format( _T( "%s%s\\%s" ), path, BMP_DIR, btn->bmp );


                TCHAR szBmpFile[256];
                _tcscpy( szBmpFile, bmpFile );

                //acutPrintf(_T("\n路径:%s"), szBmpFile);
                hr = acToolbarItem->SetBitmaps( szBmpFile, szBmpFile );
            }
        }
        //acToolbarItem->Release();
        acToolbar->Release();
    }

    acToolbars->Release();
    mnuGrp->Release();
    pMainFrame->UnlockWindowUpdate();

    stcMyToolBarNames.Copy( m_TopMenuNames ); //将工具栏名称存入静态数组中,卸载时使用
}