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


}
Example #4
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); //将工具栏名称存入静态数组中,卸载时使用
}
Example #5
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 ); //将工具栏名称存入静态数组中,卸载时使用
}