- 积分
- 390
- 明经币
- 个
- 注册时间
- 2005-3-25
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2005-4-1 10:07:00
|
显示全部楼层
我这里有段代码,不知对楼主有没有用:
//添加菜单 void addMenuThroughCOM(void)
{
AutoCAD::IAcadApplication *pAcad; HRESULT hr=NOERROR; CLSID clsid; LPUNKNOWN pUnk=NULL; LPDISPATCH pAcadDisp=NULL; hr=::CLSIDFromProgID(L"AutoCAD.Application",&clsid); if (SUCCEEDED(hr)) { if (::GetActiveObject (clsid,NULL,&pUnk)==S_OK) { if (pUnk->QueryInterface (IID_IDispatch,(LPVOID*)&pAcadDisp) !=S_OK) return; pUnk->Release (); } } if (SUCCEEDED(pAcadDisp->QueryInterface (AutoCAD::IID_IAcadApplication ,(void**) &pAcad))) pAcad->put_Visible(true); else { acutPrintf("\n出错了!"); return; } AutoCAD::IAcadMenuBar *pMenuBar; AutoCAD::IAcadMenuGroups *pMenuGroups; pAcad->get_MenuBar(&pMenuBar); pAcad->get_MenuGroups(&pMenuGroups); pAcad->Release(); long numberOfMenus; pMenuBar->get_Count (&numberOfMenus); pMenuBar->Release (); VARIANT index; VariantInit(&index); V_VT(&index)=VT_I4; V_I4(&index)=0; AutoCAD::IAcadMenuGroup *pMenuGroup; pMenuGroups->Item (index,&pMenuGroup); pMenuGroups->Release (); AutoCAD::IAcadPopupMenus *pPopUpMenus; pMenuGroup->get_Menus (&pPopUpMenus); pMenuGroup->Release (); if (!bIsMenuLoaded) { WCHAR wstrMenuName[256]; AutoCAD::IAcadPopupMenu *pPopUpMenu; MultiByteToWideChar(CP_ACP,0,"毕业设计(&B)",-1,wstrMenuName,256); pPopUpMenus->Add(wstrMenuName,&pPopUpMenu); if (pPopUpMenu!=NULL) { // // AutoCAD::IAcadPopupMenuItem *pPopUpMenuItem; WCHAR wstrMenuItemName[256],wstrMenuItemMacro[256]; // // MultiByteToWideChar(CP_ACP,0,"长方体(&C)",-1,wstrMenuItemName,256); MultiByteToWideChar(CP_ACP,0,"frmbox ",-1,wstrMenuItemMacro,256); VariantInit(&index); V_VT(&index)=VT_I4; V_I4(&index)=0; pPopUpMenu->AddMenuItem (index,wstrMenuItemName,wstrMenuItemMacro, &pPopUpMenuItem);
// // MultiByteToWideChar(CP_ACP,0,"圆球体(&Y)",-1,wstrMenuItemName,256); MultiByteToWideChar(CP_ACP,0,"frmsph ",-1,wstrMenuItemMacro,256); VariantInit(&index); V_VT(&index)=VT_I4; V_I4(&index)=1; pPopUpMenu->AddMenuItem (index,wstrMenuItemName,wstrMenuItemMacro, &pPopUpMenuItem); // //
///////////////////生成菜单 VariantInit(&index); V_VT(&index)=VT_I4; V_I4(&index)=numberOfMenus-2; pPopUpMenu->InsertInMenuBar (index); pPopUpMenuItem->Release (); bIsMenuLoaded=true; } else { acutPrintf("\n没有产生菜单!"); } } pPopUpMenus->Release (); } |
|