加载并显示以及卸载局部菜单



//加载局部菜单
bool LoadPartialMenu(
const char* filePath //局部菜单文件名
, const char* menuGroupName //局部菜单组名
)
{
resbuf pSrcRb;
resbuf* pDestRb = NULL; 
if (acedGetVar("FILEDIA", &pSrcRb) != RTNORM) return false;
if ((pDestRb = acutBuildList(RTSHORT, 0, RTNONE)) == NULL) return false;


//不显示对话框,改为命令行
if (acedSetVar("FILEDIA", pDestRb) != RTNORM) {
acutRelRb(pDestRb);
return false;
}
acutRelRb(pDestRb);
//加载菜单
if (acedCommand(RTSTR, "menuload", RTSTR, filePath, 0) != RTNORM) {
acedSetVar("FILEDIA", &pSrcRb);
return false;
}
//加载局部菜单完毕,恢复原始状态
acedSetVar("FILEDIA", &pSrcRb);
//显示局部菜单
int i, j, n;
vector menuList;
char menuCmd[512];


//依次在主菜单条最后插入菜单,局部菜单不能达到一百个^-^
for (i = 0; i < 100; i++) {
//当前主菜单条上的菜单数肯定不会超过二百个^-^
sprintf(menuCmd, "200=+%s.POP%d", menuGroupName, i + 1);
acedMenuCmd(menuCmd);
}
//如果菜单已存在则系统会继续提示输入菜单文件,所以必须发送取消命令
menuCmd[0] = 27;
menuCmd[1] = '\0';
acDocManager->sendStringToExecute(curDoc(), menuCmd);
return true;
}


//卸载局部菜单
void RemovePartialMenu(const char* menuGroupName)
{
resbuf pSrcRb;
resbuf* pDestRb = NULL; 
if (acedGetVar("FILEDIA", &pSrcRb) != RTNORM) return ;
if ((pDestRb = acutBuildList(RTSHORT, 0, RTNONE)) == NULL) return ;


//不显示对话框,改为命令行
if (acedSetVar("FILEDIA", pDestRb) != RTNORM) {
acutRelRb(pDestRb);
return ;
}
acutRelRb(pDestRb);
acedCommand(RTSTR, "menuunload", RTSTR, menuGroupName, 0);
//卸载局部菜单完毕,恢复原始状态
acedSetVar("FILEDIA", &pSrcRb);

}






//加载局部菜单
bool LoadPartialMenu(
 const TCHAR* filePath   //局部菜单文件名
 , const TCHAR* menuGroupName  //
 )
{
 //如果有的话先卸载
 long i, menuGroupNum;   //菜单组数目
 VARIANT index;
 VariantInit(&index);
 index.vt = VT_I4;
 CString strGroupName(menuGroupName);
 CAcadApplication acadApp(acedGetAcadWinApp()->GetIDispatch(TRUE));
 CAcadMenuGroups menuGroups(acadApp.get_MenuGroups());
 CAcadMenuGroup menuGroup;
 menuGroupNum = menuGroups.get_Count();
 for (i = 0; i < menuGroupNum; i++) {
  index.lVal = i;
  menuGroup = menuGroups.Item(index);
  if (menuGroup.get_Name() == strGroupName) {
   menuGroup.Unload();
   break;
  }
 }
 //加载菜单
 VARIANT BaseMenu;   //是否加载为基础菜单
 VariantInit(&BaseMenu);
 BaseMenu.vt = VT_BOOL;
 BaseMenu.boolVal = FALSE;
 menuGroup = menuGroups.Load(CString(filePath), BaseMenu);
 // 把菜单在菜单条上显示出来
 CAcadMenuBar menuBar(acadApp.get_MenuBar());  //当前菜单条
 CAcadPopupMenus popupMenus(menuGroup.get_Menus()); //要加入的菜单条
 CAcadPopupMenu popupMenu;
 long curPopupMenuNum = menuBar.get_Count();   //当前菜单条上菜单的数目
 long n = popupMenus.get_Count();
 for (long i = 0; i < n; i++) {
  index.lVal = i;
  popupMenu = popupMenus.Item(index);
  index.lVal = i + curPopupMenuNum;
  popupMenu.InsertInMenuBar(index);
 }
 return true;
}
 
 

你可能感兴趣的:(加载并显示以及卸载局部菜单)