liubo4869 发表于 2009-4-28 16:21:00

如何用C++开发菜单?

<p>&nbsp;&nbsp;&nbsp;&nbsp;<font size="4">
                </font><font size="3">小弟是做AutoCAD二次开发的菜鸟,开发环境是:VC++6.0&nbsp;&nbsp; +&nbsp;&nbsp; ObjectARX2002&nbsp;。 最近正在做菜单这块,在ObjectARX2002的开发包中有个快捷菜单的例子,非常有用。但是现在我面临的问题是:要做主菜单,查看了ObjectARX的帮助文档,发现有个<span class="h1overlay"><span lang="EN-US" style="FONT-SIZE: 14pt;"><font color="#ffffff" style="BACKGROUND-COLOR: #3399fe;"><strong>AcEdUIContext</strong></font></span></span><span style="FONT-SIZE: 14pt; FONT-FAMILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman';"><strong>类,</strong><span class="SpellE"><span lang="EN-US" style="FONT-SIZE: 10.5pt; FONT-FAMILY: 'Times New Roman';">ObjectARX</span>应用程序使用此类向AutoCAD快捷(环境)菜单中增加项。但是没有菜单类啊,是要从MFC的类库中继承一个类吗?但是,要是从MFC类库中继承的话,又如何实现和AutoCAD之间的通信呢?非常困扰啊~~~望各位大虾指点迷津,小弟在此感激不尽啊!!!</span></span></font></p><p></p>

liubo4869 发表于 2009-4-28 16:23:00

<p>最好能像开发包里面的sample一样,大虾们如果能给个例子,小弟就不胜感激了!!!</p>

etongsoft 发表于 2009-4-28 16:49:00

<p>这个我有代码! </p><p>不过需要付一点点费用</p><p></p><p>QQ:444285140</p>

松竹 发表于 2009-5-4 22:43:00

<p>这还付费啊。。。</p><p>需要导入acad.tlb来导入Com接口</p><p>void 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("MyMenu");</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;T)"), _T("_TestCmd "));</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>

liubo4869 发表于 2009-5-5 11:09:00

非常感谢楼上的这位大虾啊!!!实在感激不尽!!!眼泪哗哗的.....

GGxMM 发表于 2009-5-5 22:33:00

其实菜单你可以修改菜单文件来着。<br/><br/>个人而言,菜单非常不建议用代码形式添加。<br/>

liubo4869 发表于 2009-5-6 09:39:00

是修改.mnu文件吗?

松竹 发表于 2009-5-16 09:32:00

修改mnu文件是一种方法,但2006以上使用的cui文件,比较难修改了。

zyx137 发表于 2009-5-24 12:36:00

<p>转载论坛老师的源码,可以用在2006版本以上共同借鉴,希望老师不要介意,如果不允许,我会道歉</p><p>//加载局部菜单<br/>bool LoadPartialMenu(<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const char* filePath //局部菜单文件名<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; , const char* menuGroupName //局部菜单组名<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; )<br/>{<br/>&nbsp;resbuf pSrcRb;<br/>&nbsp;resbuf* pDestRb = NULL; <br/>&nbsp;if (acedGetVar("FILEDIA", &amp;pSrcRb) != RTNORM) return false;<br/>&nbsp;if ((pDestRb = acutBuildList(RTSHORT, 0, RTNONE)) == NULL) return false;<br/>&nbsp;<br/>&nbsp;//不显示对话框,改为命令行<br/>&nbsp;if (acedSetVar("FILEDIA", pDestRb) != RTNORM) {<br/>&nbsp;&nbsp;acutRelRb(pDestRb);<br/>&nbsp;&nbsp;return false;<br/>&nbsp;}<br/>&nbsp;acutRelRb(pDestRb);<br/>&nbsp;//加载菜单<br/>&nbsp;if (acedCommand(RTSTR, "menuload", RTSTR, filePath, 0) != RTNORM) {<br/>&nbsp;&nbsp;acedSetVar("FILEDIA", &amp;pSrcRb);<br/>&nbsp;&nbsp;return false;<br/>&nbsp;}<br/>&nbsp;//加载局部菜单完毕,恢复原始状态<br/>&nbsp;acedSetVar("FILEDIA", &amp;pSrcRb);<br/>&nbsp;<br/>&nbsp;//显示局部菜单<br/>&nbsp;char menuCmd;&nbsp;<br/>&nbsp;sprintf(menuCmd, "GACAD.HELP=+%s.POP%d", menuGroupName,13);<br/>&nbsp;acedMenuCmd(menuCmd);<br/>&nbsp;sprintf(menuCmd, "GACAD.HELP=+%s.POP%d", menuGroupName,14);<br/>&nbsp;acedMenuCmd(menuCmd);<br/>&nbsp;return true;<br/>}<br/></p>
页: [1]
查看完整版本: 如何用C++开发菜单?