easypower 发表于 2009-2-10 12:22:00

<p>1.profiles</p><p>2.com方式产生</p>

庞琛虹 发表于 2009-2-10 20:49:00

开发文档中好像有个例子的啊

unionsoft 发表于 2009-2-12 13:21:00

可以在Arx直接调用命令'menu'来加载,这样当Arx加载时,菜单也加载了。<br/>当然之前要将对话框模式关闭: filedia=0

gentlerain 发表于 2009-4-11 09:56:00

<p>&nbsp;static void HxjMenuCom_AddMenu(void)<br/>&nbsp;{<br/>&nbsp;&nbsp;// Add your code for command HxjMenuCom._AddMenu here<br/>&nbsp;&nbsp;TRY<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;CAcadApplication IAcad(acedGetAcadWinApp()-&gt;GetIDispatch(TRUE));<br/>&nbsp;&nbsp;&nbsp;CAcadMenuBar IMenuBar(IAcad.get_MenuBar());<br/>&nbsp;&nbsp;&nbsp;long numberOfMenus;<br/>&nbsp;&nbsp;&nbsp;numberOfMenus=IMenuBar.get_Count();<br/>&nbsp;&nbsp;&nbsp;CAcadMenuGroups IMenuGroups(IAcad.get_MenuGroups());<br/>&nbsp;&nbsp;&nbsp;VARIANT index;<br/>&nbsp;&nbsp;&nbsp;VariantInit(&amp;index);<br/>&nbsp;&nbsp;&nbsp;V_VT(&amp;index)=VT_I4;<br/>&nbsp;&nbsp;&nbsp;V_I4(&amp;index)=0;<br/>&nbsp;&nbsp;&nbsp;CAcadMenuGroup IMenuGroup(IMenuGroups.Item(index));<br/>&nbsp;&nbsp;&nbsp;CAcadPopupMenus IPopUpMenus(IMenuGroup.get_Menus());<br/>&nbsp;&nbsp;&nbsp;CString cstrMenuName="总图(&amp;Z)";<br/>&nbsp;&nbsp;&nbsp;VariantInit(&amp;index);<br/>&nbsp;&nbsp;&nbsp;V_VT(&amp;index)=VT_BSTR;<br/>&nbsp;&nbsp;&nbsp;V_BSTR(&amp;index)=cstrMenuName.AllocSysString();<br/>&nbsp;&nbsp;&nbsp;IDispatch* pDisp=NULL;<br/>&nbsp;&nbsp;&nbsp;//see if the menu is already there<br/>&nbsp;&nbsp;&nbsp;TRY<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;pDisp=IPopUpMenus.Item(index);<br/>&nbsp;&nbsp;&nbsp;&nbsp;pDisp-&gt;AddRef();<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;CATCH(COleDispatchException,e)<br/>&nbsp;&nbsp;&nbsp;{</p><p>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;END_CATCH;<br/>&nbsp;&nbsp;&nbsp;if(pDisp==NULL)<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;//create it<br/>&nbsp;&nbsp;&nbsp;&nbsp;CAcadPopupMenu IPopUpMenu(IPopUpMenus.Add(cstrMenuName));<br/>&nbsp;&nbsp;&nbsp;&nbsp;VariantInit(&amp;index);<br/>&nbsp;&nbsp;&nbsp;&nbsp;V_VT(&amp;index)=VT_I4;<br/>&nbsp;&nbsp;&nbsp;&nbsp;V_I4(&amp;index)=0;<br/>&nbsp;&nbsp;&nbsp;&nbsp;IPopUpMenu.AddMenuItem(index,"直线(&amp;L)","_Line ");<br/>&nbsp;&nbsp;&nbsp;&nbsp;///////////////////<br/>&nbsp;&nbsp;&nbsp;&nbsp;VariantInit(&amp;index);<br/>&nbsp;&nbsp;&nbsp;&nbsp;V_VT(&amp;index)=VT_I4;<br/>&nbsp;&nbsp;&nbsp;&nbsp;V_I4(&amp;index)=1;<br/>&nbsp;&nbsp;&nbsp;&nbsp;IPopUpMenu.AddSeparator(index);<br/>&nbsp;&nbsp;&nbsp;&nbsp;///////////////////<br/>&nbsp;&nbsp;&nbsp;&nbsp;VariantInit(&amp;index);<br/>&nbsp;&nbsp;&nbsp;&nbsp;V_VT(&amp;index)=VT_I4;<br/>&nbsp;&nbsp;&nbsp;&nbsp;V_I4(&amp;index)=2;<br/>&nbsp;&nbsp;&nbsp;&nbsp;IPopUpMenu.AddMenuItem(index,"圆(&amp;C)","_Circle ");</p><p>&nbsp;&nbsp;&nbsp;&nbsp;pDisp=IPopUpMenu.m_lpDispatch;<br/>&nbsp;&nbsp;&nbsp;&nbsp;pDisp-&gt;AddRef();<br/>&nbsp;&nbsp;&nbsp;}</p><p>&nbsp;&nbsp;&nbsp;CAcadPopupMenu IPopUpMenu(pDisp);<br/>&nbsp;&nbsp;&nbsp;if(!IPopUpMenu.get_OnMenuBar())<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;VariantInit(&amp;index);<br/>&nbsp;&nbsp;&nbsp;&nbsp;V_VT(&amp;index)=VT_I4;<br/>&nbsp;&nbsp;&nbsp;&nbsp;V_I4(&amp;index)=numberOfMenus-2;<br/>&nbsp;&nbsp;&nbsp;&nbsp;IPopUpMenu.InsertInMenuBar(index);<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;else<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;VariantInit(&amp;index);<br/>&nbsp;&nbsp;&nbsp;&nbsp;V_VT(&amp;index)=VT_BSTR;<br/>&nbsp;&nbsp;&nbsp;&nbsp;V_BSTR(&amp;index)=cstrMenuName.AllocSysString();<br/>&nbsp;&nbsp;&nbsp;&nbsp;IPopUpMenus.RemoveMenuFromMenuBar(index);<br/>&nbsp;&nbsp;&nbsp;&nbsp;VariantClear(&amp;index);<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;&nbsp;pDisp-&gt;Release();<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;CATCH(COleDispatchException,e)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;e-&gt;ReportError();<br/>&nbsp;&nbsp;&nbsp;e-&gt;Delete();<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;END_CATCH;<br/>&nbsp;}</p><p></p><p>稍微改一下就可以变为自动了,经过调试可以运行</p>

松竹 发表于 2009-4-12 22:45:00

<p>不知是想使用代码的方式动态添加菜单还是使用mnu文件的方式添加菜单,如果使用代码的方式添加菜单需要使用AutoCAD的com接口来实现。参考下面的代码:</p><p>void TdiFoundationApp::CreateMenuItem()<br/>{<br/>&nbsp;TRY<br/>&nbsp;{<br/>&nbsp;&nbsp;IAcadApplication IAcad(acedGetAcadWinApp()-&gt;GetIDispatch(TRUE));</p><p>&nbsp;&nbsp;IAcadMenuBar IMenuBar(IAcad.GetMenuBar());</p><p>&nbsp;&nbsp;long numberOfMenus;<br/>&nbsp;&nbsp;numberOfMenus = IMenuBar.GetCount();</p><p>&nbsp;&nbsp;IAcadMenuGroups IMenuGroups(IAcad.GetMenuGroups());</p><p>&nbsp;&nbsp;VARIANT index;<br/>&nbsp;&nbsp;VariantInit(&amp;index);<br/>&nbsp;&nbsp;V_VT(&amp;index) = VT_I4;<br/>&nbsp;&nbsp;V_I4(&amp;index) = 0;</p><p>&nbsp;&nbsp;IAcadMenuGroup IMenuGroup(IMenuGroups.Item(index));</p><p>&nbsp;&nbsp;IAcadPopupMenus IPopUpMenus(IMenuGroup.GetMenus());</p><p>&nbsp;&nbsp;CString cstrMenuName = _T("TDI");</p><p>&nbsp;&nbsp;VariantInit(&amp;index);<br/>&nbsp;&nbsp;V_VT(&amp;index) = VT_BSTR;<br/>&nbsp;&nbsp;V_BSTR(&amp;index) = cstrMenuName.AllocSysString();</p><p>&nbsp;&nbsp;IDispatch* pDisp=NULL;</p><p>&nbsp;&nbsp;//see if the menu is already there<br/>&nbsp;&nbsp;TRY<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;pDisp = IPopUpMenus.Item(index);<br/>&nbsp;&nbsp;&nbsp;pDisp-&gt;AddRef();<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;CATCH(COleDispatchException,e)<br/>&nbsp;&nbsp;{}<br/>&nbsp;&nbsp;END_CATCH;</p><p>&nbsp;&nbsp;int iIndex = 0;<br/>&nbsp;&nbsp;if (pDisp==NULL)<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;//create it<br/>&nbsp;&nbsp;&nbsp;IAcadPopupMenu IPopUpMenu(IPopUpMenus.Add(cstrMenuName));</p><p>&nbsp;&nbsp;&nbsp;VariantInit(&amp;index);<br/>&nbsp;&nbsp;&nbsp;V_VT(&amp;index) = VT_I4;<br/>&nbsp;&nbsp;&nbsp;V_I4(&amp;index) = iIndex++;<br/>&nbsp;&nbsp;&nbsp;IPopUpMenu.AddMenuItem(index, _T("新建(&amp;N)"), _T("_MyNEW "));</p><p>&nbsp;&nbsp;&nbsp;VariantInit(&amp;index);<br/>&nbsp;&nbsp;&nbsp;V_VT(&amp;index) = VT_I4;<br/>&nbsp;&nbsp;&nbsp;V_I4(&amp;index) = iIndex++;<br/>&nbsp;&nbsp;&nbsp;IPopUpMenu.AddMenuItem(index, _T("检入(&amp;I)"), _T("_MyCHECKIN "));</p><p><br/>&nbsp;&nbsp;&nbsp;pDisp = IPopUpMenu.m_lpDispatch;<br/>&nbsp;&nbsp;&nbsp;pDisp-&gt;AddRef();<br/>&nbsp;&nbsp;}</p><p>&nbsp;&nbsp;IAcadPopupMenu IPopUpMenu(pDisp);<br/>&nbsp;&nbsp;if (!IPopUpMenu.GetOnMenuBar())<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;VariantInit(&amp;index);<br/>&nbsp;&nbsp;&nbsp;V_VT(&amp;index) = VT_I4;<br/>&nbsp;&nbsp;&nbsp;V_I4(&amp;index) = numberOfMenus - 2;;<br/>&nbsp;&nbsp;&nbsp;IPopUpMenu.InsertInMenuBar(index);<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;else<br/>&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;VariantInit(&amp;index);<br/>&nbsp;&nbsp;&nbsp;V_VT(&amp;index) = VT_BSTR;<br/>&nbsp;&nbsp;&nbsp;V_BSTR(&amp;index) = cstrMenuName.AllocSysString();<br/>&nbsp;&nbsp;&nbsp;IPopUpMenus.RemoveMenuFromMenuBar(index);<br/>&nbsp;&nbsp;&nbsp;VariantClear(&amp;index);<br/>&nbsp;&nbsp;}<br/>&nbsp;&nbsp;pDisp-&gt;Release();<br/>&nbsp;}<br/>&nbsp;CATCH(COleDispatchException,e)<br/>&nbsp;{<br/>&nbsp;&nbsp;e-&gt;ReportError();<br/>&nbsp;&nbsp;e-&gt;Delete();<br/>&nbsp;}<br/>&nbsp;END_CATCH;<br/>}</p>

nogirlfriend 发表于 2009-4-22 21:08:00

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

nogirlfriend 发表于 2009-4-23 18:10:00

<p>利用Com来做吧 </p><p>具体见例子:\samples\com\AsdkMfcComSamp_dg</p><p></p>
页: 1 [2]
查看完整版本: 斑竹,问一个比较难的问题,在ARX中如何加载菜单