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; }
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; }
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; }
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; }
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; }