明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
12
返回列表 发新帖
楼主: sophie_wzh

斑竹,问一个比较难的问题,在ARX中如何加载菜单

  [复制链接]
发表于 2009-2-10 12:22:00 | 显示全部楼层

1.profiles

2.com方式产生

发表于 2009-2-10 20:49:00 | 显示全部楼层
开发文档中好像有个例子的啊
发表于 2009-2-12 13:21:00 | 显示全部楼层
可以在Arx直接调用命令'menu'来加载,这样当Arx加载时,菜单也加载了。
当然之前要将对话框模式关闭: filedia=0
发表于 2009-4-11 09:56:00 | 显示全部楼层

 static void HxjMenuCom_AddMenu(void)
 {
  // Add your code for command HxjMenuCom._AddMenu here
  TRY
  {
   CAcadApplication IAcad(acedGetAcadWinApp()->GetIDispatch(TRUE));
   CAcadMenuBar IMenuBar(IAcad.get_MenuBar());
   long numberOfMenus;
   numberOfMenus=IMenuBar.get_Count();
   CAcadMenuGroups IMenuGroups(IAcad.get_MenuGroups());
   VARIANT index;
   VariantInit(&index);
   V_VT(&index)=VT_I4;
   V_I4(&index)=0;
   CAcadMenuGroup IMenuGroup(IMenuGroups.Item(index));
   CAcadPopupMenus IPopUpMenus(IMenuGroup.get_Menus());
   CString cstrMenuName="总图(&Z)";
   VariantInit(&index);
   V_VT(&index)=VT_BSTR;
   V_BSTR(&index)=cstrMenuName.AllocSysString();
   IDispatch* pDisp=NULL;
   //see if the menu is already there
   TRY
   {
    pDisp=IPopUpMenus.Item(index);
    pDisp->AddRef();
   }
   CATCH(COleDispatchException,e)
   {

   }
   END_CATCH;
   if(pDisp==NULL)
   {
    //create it
    CAcadPopupMenu IPopUpMenu(IPopUpMenus.Add(cstrMenuName));
    VariantInit(&index);
    V_VT(&index)=VT_I4;
    V_I4(&index)=0;
    IPopUpMenu.AddMenuItem(index,"直线(&L)","_Line ");
    ///////////////////
    VariantInit(&index);
    V_VT(&index)=VT_I4;
    V_I4(&index)=1;
    IPopUpMenu.AddSeparator(index);
    ///////////////////
    VariantInit(&index);
    V_VT(&index)=VT_I4;
    V_I4(&index)=2;
    IPopUpMenu.AddMenuItem(index,"圆(&C)","_Circle ");

    pDisp=IPopUpMenu.m_lpDispatch;
    pDisp->AddRef();
   }

   CAcadPopupMenu IPopUpMenu(pDisp);
   if(!IPopUpMenu.get_OnMenuBar())
   {
    VariantInit(&index);
    V_VT(&index)=VT_I4;
    V_I4(&index)=numberOfMenus-2;
    IPopUpMenu.InsertInMenuBar(index);
   }
   else
   {
    VariantInit(&index);
    V_VT(&index)=VT_BSTR;
    V_BSTR(&index)=cstrMenuName.AllocSysString();
    IPopUpMenus.RemoveMenuFromMenuBar(index);
    VariantClear(&index);
   }
   pDisp->Release();
  }
  CATCH(COleDispatchException,e)
  {
   e->ReportError();
   e->Delete();
  }
  END_CATCH;
 }

稍微改一下就可以变为自动了,经过调试可以运行

发表于 2009-4-12 22:45:00 | 显示全部楼层

不知是想使用代码的方式动态添加菜单还是使用mnu文件的方式添加菜单,如果使用代码的方式添加菜单需要使用AutoCAD的com接口来实现。参考下面的代码:

void TdiFoundationApp::CreateMenuItem()
{
 TRY
 {
  IAcadApplication IAcad(acedGetAcadWinApp()->GetIDispatch(TRUE));

  IAcadMenuBar IMenuBar(IAcad.GetMenuBar());

  long numberOfMenus;
  numberOfMenus = IMenuBar.GetCount();

  IAcadMenuGroups IMenuGroups(IAcad.GetMenuGroups());

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

  IAcadMenuGroup IMenuGroup(IMenuGroups.Item(index));

  IAcadPopupMenus IPopUpMenus(IMenuGroup.GetMenus());

  CString cstrMenuName = _T("TDI");

  VariantInit(&index);
  V_VT(&index) = VT_BSTR;
  V_BSTR(&index) = cstrMenuName.AllocSysString();

  IDispatch* pDisp=NULL;

  //see if the menu is already there
  TRY
  {
   pDisp = IPopUpMenus.Item(index);
   pDisp->AddRef();
  }
  CATCH(COleDispatchException,e)
  {}
  END_CATCH;

  int iIndex = 0;
  if (pDisp==NULL)
  {
   //create it
   IAcadPopupMenu IPopUpMenu(IPopUpMenus.Add(cstrMenuName));

   VariantInit(&index);
   V_VT(&index) = VT_I4;
   V_I4(&index) = iIndex++;
   IPopUpMenu.AddMenuItem(index, _T("新建(&N)"), _T("_MyNEW "));

   VariantInit(&index);
   V_VT(&index) = VT_I4;
   V_I4(&index) = iIndex++;
   IPopUpMenu.AddMenuItem(index, _T("检入(&I)"), _T("_MyCHECKIN "));


   pDisp = IPopUpMenu.m_lpDispatch;
   pDisp->AddRef();
  }

  IAcadPopupMenu IPopUpMenu(pDisp);
  if (!IPopUpMenu.GetOnMenuBar())
  {
   VariantInit(&index);
   V_VT(&index) = VT_I4;
   V_I4(&index) = numberOfMenus - 2;;
   IPopUpMenu.InsertInMenuBar(index);
  }
  else
  {
   VariantInit(&index);
   V_VT(&index) = VT_BSTR;
   V_BSTR(&index) = cstrMenuName.AllocSysString();
   IPopUpMenus.RemoveMenuFromMenuBar(index);
   VariantClear(&index);
  }
  pDisp->Release();
 }
 CATCH(COleDispatchException,e)
 {
  e->ReportError();
  e->Delete();
 }
 END_CATCH;
}

发表于 2009-4-22 21:08:00 | 显示全部楼层

利用COM接口来实现相关autocad菜单的扩展。。。。

发表于 2009-4-23 18:10:00 | 显示全部楼层

利用Com来做吧

具体见例子:\samples\com\AsdkMfcComSamp_dg

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 14:49 , Processed in 0.169482 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表